Exemplo n.º 1
0
def handle_subscription_metrics_logger(subscription_update, subscription):
    """
    Logs results from a `QuerySubscription`.
    :param subscription_update: dict formatted according to schemas in
    sentry.snuba.json_schemas.SUBSCRIPTION_PAYLOAD_VERSIONS
    :param subscription: The `QuerySubscription` that this update is for
    """
    from sentry.incidents.subscription_processor import SubscriptionProcessor

    try:
        processor = SubscriptionProcessor(subscription)
        processor.alert_rule = AlertRule()
        aggregation_value = int(
            processor.get_aggregation_value(subscription_update))
        processor.alert_rule.comparison_delta = int(
            timedelta(days=7).total_seconds())
        comparison_value = processor.get_aggregation_value(subscription_update)
        tags = {
            "project_id": subscription.project_id,
            "project_slug": subscription.project.slug,
            "subscription_id": subscription.id,
            "time_window": subscription.snuba_query.time_window,
        }
        metrics.incr("subscriptions.result.value",
                     aggregation_value,
                     tags=tags,
                     sample_rate=1.0)
        if comparison_value is not None:
            metrics.incr("subscriptions.result.comparison",
                         int(comparison_value),
                         tags=tags,
                         sample_rate=1.0)
    except Exception:
        logger.exception("Failed to log subscription results")
Exemplo n.º 2
0
 def send_update(self, rule, value, time_delta=None):
     if time_delta is None:
         time_delta = timedelta()
     subscription = rule.query_subscriptions.get()
     processor = SubscriptionProcessor(subscription)
     message = self.build_subscription_update(subscription, value=value, time_delta=time_delta)
     processor.process_update(message)
     return processor
Exemplo n.º 3
0
 def send_update(self, rule, value, time_delta=None, subscription=None):
     if time_delta is None:
         time_delta = timedelta()
     if subscription is None:
         subscription = self.sub
     processor = SubscriptionProcessor(subscription)
     message = self.build_subscription_update(subscription, value=value, time_delta=time_delta)
     processor.process_update(message)
     return processor
 def send_update(self, rule, value, time_delta=None, subscription=None):
     self.email_action_handler.reset_mock()
     if time_delta is None:
         time_delta = timedelta()
     if subscription is None:
         subscription = self.sub
     processor = SubscriptionProcessor(subscription)
     message = self.build_subscription_update(subscription, value=value, time_delta=time_delta)
     with self.feature(["organizations:incidents", "organizations:performance-view"]):
         processor.process_update(message)
     return processor
Exemplo n.º 5
0
 def test_removed_alert_rule(self):
     message = self.build_subscription_update(self.sub)
     self.rule.delete()
     SubscriptionProcessor(self.sub).process_update(message)
     self.metrics.incr.assert_called_once_with(
         "incidents.alert_rules.no_alert_rule_for_subscription"
     )
 def test_no_feature_performance(self):
     self.sub.snuba_query.dataset = "transactions"
     message = self.build_subscription_update(self.sub)
     with self.feature("organizations:incidents"):
         SubscriptionProcessor(self.sub).process_update(message)
     self.metrics.incr.assert_called_once_with(
         "incidents.alert_rules.ignore_update_missing_incidents_performance"
     )
 def test_removed_alert_rule(self):
     message = self.build_subscription_update(self.sub)
     self.rule.delete()
     with self.feature(["organizations:incidents", "organizations:performance-view"]):
         SubscriptionProcessor(self.sub).process_update(message)
     self.metrics.incr.assert_called_once_with(
         "incidents.alert_rules.no_alert_rule_for_subscription"
     )
Exemplo n.º 8
0
def handle_snuba_query_update(subscription_update, subscription):
    """
    Handles a subscription update for a `QuerySubscription`.
    :param subscription_update: dict formatted according to schemas in
    sentry.snuba.json_schemas.SUBSCRIPTION_PAYLOAD_VERSIONS
    :param subscription: The `QuerySubscription` that this update is for
    """
    from sentry.incidents.subscription_processor import SubscriptionProcessor

    SubscriptionProcessor(subscription).process_update(subscription_update)
 def test_no_feature(self):
     message = self.build_subscription_update(self.sub)
     SubscriptionProcessor(self.sub).process_update(message)
     self.metrics.incr.assert_called_once_with(
         "incidents.alert_rules.ignore_update_missing_incidents"
     )