From 323ddb7ec6811c957a64eab15bfaf444a5d46e06 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Wed, 13 Sep 2023 10:08:23 -0700 Subject: [PATCH] Adds canary support for signals. (#3785) * clean pr * Add revision --- .../versions/2023-09-13_e875e9544048.py | 26 +++++++++++++++++++ src/dispatch/signal/flows.py | 4 +++ src/dispatch/signal/models.py | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 src/dispatch/database/revisions/tenant/versions/2023-09-13_e875e9544048.py diff --git a/src/dispatch/database/revisions/tenant/versions/2023-09-13_e875e9544048.py b/src/dispatch/database/revisions/tenant/versions/2023-09-13_e875e9544048.py new file mode 100644 index 000000000000..2522f08015a9 --- /dev/null +++ b/src/dispatch/database/revisions/tenant/versions/2023-09-13_e875e9544048.py @@ -0,0 +1,26 @@ +"""Adds canary column to signal_instance + +Revision ID: e875e9544048 +Revises: 0560fab4537f +Create Date: 2023-09-13 09:31:24.223488 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = "e875e9544048" +down_revision = "0560fab4537f" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("signal_instance", sa.Column("canary", sa.Boolean(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("signal_instance", "canary") diff --git a/src/dispatch/signal/flows.py b/src/dispatch/signal/flows.py index 373ec4efa85f..680d10a75ed8 100644 --- a/src/dispatch/signal/flows.py +++ b/src/dispatch/signal/flows.py @@ -90,6 +90,10 @@ def signal_instance_create_flow( ) return signal_instance + # limited support for canary signals, just store the instance and return + if signal_instance.canary: + return signal_instance + if not signal_instance.signal.create_case: return signal_instance diff --git a/src/dispatch/signal/models.py b/src/dispatch/signal/models.py index 23dfd127e490..d35154a8c325 100644 --- a/src/dispatch/signal/models.py +++ b/src/dispatch/signal/models.py @@ -231,6 +231,7 @@ class SignalInstance(Base, TimeStampMixin, ProjectMixin): case_priority = relationship("CasePriority", backref="signal_instances") fingerprint = Column(String) filter_action = Column(String) + canary = Column(Boolean, default=False) raw = Column(JSONB) signal = relationship("Signal", backref="instances") signal_id = Column(Integer, ForeignKey("signal.id")) @@ -364,6 +365,7 @@ class AdditionalMetadata(DispatchBase): class SignalInstanceBase(DispatchBase): project: ProjectRead case: Optional[CaseReadMinimal] + canary: Optional[bool] = False entities: Optional[List[EntityRead]] = [] raw: dict[str, Any] filter_action: SignalFilterAction = None