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

feat(discover): Use SnQL for some of event-stats #29471

Merged
merged 4 commits into from
Oct 25, 2021

Conversation

wmak
Copy link
Member

@wmak wmak commented Oct 21, 2021

  • This enables the use of a new TimeseriesQueryBuilder on event-stats
    queries that don't include comparsion, and aren't top events queries
  • Had to refactor a lot of the tests to use the same do_request
    pattern from eventsv2 to make testing easier
  • Needed to add a 4th list to resolve_equation_list so we could
    differentiate easily between equations that are on functions or not
    • Didn't go with a class or namedtuple in the response since we'll
      likely be removing some of this once we're done migrating
  • Only adding project_threshold_config when auto_fields are on, which
    means that the table response is unchanged, but now we no longer need
    to do the averaging for graphing threshold based functions

- This enables the use of a new TimeseriesQueryBuilder on event-stats
  queries that don't include comparsion, and aren't top events queries
- Had to refactor a lot of the tests to use the same `do_request`
  pattern from eventsv2 to make testing easier
- Needed to add a 4th list to resolve_equation_list so we could
  differentiate easily between equations that are on functions or not
  - Didn't go with a class or namedtuple in the response since we'll
    likely be removing some of this once we're done migrating
- Only adding project_threshold_config when auto_fields are on, which
  means that the table response is unchanged, but now we no longer need
  to do the averaging for graphing threshold based functions
@@ -71,7 +71,7 @@ def validate(self, data):

if equations is not None:
try:
resolved_equations, _, _ = resolve_equation_list(equations, fields)
resolved_equations, _, _, _ = resolve_equation_list(equations, fields)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure of a better suggestion but destructuring a 4-tuple is getting a little unwieldy. Perhaps consider returning an object with named attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered that, but decided since this is only temporary (first two go away once we no longer need to return JSON) to leave this as-is for now

select=self.select,
where=self.where,
having=self.having,
# This is a timeseries, the groupby will always be time
Copy link
Member

Choose a reason for hiding this comment

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

This assumption breaks with top 5 charts right? Did you already have an idea for that?

Copy link
Member Author

@wmak wmak Oct 21, 2021

Choose a reason for hiding this comment

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

Dang I considered commenting this but thought it was overly verbose for this PR

Yeah I think for top events we should have just introduce a different timeseries builder that inherits from this one and changes the groupby etc. as needed

):
stripped_columns.append(PROJECT_THRESHOLD_CONFIG_ALIAS)
break
if self.auto_fields:
Copy link
Member

Choose a reason for hiding this comment

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

This auto_fields condition did not exist previously, what is the motivation behind this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah hm leftover from earlier iteration where i slammed all of self.select into the query and not just the aggregates. I'll undo this change 👍

Comment on lines +111 to +112
if isinstance(obj["time"], str):
obj["time"] = int(to_timestamp(parse_datetime(obj["time"])))
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Does snql return a str now instead of a int like it did previously?

Copy link
Member Author

Choose a reason for hiding this comment

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

so the query has always returned the date as a str, but there was a reverse processor here
Which we're no longer using.

- Adding a comment explaining why we need to parse the times now
- Removing the auto fields that we no longer need
- Fixing tests that broke cause I removed the select property
Comment on lines 2812 to 2814
for index, (equation, is_function) in enumerate(
zip(parsed_equations, contains_function)
):
Copy link
Member

Choose a reason for hiding this comment

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

This is now dependent on the fact that parsed_equations and contains_function are the same lengths. Does this need a comment in resolve_equation_list to make it clear that this must be the case? Or even add a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

dangit this comment convinced me, going to have resolve_equation_list return a list of objects instead of two lists for the snql syntax, which should mean after the migration we only need the single list in the response.

@wmak wmak merged commit 84e73fe into master Oct 25, 2021
@wmak wmak deleted the wmak/feat/snql-event-stats-simple branch October 25, 2021 15:18
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants