Skip to content

Commit 85db68c

Browse files
authored
fix(eap-alerts): Use the correct entity key (#91801)
Also updates all the integration tests to not mock snuba calls. These tests should have caught that EntityKey.EAPSpans was no longer an available option. Also tests creating + updating + deleting a subscription in a single tests since `create` uses a new RPC whereas `delete` uses an older endpoint
1 parent e6d1548 commit 85db68c

File tree

6 files changed

+26
-33
lines changed

6 files changed

+26
-33
lines changed

src/sentry/incidents/logic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def get_metric_issue_aggregates(
415415
"incidents.get_incident_aggregates.snql.query.error",
416416
tags={
417417
"dataset": params.snuba_query.dataset,
418-
"entity": EntityKey.EAPSpans.value,
418+
"entity": EntityKey.EAPItemsSpan.value,
419419
},
420420
)
421421
raise

src/sentry/search/events/builder/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
DATASET_TO_ENTITY_MAP: Mapping[Dataset, EntityKey] = {
8080
Dataset.Events: EntityKey.Events,
8181
Dataset.Transactions: EntityKey.Transactions,
82-
Dataset.EventsAnalyticsPlatform: EntityKey.EAPSpans,
82+
Dataset.EventsAnalyticsPlatform: EntityKey.EAPItemsSpan,
8383
}
8484

8585

src/sentry/snuba/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EntityKey(Enum):
6161
Sessions = "sessions"
6262
Spans = "spans"
6363
EAPSpans = "eap_spans"
64+
EAPItemsSpan = "eap_items_span"
6465
Transactions = "transactions"
6566
MetricsSets = "metrics_sets"
6667
MetricsCounters = "metrics_counters"

src/sentry/snuba/entity_subscription.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
EntityKey.GenericMetricsGauges: "timestamp",
4949
EntityKey.MetricsCounters: "timestamp",
5050
EntityKey.MetricsSets: "timestamp",
51-
EntityKey.EAPSpans: "timestamp",
51+
EntityKey.EAPItemsSpan: "timestamp",
5252
}
5353
CRASH_RATE_ALERT_AGGREGATE_RE = (
5454
r"^percentage\([ ]*(sessions_crashed|users_crashed)[ ]*\,[ ]*(sessions|users)[ ]*\)"
@@ -621,7 +621,7 @@ def get_entity_key_from_snuba_query(
621621
) -> EntityKey:
622622
query_dataset = Dataset(snuba_query.dataset)
623623
if query_dataset == Dataset.EventsAnalyticsPlatform:
624-
return EntityKey.EAPSpans
624+
return EntityKey.EAPItemsSpan
625625
entity_subscription = get_entity_subscription_from_snuba_query(
626626
snuba_query,
627627
organization_id,

src/sentry/snuba/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def update_subscription_in_snuba(
148148
},
149149
)
150150
old_entity_key = (
151-
EntityKey.EAPSpans
151+
EntityKey.EAPItemsSpan
152152
if dataset == Dataset.EventsAnalyticsPlatform
153153
else get_entity_key_from_query_builder(
154154
old_entity_subscription.build_query_builder(

tests/sentry/snuba/test_tasks.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -365,28 +365,24 @@ def test_eap_rpc_query_count(self):
365365
aggregate="count(span.duration)",
366366
dataset=Dataset.EventsAnalyticsPlatform,
367367
)
368-
with patch("sentry.utils.snuba_rpc._snuba_pool") as rpc_pool:
369-
with patch("sentry.snuba.tasks._snuba_pool") as pool:
370-
resp = Mock()
371-
resp.status = 202
372-
resp.data = b'\n"0/a92bba96a12e11ef8b0eaeb51d7f1da4'
373-
rpc_pool.urlopen.return_value = resp
374-
pool.urlopen.return_value = resp
375-
376-
create_subscription_in_snuba(sub.id)
377-
sub = QuerySubscription.objects.get(id=sub.id)
378-
assert sub.status == QuerySubscription.Status.ACTIVE.value
379-
assert sub.subscription_id is not None
368+
create_subscription_in_snuba(sub.id)
369+
sub = QuerySubscription.objects.get(id=sub.id)
370+
assert sub.status == QuerySubscription.Status.ACTIVE.value
371+
assert sub.subscription_id is not None
380372

381-
sub.status = QuerySubscription.Status.UPDATING.value
382-
sub.update(
383-
status=QuerySubscription.Status.UPDATING.value,
384-
subscription_id=sub.subscription_id,
385-
)
386-
update_subscription_in_snuba(sub.id)
387-
sub = QuerySubscription.objects.get(id=sub.id)
388-
assert sub.status == QuerySubscription.Status.ACTIVE.value
389-
assert sub.subscription_id is not None
373+
sub.update(
374+
status=QuerySubscription.Status.UPDATING.value,
375+
)
376+
update_subscription_in_snuba(sub.id)
377+
sub = QuerySubscription.objects.get(id=sub.id)
378+
assert sub.status == QuerySubscription.Status.ACTIVE.value
379+
assert sub.subscription_id is not None
380+
381+
sub.update(
382+
status=QuerySubscription.Status.DELETING.value,
383+
)
384+
delete_subscription_from_snuba(sub.id)
385+
assert not QuerySubscription.objects.filter(id=sub.id).exists()
390386

391387

392388
class DeleteSubscriptionFromSnubaTest(BaseSnubaTaskTest):
@@ -422,19 +418,15 @@ def test_eap_rpc_query_count(self):
422418
aggregate="count(span.duration)",
423419
dataset=Dataset.EventsAnalyticsPlatform,
424420
)
425-
with patch("sentry.snuba.tasks._snuba_pool") as pool:
426-
resp = Mock()
427-
resp.status = 202
428-
pool.urlopen.return_value = resp
429-
421+
with patch.object(_snuba_pool, "urlopen", side_effect=_snuba_pool.urlopen) as urlopen:
430422
delete_subscription_from_snuba(sub.id)
431423
assert not QuerySubscription.objects.filter(id=sub.id).exists()
432424

433-
(method, url) = pool.urlopen.call_args[0]
425+
(method, url) = urlopen.call_args[0]
434426
assert method == "DELETE"
435427
assert (
436428
url
437-
== f"/{Dataset.EventsAnalyticsPlatform.value}/{EntityKey.EAPSpans.value}/subscriptions/{subscription_id}"
429+
== f"/{Dataset.EventsAnalyticsPlatform.value}/{EntityKey.EAPItemsSpan.value}/subscriptions/{subscription_id}"
438430
)
439431

440432
def test_no_subscription_id(self):

0 commit comments

Comments
 (0)