Skip to content

feat(discover): allow querying for cache.item_size and cache.hit #68788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/sentry/search/events/builder/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ def is_performance(self) -> bool:

@property
def use_case_id(self) -> UseCaseID:
if self.is_performance:
return UseCaseID.TRANSACTIONS
elif self.spans_metrics_builder:

if self.spans_metrics_builder:
return UseCaseID.SPANS
elif self.is_performance:
return UseCaseID.TRANSACTIONS
Comment on lines +357 to +360
Copy link
Contributor Author

@DominikB2014 DominikB2014 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanh turns out this was the problem, we were setting the wrong useCaseId, and the metric/tag index would fail to resolve when we queried for them, tests pass just fine now!

else:
return UseCaseID.SESSIONS

Expand Down
2 changes: 2 additions & 0 deletions src/sentry/search/events/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class ThresholdDict(TypedDict):
"query_hash",
"release",
"resource.render_blocking_status",
"cache.hit",
"satisfaction",
"sdk",
"session.status",
Expand All @@ -327,6 +328,7 @@ class ThresholdDict(TypedDict):
"http.response_content_length": "d:spans/http.response_content_length@byte",
"http.decoded_response_content_length": "d:spans/http.decoded_response_content_length@byte",
"http.response_transfer_size": "d:spans/http.response_transfer_size@byte",
"cache.item_size": "d:spans/cache.item_size@byte",
}
SELF_TIME_LIGHT = "d:spans/exclusive_time_light@millisecond"
# 50 to match the size of tables in the UI + 1 for pagination reasons
Expand Down
1 change: 1 addition & 0 deletions src/sentry/snuba/metrics/naming_layer/mri.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class SpanMRI(Enum):
SELF_TIME_LIGHT = "d:spans/exclusive_time_light@millisecond"
RESPONSE_CONTENT_LENGTH = "d:spans/http.response_content_length@byte"
DECODED_RESPONSE_CONTENT_LENGTH = "d:spans/http.decoded_response_content_length@byte"
CACHE_ITEM_SIZE = "d:spans/cache.item_size@byte"
RESPONSE_TRANSFER_SIZE = "d:spans/http.response_transfer_size@byte"

# Derived
Expand Down
1 change: 1 addition & 0 deletions src/sentry/snuba/metrics/naming_layer/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class SpanMetricKey(Enum):
RESPONSE_CONTENT_LENGTH = "http.response_content_length"
DECODED_RESPONSE_CONTENT_LENGTH = "http.decoded_response_content_length"
RESPONSE_TRANSFER_SIZE = "http.response_transfer_size"
CACHE_ITEM_SIZE = "cache.item_size"

HTTP_ERROR_COUNT = "span.http_error_count"
HTTP_ERROR_RATE = "span.http_error_rate"
Expand Down
1 change: 1 addition & 0 deletions src/sentry/testutils/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,7 @@ class MetricsEnhancedPerformanceTestCase(BaseMetricsLayerTestCase, TestCase):
"span.self_time": "metrics_distributions",
"http.response_content_length": "metrics_distributions",
"http.decoded_response_content_length": "metrics_distributions",
"cache.item_size": "metrics_distributions",
"http.response_transfer_size": "metrics_distributions",
"measurements.lcp": "metrics_distributions",
"measurements.fp": "metrics_distributions",
Expand Down
1 change: 1 addition & 0 deletions tests/sentry/snuba/metrics/fields/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def get_entity_of_metric_mocked(_, metric_mri, use_case_id):
SpanMRI.RESPONSE_CONTENT_LENGTH.value: EntityKey.MetricsDistributions,
SpanMRI.DECODED_RESPONSE_CONTENT_LENGTH.value: EntityKey.MetricsDistributions,
SpanMRI.RESPONSE_TRANSFER_SIZE.value: EntityKey.MetricsDistributions,
SpanMRI.CACHE_ITEM_SIZE.value: EntityKey.MetricsDistributions,
}[metric_mri]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,34 @@ def test_resource_transfer_size(self):
assert not data[0][1][0]["count"]
assert data[1][1][0]["count"] == 4.0

def test_cache_item_size(self):
self.store_span_metric(
4,
metric="cache.item_size",
timestamp=self.day_ago + timedelta(minutes=1),
tags={"transaction": "foo", "cache.hit": "true"},
)

response = self.do_request(
data={
"start": iso_format(self.day_ago),
"end": iso_format(self.day_ago + timedelta(minutes=2)),
"interval": "1m",
"yAxis": "avg(cache.item_size)",
"field": ["cache.hit"],
"project": self.project.id,
"dataset": "spansMetrics",
"excludeOther": 0,
},
)

assert response.status_code == 200

data = response.data["data"]
assert len(data) == 2
assert not data[0][1][0]["count"]
assert data[1][1][0]["count"] == 4.0


class OrganizationEventsStatsSpansMetricsEndpointTestWithMetricLayer(
OrganizationEventsStatsSpansMetricsEndpointTest
Expand Down
Loading