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

wip(eap): http response rate function #85662

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

DominikB2014
Copy link
Contributor

@DominikB2014 DominikB2014 commented Feb 21, 2025

Work for #81750

  1. Adds the ability to define custom functions (formulas)
  2. Implement the http_response_rate function, which is used in insights

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 21, 2025
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 97.75281% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/search/eap/columns.py 97.43% 1 Missing ⚠️
src/sentry/search/eap/span_columns.py 94.44% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #85662       +/-   ##
===========================================
+ Coverage   42.22%   87.89%   +45.67%     
===========================================
  Files        9665     9695       +30     
  Lines      548129   549723     +1594     
  Branches    21345    21345               
===========================================
+ Hits       231453   483190   +251737     
+ Misses     316366    66223   -250143     
  Partials      310      310               

Comment on lines +700 to +701
if function in self.definitions.functions:
function_definition = self.definitions.functions[function]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a future refactor, we can rename self.definitions.functions to self.definitions.aggregates

@DominikB2014 DominikB2014 marked this pull request as ready for review February 26, 2025 16:06
@DominikB2014 DominikB2014 requested a review from a team as a code owner February 26, 2025 16:06
@DominikB2014 DominikB2014 requested a review from wmak February 26, 2025 16:07
@DominikB2014
Copy link
Contributor Author

DominikB2014 commented Feb 26, 2025

@wmak I addressed your comments!
I slapped all the formulas in one file for now.
In future PRs, i'm planning to splitting up the span_columns as we discussed and address the TODO comments.

Lmk if that works for you!



@dataclass
class FormulaDefinition:
Copy link
Member

Choose a reason for hiding this comment

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

Could we have this inherit from FunctionDefinition so we're not repeating everything?

@@ -324,7 +327,7 @@ def resolve_virtual_context_term(
self,
term: str,
raw_value: str | list[str],
resolved_column: ResolvedColumn,
resolved_column: ResolvedColumn | ResolvedFormula | ResolvedFormula,
Copy link
Member

Choose a reason for hiding this comment

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

Is this intentional? VCCs should only apply to Resolved Columns

@@ -468,7 +471,7 @@ def resolve_aggregate_term(

def _resolve_search_value(
self,
column: ResolvedColumn,
column: ResolvedColumn | ResolvedFormula,
Copy link
Member

Choose a reason for hiding this comment

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

Another one, is this intentional? We don't resolve search values for formulas do we?

@@ -386,6 +402,65 @@ def count_processor(count_value: int | None) -> int:
return count_value


def http_response_rate(arg: str) -> Column.BinaryFormula:

if not arg.isdigit():
Copy link
Member

Choose a reason for hiding this comment

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

nit: why not just check that arg is in a list of the strings of 1-5, then you can cast safely without concern?

op=ComparisonFilter.OP_IN,
value=AttributeValue(
val_str_array=StrArray(
values=response_codes, #
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
values=response_codes, #
values=response_codes,

ArgumentDefinition(
argument_types={
"string"
}, # TODO - this should be an integer, but `resolve_attribute` returns a string
Copy link
Member

Choose a reason for hiding this comment

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

I think instead of leaving this as a todo we need to add a way to define arguments that aren't just attributes, so that SearchResolver.resolve_aggregate knows to cast a user input, which probably would clean up the definition of http_response_rate for you too

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.

Overall in the right direction, I'm mostly concerned that we're sorta hacking the argument resolution currently.

@DominikB2014
Copy link
Contributor Author

DominikB2014 commented Feb 26, 2025

Overall in the right direction, I'm mostly concerned that we're sorta hacking the argument resolution currently.

👍 thanks for the review, I don't mind spending some more time getting the args working properly in this PR

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.

3 participants