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

test(insights): Run all tests with filters-based insights using HogQL #21861

Merged
merged 19 commits into from
May 23, 2024

Conversation

Twixes
Copy link
Member

@Twixes Twixes commented Apr 25, 2024

Changes

Let's make the HogQL engine the default. Still leaving a strategy with the legacy engine running.
This will allow us to catch problems in the saved insights/dashboards layer, and later on when converting /insight/{trend,funnel,etc}.

@posthog-bot

This comment was marked as outdated.

@Twixes Twixes force-pushed the hogql-insights-ci branch 2 times, most recently from 1cac259 to dd58b80 Compare May 8, 2024 19:05
@Twixes Twixes changed the base branch from master to query-in-background-reloads May 8, 2024 19:06
@Twixes Twixes force-pushed the hogql-insights-ci branch from dd58b80 to a73325d Compare May 8, 2024 19:06
@posthog-bot posthog-bot removed the stale label May 9, 2024
@Twixes Twixes force-pushed the hogql-insights-ci branch from 21ee586 to 1c3f26f Compare May 9, 2024 22:03
@Twixes Twixes force-pushed the query-in-background-reloads branch 2 times, most recently from 9ce7475 to f09821a Compare May 9, 2024 22:41
@Twixes Twixes force-pushed the hogql-insights-ci branch from 3049815 to 92c1c05 Compare May 10, 2024 09:04
Base automatically changed from query-in-background-reloads to master May 15, 2024 14:22
@Twixes Twixes force-pushed the hogql-insights-ci branch 2 times, most recently from 1d83564 to 50a471f Compare May 20, 2024 16:49
@Twixes Twixes force-pushed the hogql-insights-ci branch from 96d5525 to dd9aa72 Compare May 22, 2024 10:10
@@ -326,7 +326,6 @@ def create(self, validated_data: dict, *args: Any, **kwargs: Any) -> Insight:
raise serializers.ValidationError("Dashboard not found")

DashboardTile.objects.create(insight=insight, dashboard=dashboard, last_refresh=now())
insight.last_refresh = now() # set last refresh if the insight is on at least one dashboard
Copy link
Member Author

Choose a reason for hiding this comment

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

This has not been used in a long time and not sure it ever actually worked. The actual last_refresh is in InsightCachingState at the insight level, and in the cached result packages themselves

@Twixes Twixes marked this pull request as ready for review May 23, 2024 17:12
@Twixes Twixes force-pushed the hogql-insights-ci branch from 68f5bd6 to 483d786 Compare May 23, 2024 17:16
Comment on lines +151 to +157
if isinstance(cache_key, str) and isinstance(last_refresh, str):
update_cached_state( # Updating the relevant InsightCachingState
insight.team_id,
cache_key,
last_refresh,
result=None, # Not caching the result here, since in HogQL this is the query runner's responsibility
)
Copy link
Member Author

Choose a reason for hiding this comment

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

The only behavioral change in this PR: TestDashboard::test_refresh_cache revealed we weren't updating InsightCachingState in here. This change brings us fully back on track with tracking which insights need a background refresh

@Twixes Twixes requested a review from a team May 23, 2024 19:12
@Twixes Twixes changed the title ci: Run core backend tests with both HogQL and legacy insights test(insights): Run all tests with filters-based insights using HogQL May 23, 2024
Copy link
Contributor

@thmsobrmlr thmsobrmlr left a comment

Choose a reason for hiding this comment

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

Changes look good. 👍 to merge this in once tests pass

This will allow us to catch problems in the saved insights/dashboards layer, and later on when converting /insight/{trend,funnel,etc}.

I don't think we ever want to convert these, since they are replaced by /query, right?

@Twixes Twixes enabled auto-merge (squash) May 23, 2024 20:36
@Twixes
Copy link
Member Author

Twixes commented May 23, 2024

As for /insight/{trend,funnel,etc}, the issue is that we definitely want to throw out the code of legacy insights, and these run-filters-ad-hoc endpoints are a blocker in their current state. There are two paths that I see right now:

  1. We just remove them – but it's certain that there are users somewhere with cron jobs or whatever programmed to get data out of PostHog by hitting these endpoints. Pulling the plug would cause those users massive pain.
  2. We keep the endpoints, but wrap them all in filters_to_query(). The legacy code gets the boot, while API users are (generally) unharmed.

What do you think @thmsobrmlr? Let me know if you have an idea to refine this

@Twixes Twixes force-pushed the hogql-insights-ci branch from 1989825 to 95cc8be Compare May 23, 2024 21:20
@Twixes Twixes merged commit b1cb745 into master May 23, 2024
126 of 149 checks passed
@Twixes Twixes deleted the hogql-insights-ci branch May 23, 2024 21:41
xrdt pushed a commit that referenced this pull request May 24, 2024
…QL (#21861)

* ci: Run core backend tests with both HogQL and legacy insights

* Double the number of tests

* Fix env var setting

* Add some HOGQL_INSIGHTS_OVERRIDE overrides in tests

* Mark `Insight.last_refresh` as deprecated

* Fix bad merge

* Update query snapshots

* Update query snapshots

* Update test_team.py

* Actually remove legacy backend from matrix

* Update test_fetch_from_cache.py

* Use `update_cached_state` in `calculate_for_query_based_insight()`

* Clean up CI changes and a comment

* Fix `update_cached_state` typing

* Update test_fetch_from_cache.py

* Update test_insight_cache.py

* Update test_insight_cache.py

* Clarify `generate_insight_cache_key` as legacy function

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
timgl pushed a commit that referenced this pull request May 24, 2024
…QL (#21861)

* ci: Run core backend tests with both HogQL and legacy insights

* Double the number of tests

* Fix env var setting

* Add some HOGQL_INSIGHTS_OVERRIDE overrides in tests

* Mark `Insight.last_refresh` as deprecated

* Fix bad merge

* Update query snapshots

* Update query snapshots

* Update test_team.py

* Actually remove legacy backend from matrix

* Update test_fetch_from_cache.py

* Use `update_cached_state` in `calculate_for_query_based_insight()`

* Clean up CI changes and a comment

* Fix `update_cached_state` typing

* Update test_fetch_from_cache.py

* Update test_insight_cache.py

* Update test_insight_cache.py

* Clarify `generate_insight_cache_key` as legacy function

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
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