feat(tracemetrics): Bypass metric field validation for equations#112479
Conversation
|
There's a chance that, since we encode the metric name in the aggregate function now, this validation can go away, but for now I do not want to make that change because frontend code may be reliant on this field being filled out. Post-GA we can circle back and see if this field is still necessary, but for now we do not need to do large changes to account for this. |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed:
all()on empty iterable bypasses metric validation- Fixed by collecting y_axes into a list and checking both that the list is non-empty AND that all items are equations, ensuring has_equations is only True when actual equation y-axes are present.
Or push these changes by commenting:
@cursor push 1300763d88
Preview (1300763d88)
diff --git a/src/sentry/explore/endpoints/serializers.py b/src/sentry/explore/endpoints/serializers.py
--- a/src/sentry/explore/endpoints/serializers.py
+++ b/src/sentry/explore/endpoints/serializers.py
@@ -225,11 +225,12 @@
)
# the metrics field is only required for non-equation queries
- has_equations = all(
- is_equation(y_axis)
+ y_axes = [
+ y_axis
for aggregate_field in q.get("aggregateField") or []
for y_axis in aggregate_field.get("yAxes") or []
- )
+ ]
+ has_equations = len(y_axes) > 0 and all(is_equation(y_axis) for y_axis in y_axes)
if data["dataset"] == "metrics" and not has_equations and "metric" not in q:
raise serializers.ValidationError(
"Metric field is required for non-equation queries on the metrics dataset"This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2156b77. Configure here.
This comment was marked as outdated.
This comment was marked as outdated.
| raise serializers.ValidationError( | ||
| "Metric field is only allowed for metrics dataset" | ||
| ) | ||
| if data["dataset"] == "metrics" and "metric" not in q: |
There was a problem hiding this comment.
I think we actually can get rid of metric constraint, have to check redash first to see if it'll break any old saved queries, but this is left over before we switched function syntax to count(..., metric tuple) since we had to discern count() meant it was for a particular metric.
We should update the test to ensure it's properly validating the function count() since it should be confirming all functions contain the metrics tuple if it's properly using search resolver
There was a problem hiding this comment.
Checked, the first non-internal saved query was avg(value,<metric name>, <type>,-) so we're fine.
k-fish
left a comment
There was a problem hiding this comment.
Agreed we can defer this, make a ticket so we don't forget
…2479) We enforce that there's a `metric` payload for saved queries, but when a user is plotting an equation, there can be multiple `metric`s involved, so this field no longer makes sense. This PR relaxes the constraint so `metric` can be skipped if the user is querying an equation (i.e. we check if there's the `equation|` prefix)


We enforce that there's a
metricpayload for saved queries, but when a user is plotting an equation, there can be multiplemetrics involved, so this field no longer makes sense.This PR relaxes the constraint so
metriccan be skipped if the user is querying an equation (i.e. we check if there's theequation|prefix)