Skip to content

Conversation

gesh
Copy link
Contributor

@gesh gesh commented Oct 16, 2025

Problem

Hourly trends alerts are not calculated properly.
For the cache key, we use relative dates (like -2h).
We cache the trends value for the past hour using the relative date. Then, after 1 hour, for the next check, we use the cached value, which is not valid now.
Making the less expensive alerts calculations to ignore the caching, so they use the latest data, and prevent spamming alerts.

https://posthoghelp.zendesk.com/agent/tickets/39356

How did you test this code?

Manually + Added some tests

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. posthog/tasks/alerts/trends.py, line 305-309 (link)

    syntax: duplicate call to _pick_series_result - the second call (lines 308-309) does nothing since the result isn't used

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@gesh gesh requested a review from a team October 16, 2025 15:00
Copy link
Contributor

@anirudhpillai anirudhpillai left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for adding the test!
Hourly insight results are cached long enough for this issue to come up, for other intervals you're right, this shouldn't be an issue

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.

2 participants