def test_transaction(self): sub = self.create_subscription(QuerySubscription.Status.CREATING, dataset=QueryDatasets.TRANSACTIONS) create_subscription_in_snuba(sub.id) sub = QuerySubscription.objects.get(id=sub.id) assert sub.status == QuerySubscription.Status.ACTIVE.value assert sub.subscription_id is not None
def test_granularity_on_metrics_crash_rate_alerts(self): for tag in [ SessionMetricKey.SESSION.value, SessionMetricKey.USER.value, "session.status" ]: indexer.record(tag) for (time_window, expected_granularity) in [ (30, 10), (90, 60), (5 * 60, 3600), (25 * 60, 3600 * 24), ]: for idx, aggregate in enumerate(["sessions", "users"]): sub = self.create_subscription( dataset=QueryDatasets.METRICS, aggregate=f"percentage({aggregate}_crashed, {aggregate}) AS " f"_crash_rate_alert_aggregate", time_window=int( timedelta(minutes=time_window).total_seconds()), status=QuerySubscription.Status.CREATING, ) with patch("sentry.snuba.tasks._snuba_pool") as pool: resp = Mock() resp.status = 202 resp.data = json.dumps( {"subscription_id": "123" + f"{time_window + idx}"}) pool.urlopen.return_value = resp create_subscription_in_snuba(sub.id) request_body = json.loads( pool.urlopen.call_args[1]["body"]) assert request_body["granularity"] == expected_granularity
def test_already_created(self): sub = self.create_subscription( QuerySubscription.Status.CREATING, subscription_id=uuid4().hex ) create_subscription_in_snuba(sub.id) self.metrics.incr.assert_called_once_with( "snuba.subscriptions.create.already_created_in_snuba" )
def test_adds_type(self): sub = self.create_subscription(QuerySubscription.Status.CREATING) with patch("sentry.snuba.tasks._snuba_pool") as pool: resp = Mock() resp.status = 202 resp.data = json.dumps({"subscription_id": "123"}) pool.urlopen.return_value = resp create_subscription_in_snuba(sub.id) request_body = json.loads(pool.urlopen.call_args[1]["body"]) assert ["type", "=", "error"] in request_body["conditions"]
def test_group_id(self): group_id = 1234 sub = self.create_subscription(QuerySubscription.Status.CREATING, query=f"issue.id:{group_id}") with patch.object(_snuba_pool, "urlopen", side_effect=_snuba_pool.urlopen) as urlopen: create_subscription_in_snuba(sub.id) assert ["group_id", "IN", [group_id] ] in json.loads(urlopen.call_args[1]["body"])["conditions"] sub = QuerySubscription.objects.get(id=sub.id) assert sub.status == QuerySubscription.Status.ACTIVE.value assert sub.subscription_id is not None
def test(self): sub = self.create_subscription(QuerySubscription.Status.CREATING) create_subscription_in_snuba(sub.id) sub = QuerySubscription.objects.get(id=sub.id) assert sub.status == QuerySubscription.Status.ACTIVE.value assert sub.subscription_id is not None