From e9499d61ee84e0f30e9d0bd11b5e7dd38d3300b8 Mon Sep 17 00:00:00 2001 From: Dominik Buszowiecki <44422760+DominikB2014@users.noreply.github.com> Date: Mon, 15 Jul 2024 15:20:02 -0400 Subject: [PATCH] fix(insights): add cache.item_size as nullable metric (#74275) fixes #74130 Not all orgs will send in `cache.item_size`, we should ensure that we add this metric as nullable so that it does not fail at query time. --- .../search/events/datasets/spans_metrics.py | 5 ++- .../test_organization_events_span_metrics.py | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/sentry/search/events/datasets/spans_metrics.py b/src/sentry/search/events/datasets/spans_metrics.py index 50f41e4be6b4a..37a0aa5eeafb5 100644 --- a/src/sentry/search/events/datasets/spans_metrics.py +++ b/src/sentry/search/events/datasets/spans_metrics.py @@ -27,7 +27,10 @@ class Args(TypedDict): class SpansMetricsDatasetConfig(DatasetConfig): missing_function_error = IncompatibleMetricsQuery - nullable_metrics = {constants.SPAN_MESSAGING_LATENCY} + nullable_metrics = { + constants.SPAN_MESSAGING_LATENCY, + constants.SPAN_METRICS_MAP["cache.item_size"], + } def __init__(self, builder: spans_metrics.SpansMetricsQueryBuilder): self.builder = builder diff --git a/tests/snuba/api/endpoints/test_organization_events_span_metrics.py b/tests/snuba/api/endpoints/test_organization_events_span_metrics.py index 96d13a97d5c92..b1a20dd2845ad 100644 --- a/tests/snuba/api/endpoints/test_organization_events_span_metrics.py +++ b/tests/snuba/api/endpoints/test_organization_events_span_metrics.py @@ -1741,6 +1741,37 @@ def test_messaging_does_not_exist_as_metric(self): meta = response.data["meta"] assert meta["fields"]["avg(messaging.message.receive.latency)"] == "null" + def test_cache_item_size_does_not_exist_as_metric(self): + self.store_span_metric( + 100, + internal_metric=constants.SPAN_METRICS_MAP["span.duration"], + tags={"cache.item": "true"}, + timestamp=self.min_ago, + ) + response = self.do_request( + { + "field": [ + "avg(cache.item_size)", + "avg(span.duration)", + ], + "query": "", + "project": self.project.id, + "dataset": "spansMetrics", + "statsPeriod": "1h", + } + ) + + assert response.status_code == 200, response.content + data = response.data["data"] + assert data == [ + { + "avg(cache.item_size)": None, + "avg(span.duration)": 100, + }, + ] + meta = response.data["meta"] + assert meta["fields"]["avg(cache.item_size)"] == "null" + def test_trace_status_rate(self): self.store_span_metric( 1,