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: Add group support to the lifecycle insight #21876

Merged
merged 32 commits into from May 1, 2024

Conversation

aspicer
Copy link
Contributor

@aspicer aspicer commented Apr 26, 2024

Problem

Lifecycle insights (like others) should support groups for paid users.

Changes

image image image image

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

4 snapshot changes in total. 0 added, 4 modified, 0 deleted:

Triggered by this commit.

👉 Review this PR's diff of snapshots.

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.

This is off to a very solid start 👍. I left some comments inline and answered the questions.

Comment on lines 291 to 309
event_filters = [self.event_filter]

if self.group_type_index is not None:
group_index = int(self.group_type_index)
if 0 <= group_index <= 4:
target_field = f"$group_{group_index}"

event_filters.append(
ast.Not(
expr=ast.Call(
name="has",
args=[
ast.Array(exprs=[ast.Constant(value="")]),
ast.Field(chain=["events", f"$group_{self.group_type_index}"]),
],
),
),
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should go directly into the self.event_filter() property. Something else could also access this property on the query runner to get the same event set, and would then get inconsistent results.

@@ -95,6 +95,7 @@ def to_query(self) -> ast.SelectQuery | ast.SelectUnionQuery:
def to_actors_query(
self, day: Optional[str] = None, status: Optional[str] = None
) -> ast.SelectQuery | ast.SelectUnionQuery:
# should I update this?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could see this being a followup PR, however yes, somebody one day should. This is the query that opens when you click on one of the bars on the chart. I don't think it's that many extra steps to get this working.

)
)
for timestamp, groups in timestamps_and_groups:
# not sure this is right, this maybe should put groups in directly?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Possibly. Many other tests do this:

GroupTypeMapping.objects.create(team=self.team, group_type="organization", group_type_index=0)
GroupTypeMapping.objects.create(team=self.team, group_type="company", group_type_index=1)
create_group(
team_id=self.team.pk,
group_type_index=0,
group_key="org:5",
properties={"industry": "finance"},
)
create_group(
team_id=self.team.pk,
group_type_index=0,
group_key="org:6",
properties={"industry": "technology"},
)

@@ -36,6 +36,544 @@ def create_action(**kwargs):
return action


class TestLifecycleQueryRetentionGroupAggregation(ClickhouseTestMixin, APIBaseTest):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: We've usually been pretty lazy and adding all tests inside one large class. This can make it easier to "run all" in PyCharm, but we use that almost never, and I'm not against splitting it up. However might be good to move the new stuff to the end of the file.

@mariusandra
Copy link
Collaborator

Annoyingly I couldn't run it locally yet. I'm still having some trouble with the billing service... 🙈

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 1)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@aspicer aspicer changed the title Aspicer/lifecycle groups feat: Add group support to the lifecycle insight Apr 30, 2024
@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

Copy link
Contributor

github-actions bot commented Apr 30, 2024

Size Change: 0 B

Total Size: 1.05 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.05 MB

compressed-size-action

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@aspicer aspicer marked this pull request as ready for review April 30, 2024 14:00
@aspicer aspicer merged commit 7f170aa into master May 1, 2024
104 checks passed
@aspicer aspicer deleted the aspicer/lifecycle_groups branch May 1, 2024 07:43
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.

None yet

3 participants