Skip to content

fix: query elements from start of day #9827

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 1 commit into from
May 20, 2022
Merged

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented May 17, 2022

Problem

see #9770 - doesn't fix this issue by itself, but should help

when loading a trend view of an action (which in this case tracks clicks) we query including a date_from filter like

 AND timestamp >= toStartOfDay(toDateTime('2022-05-10 07:00:00', 'US/Pacific'))

when loading the elements for the toolbar's heat map we query including a date_from filter like

AND timestamp >= toDateTime('2022-05-10 07:00:00', 'US/Pacific')

without the toStartOfDay ClickHouse function

running this for a particular test action gave 72 results for the trend and 69 for the heat map

Changes

ensures the api/elements/stats endpoint queries from the start of the day

How did you test this code?

adding a unit test for the new behaviour

@pauldambra pauldambra requested review from timgl and mariusandra May 17, 2022 23:02
@pauldambra
Copy link
Member Author

pauldambra commented May 18, 2022

the most recent five elements queries from PostHog cloud at some point on 17th May showed date_from as

Screenshot 2022-05-18 at 09 10 03

so would not always match the equivalent Trend graph

Copy link
Collaborator

@mariusandra mariusandra left a comment

Choose a reason for hiding this comment

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

Basically looks good, though you many need to add if _ != "": (or something nicer) to avoid triggering sentry

Comment on lines +50 to +51
_, date_to, date_params = parse_timestamps(filter, team=self.team)
date_from = date_from_clause("toStartOfDay", True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's too much magic happening behind those two lines for me to be able to confidently approve them. It's the first time I see this code, and I'm not sure of all the places it can be called. However, just following the thread, how do we know in date_from_clause that params['date_from'] is always a thing? I fear we might get unexpected sentry errors...

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

More seriously, I'm pretty confident that the flow through this code is safe... Plus it's easy to revert if it does cause errors :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd guess the place where things can go wrong in either case (trends/stats) is if how the API being called is different? For example, we're reasonably sure the trends API wouldn't bugger out because the primary caller is our code which always puts in a date_from. Idk if we can say the same for stats ( haven't looked for call sites )

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it's only called from toolbar heatmap. The default case is that it isn't sent - in which case it defaults to seven days ago

@pauldambra pauldambra requested a review from mariusandra May 19, 2022 15:00
@pauldambra pauldambra merged commit c999d6d into master May 20, 2022
@pauldambra pauldambra deleted the heatmap_timezone_follow_up branch May 20, 2022 07:12
fuziontech added a commit that referenced this pull request May 20, 2022
* master:
  chore: start stack once in cloud tests (#9879)
  feat(apps): frontend apps (#9831)
  chore: Fix snapshots on master (#9885)
  chore(apps): rename plugins to apps (#9755)
  refactor: Remove constance library dependency, use json-encoded model (#9852)
  chore(clickhouse): avoid creating kafka_events, events_mv (#9863)
  fix(insights): Fix timezone date issues (#9678)
  refactor(plugin-server): refactor the event pipeline (#9829)
  feat(object storage): add unused object storage (#9846)
  fix: make kafka health check timeout test reliable (#9857)
  fix: query elements from start of day (#9827)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants