-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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(hogql): run filter based insights via hogql (undo revert) #17645
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ab76dcb
Revert "revert: "feat(hogql): run filter based insights via hogql (#1…
thmsobrmlr 77822d5
fix feature flag handling for endpoints without auth
thmsobrmlr 18d9edb
add anonymous type
thmsobrmlr 9bbf201
Merge branch 'master' into unrevert-17611
thmsobrmlr f012265
Merge branch 'master' into unrevert-17611
thmsobrmlr 914f504
Update UI snapshots for `chromium` (2)
github-actions[bot] 86943c7
Merge branch 'master' into unrevert-17611
thmsobrmlr 1e507ff
Update UI snapshots for `chromium` (1)
github-actions[bot] 6936fb7
Update UI snapshots for `chromium` (2)
github-actions[bot] c16cc2a
Merge branch 'master' into unrevert-17611
thmsobrmlr 41bab66
Update UI snapshots for `chromium` (1)
github-actions[bot] 594d08e
fix test
thmsobrmlr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
posthog/hogql_queries/legacy_compatibility/feature_flag.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import posthoganalytics | ||
from django.conf import settings | ||
from posthog.cloud_utils import is_cloud | ||
from posthog.models.user import User | ||
|
||
|
||
def hogql_insights_enabled(user: User) -> bool: | ||
if settings.HOGQL_INSIGHTS_OVERRIDE is not None: | ||
return settings.HOGQL_INSIGHTS_OVERRIDE | ||
|
||
# on PostHog Cloud, use the feature flag | ||
if is_cloud(): | ||
if not hasattr(user, "distinct_id"): # exclude api endpoints that don't have auth from the flag | ||
return False | ||
|
||
return posthoganalytics.feature_enabled( | ||
"hogql-insights", | ||
user.distinct_id, | ||
person_properties={"email": user.email}, | ||
only_evaluate_locally=True, | ||
send_feature_flag_events=False, | ||
) | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
posthog/hogql_queries/legacy_compatibility/process_insight.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from posthog.caching.fetch_from_cache import InsightResult | ||
from posthog.hogql_queries.legacy_compatibility.filter_to_query import filter_to_query | ||
from posthog.hogql_queries.lifecycle_query_runner import LifecycleQueryRunner | ||
from posthog.hogql_queries.query_runner import CachedQueryResponse | ||
from posthog.models.filters.filter import Filter as LegacyFilter | ||
from posthog.models.filters.path_filter import PathFilter as LegacyPathFilter | ||
from posthog.models.filters.retention_filter import RetentionFilter as LegacyRetentionFilter | ||
from posthog.models.filters.stickiness_filter import StickinessFilter as LegacyStickinessFilter | ||
from posthog.models.insight import Insight | ||
from posthog.models.team.team import Team | ||
from posthog.types import InsightQueryNode | ||
|
||
|
||
# sync with frontend/src/queries/utils.ts | ||
def is_insight_with_hogql_support(insight: Insight): | ||
if insight.filters.get("insight") == "LIFECYCLE": | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
def _insight_to_query(insight: Insight, team: Team) -> InsightQueryNode: | ||
if insight.filters.get("insight") == "RETENTION": | ||
filter = LegacyRetentionFilter(data=insight.filters, team=team) | ||
elif insight.filters.get("insight") == "PATHS": | ||
filter = LegacyPathFilter(data=insight.filters, team=team) | ||
elif insight.filters.get("insight") == "STICKINESS": | ||
filter = LegacyStickinessFilter(data=insight.filters, team=team) | ||
else: | ||
filter = LegacyFilter(data=insight.filters, team=team) | ||
return filter_to_query(filter) | ||
|
||
|
||
def _cached_response_to_insight_result(response: CachedQueryResponse) -> InsightResult: | ||
result = InsightResult(**response.model_dump()) | ||
return result | ||
|
||
|
||
def process_insight(insight: Insight, team: Team) -> InsightResult: | ||
query = _insight_to_query(insight, team) | ||
response = LifecycleQueryRunner(query=query, team=team).run(refresh_requested=False) | ||
return _cached_response_to_insight_result(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types can help somewhat here: