Skip to content
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

fix(frames-delay): Update meta resolver frames delay units #82209

Conversation

narsaynorath
Copy link
Member

@narsaynorath narsaynorath commented Dec 17, 2024

Map the mobile.frames_delay metric to seconds. Supposedly this can be retrieved from the MRI but I wasn't able to find the code path that did that, instead I found this meta unit resolver and added the mapping there.

It's similar to #81884 which adds the proper type for HTTP response sizes, but I didn't want to just add another property to the class.

Fixes #81560

@narsaynorath narsaynorath requested a review from a team as a code owner December 17, 2024 00:05
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 17, 2024
@markushi
Copy link
Member

Awesome, thank you! I did some more digging and the root cause for this issue seems to stem from the SpanMetricsDataSetConfig, as it defines a result_type_fn for functions like avg_if() to look up the type of the actual metric.

fields.MetricsFunction(
"avg_if",
required_args=[
fields.MetricArg(
"column",
allowed_columns=constants.SPAN_METRIC_DURATION_COLUMNS
| constants.SPAN_METRIC_COUNT_COLUMNS,
),
fields.MetricArg(
"if_col",
allowed_columns=["release", "span.op"],
),
fields.SnQLStringArg(
"if_val", unquote=True, unescape_quotes=True, optional_unquote=True
),
],
calculated_args=[resolve_metric_id],
snql_gauge=self._resolve_avg_if,
snql_distribution=self._resolve_avg_if,
result_type_fn=self.reflective_result_type(),
default_result_type="duration",

But unless defined (that's what you did in the this PR), it simply calls MetricArg.get_type():

def result_type_fn(
function_arguments: list[fields.FunctionArg], parameter_values: dict[str, Any]
) -> str:
argument = function_arguments[index]
value = parameter_values[argument.name]
if (field_type := self.builder.get_field_type(value)) is not None: # type: ignore[attr-defined]
return field_type
else:
return argument.get_type(value)

Which itself always defaults to number here:

def get_type(self, value: str) -> str:
# Just a default
return "number"

So I guess ideally the result_type_fn can properly look up it's known metrics and derive the unit from there? I gave it a quick try over here.

@narsaynorath
Copy link
Member Author

So I guess ideally the result_type_fn can properly look up it's known metrics and derive the unit from there?

@markushi I like this solution better as it seems like the way it's intended to work (pull the unit from the MRI). Great find. Would you be able to merge it into these changes and take over the PR?

Copy link
Member Author

@narsaynorath narsaynorath left a comment

Choose a reason for hiding this comment

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

Just some small comments. The changes look good to me and the tests are passing so I feel like this is a safe change to make. I can't approve my PR but I can tag someone to review it tomorrow.

src/sentry/search/events/builder/spans_metrics.py Outdated Show resolved Hide resolved
src/sentry/search/events/datasets/spans_metrics.py Outdated Show resolved Hide resolved
) -> str:
argument = function_arguments[index]
value = parameter_values[argument.name]
mri = constants.SPAN_METRICS_MAP.get(value)
Copy link
Member

Choose a reason for hiding this comment

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

Just checking, could we not use self.builder.get_field_type here instead? Or am I missing context 😬

Copy link
Member

Choose a reason for hiding this comment

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

Or rather, could we augment get_field_type to handle span metrics, we use that for search field typing as well so the units there need to be correct for the search syntax to handle units correctly. eg. if you search for some_span_metric:534k we need to know that its a number to know k means thousand

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm makes sense, I originally added a change there but I was updating the meta_resolver_map for this field specifically. @markushi I suppose we should port these changes over to that method. I can give that a crack since it's after hours for you right now.

I didn't realize this would only fix the units for the output type and not search

Copy link
Member Author

Choose a reason for hiding this comment

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

@wmak Moved the changes over to the get_field_type method in SpansMetricsQueryBuilder. Let us know how you feel about it

https://github.com/getsentry/sentry/pull/82209/files#diff-4cf33582e331d118cce575a23d98881984f20b579edcba5122bbcb2a831f0d28R47

Copy link
Member

@wmak wmak left a comment

Choose a reason for hiding this comment

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

just double checking, the list of parsed_mri.units overlap the units that discover already uses?

@gggritso
Copy link
Member

👀 nice fix! Should also fix the units for messaging.message.receive.latency 👍🏻

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #82209      +/-   ##
==========================================
- Coverage   87.49%   87.45%   -0.04%     
==========================================
  Files        9410     9394      -16     
  Lines      536846   536330     -516     
  Branches    21049    20971      -78     
==========================================
- Hits       469701   469062     -639     
- Misses      66776    66857      +81     
- Partials      369      411      +42     

@narsaynorath
Copy link
Member Author

@wmak

just double checking, the list of parsed_mri.units overlap the units that discover already uses?

I just checked Relay, and there are a few metrics that provide units that are not supported under discover, but they're not relevant for the reported issue, i.e. usd is used as a unit in the AI modules and ratio is a defined as a unit for some of the web vitals calculated metrics.

I'm going to merge this since those cases will just return None as before, but if you feel like we should tackle those missing units then let me know and we can look at what makes sense for those missing units!

@narsaynorath narsaynorath merged commit 84fa15f into master Jan 3, 2025
49 checks passed
@narsaynorath narsaynorath deleted the nar/fix/mobile-frames-delay-update-meta-resolver-for-span-metrics branch January 3, 2025 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix missing unit for frame delay
4 participants