Skip to content

Commit 2b973b8

Browse files
authored
feat(discover): allow querying for cache.item_size and cache.hit (#68788)
1 parent b6239b6 commit 2b973b8

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,11 @@ def is_performance(self) -> bool:
353353

354354
@property
355355
def use_case_id(self) -> UseCaseID:
356-
if self.is_performance:
357-
return UseCaseID.TRANSACTIONS
358-
elif self.spans_metrics_builder:
356+
357+
if self.spans_metrics_builder:
359358
return UseCaseID.SPANS
359+
elif self.is_performance:
360+
return UseCaseID.TRANSACTIONS
360361
else:
361362
return UseCaseID.SESSIONS
362363

src/sentry/search/events/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ class ThresholdDict(TypedDict):
311311
"query_hash",
312312
"release",
313313
"resource.render_blocking_status",
314+
"cache.hit",
314315
"satisfaction",
315316
"sdk",
316317
"session.status",
@@ -327,6 +328,7 @@ class ThresholdDict(TypedDict):
327328
"http.response_content_length": "d:spans/http.response_content_length@byte",
328329
"http.decoded_response_content_length": "d:spans/http.decoded_response_content_length@byte",
329330
"http.response_transfer_size": "d:spans/http.response_transfer_size@byte",
331+
"cache.item_size": "d:spans/cache.item_size@byte",
330332
}
331333
SELF_TIME_LIGHT = "d:spans/exclusive_time_light@millisecond"
332334
# 50 to match the size of tables in the UI + 1 for pagination reasons

src/sentry/snuba/metrics/naming_layer/mri.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class SpanMRI(Enum):
167167
SELF_TIME_LIGHT = "d:spans/exclusive_time_light@millisecond"
168168
RESPONSE_CONTENT_LENGTH = "d:spans/http.response_content_length@byte"
169169
DECODED_RESPONSE_CONTENT_LENGTH = "d:spans/http.decoded_response_content_length@byte"
170+
CACHE_ITEM_SIZE = "d:spans/cache.item_size@byte"
170171
RESPONSE_TRANSFER_SIZE = "d:spans/http.response_transfer_size@byte"
171172

172173
# Derived

src/sentry/snuba/metrics/naming_layer/public.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class SpanMetricKey(Enum):
120120
RESPONSE_CONTENT_LENGTH = "http.response_content_length"
121121
DECODED_RESPONSE_CONTENT_LENGTH = "http.decoded_response_content_length"
122122
RESPONSE_TRANSFER_SIZE = "http.response_transfer_size"
123+
CACHE_ITEM_SIZE = "cache.item_size"
123124

124125
HTTP_ERROR_COUNT = "span.http_error_count"
125126
HTTP_ERROR_RATE = "span.http_error_rate"

src/sentry/testutils/cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,7 @@ class MetricsEnhancedPerformanceTestCase(BaseMetricsLayerTestCase, TestCase):
20192019
"span.self_time": "metrics_distributions",
20202020
"http.response_content_length": "metrics_distributions",
20212021
"http.decoded_response_content_length": "metrics_distributions",
2022+
"cache.item_size": "metrics_distributions",
20222023
"http.response_transfer_size": "metrics_distributions",
20232024
"measurements.lcp": "metrics_distributions",
20242025
"measurements.fp": "metrics_distributions",

tests/sentry/snuba/metrics/fields/test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def get_entity_of_metric_mocked(_, metric_mri, use_case_id):
7171
SpanMRI.RESPONSE_CONTENT_LENGTH.value: EntityKey.MetricsDistributions,
7272
SpanMRI.DECODED_RESPONSE_CONTENT_LENGTH.value: EntityKey.MetricsDistributions,
7373
SpanMRI.RESPONSE_TRANSFER_SIZE.value: EntityKey.MetricsDistributions,
74+
SpanMRI.CACHE_ITEM_SIZE.value: EntityKey.MetricsDistributions,
7475
}[metric_mri]
7576

7677

tests/snuba/api/endpoints/test_organization_events_stats_span_metrics.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,34 @@ def test_resource_transfer_size(self):
270270
assert not data[0][1][0]["count"]
271271
assert data[1][1][0]["count"] == 4.0
272272

273+
def test_cache_item_size(self):
274+
self.store_span_metric(
275+
4,
276+
metric="cache.item_size",
277+
timestamp=self.day_ago + timedelta(minutes=1),
278+
tags={"transaction": "foo", "cache.hit": "true"},
279+
)
280+
281+
response = self.do_request(
282+
data={
283+
"start": iso_format(self.day_ago),
284+
"end": iso_format(self.day_ago + timedelta(minutes=2)),
285+
"interval": "1m",
286+
"yAxis": "avg(cache.item_size)",
287+
"field": ["cache.hit"],
288+
"project": self.project.id,
289+
"dataset": "spansMetrics",
290+
"excludeOther": 0,
291+
},
292+
)
293+
294+
assert response.status_code == 200
295+
296+
data = response.data["data"]
297+
assert len(data) == 2
298+
assert not data[0][1][0]["count"]
299+
assert data[1][1][0]["count"] == 4.0
300+
273301

274302
class OrganizationEventsStatsSpansMetricsEndpointTestWithMetricLayer(
275303
OrganizationEventsStatsSpansMetricsEndpointTest

0 commit comments

Comments
 (0)