-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(anomaly detection): Maintain historical timeseries #1670
Changes from all commits
a23ef39
d1c5345
9c6e830
605baaf
02a9949
a49c9fc
eebe61e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Migration | ||
|
||
Revision ID: 5a7ff418f726 | ||
Revises: 3914e6cdb818 | ||
Create Date: 2024-12-30 23:36:51.280449 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "5a7ff418f726" | ||
down_revision = "3914e6cdb818" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"dynamic_alert_time_series_history", | ||
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), | ||
sa.Column("alert_id", sa.BigInteger(), nullable=False), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are cleaning up history based on timestamp, do we need an index on this field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The id column is to avoid duplicate values in the rows since the other columns can be the same including the timestamped ones if they are added at the same time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was asking about the timestamp column. Since the where clause of the SQL will have timestamp, we need an index (not primary index as id will still be the primary index). |
||
sa.Column("value", sa.Float(), nullable=False), | ||
sa.Column("anomaly_type", sa.String(), nullable=False), | ||
sa.Column("saved_at", sa.DateTime(), nullable=False), | ||
sa.PrimaryKeyConstraint("id", "alert_id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("dynamic_alert_time_series_history") | ||
# ### end Alembic commands ### |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Migration | ||
|
||
Revision ID: 86ba1a6c0cc3 | ||
Revises: 5a7ff418f726 | ||
Create Date: 2025-01-03 19:33:47.489760 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "86ba1a6c0cc3" | ||
down_revision = "5a7ff418f726" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("dynamic_alert_time_series_history", schema=None) as batch_op: | ||
batch_op.alter_column( | ||
"id", | ||
existing_type=sa.INTEGER(), | ||
type_=sa.BigInteger(), | ||
existing_nullable=False, | ||
autoincrement=True, | ||
) | ||
batch_op.create_index( | ||
"ix_dynamic_alert_time_series_history_timestamp", ["timestamp"], unique=False | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table("dynamic_alert_time_series_history", schema=None) as batch_op: | ||
batch_op.drop_index("ix_dynamic_alert_time_series_history_timestamp") | ||
batch_op.alter_column( | ||
"id", | ||
existing_type=sa.BigInteger(), | ||
type_=sa.INTEGER(), | ||
existing_nullable=False, | ||
autoincrement=True, | ||
) | ||
|
||
# ### end Alembic commands ### |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious how come alert_id is biginteger but this id is integer? We will be having more rows in this table than the alert table, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch -- fixed