Skip to content

Commit

Permalink
fix(insights): add cache.item_size as nullable metric (#74275)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DominikB2014 authored Jul 15, 2024
1 parent 330015b commit e9499d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sentry/search/events/datasets/spans_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions tests/snuba/api/endpoints/test_organization_events_span_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e9499d6

Please sign in to comment.