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

fix(experiments): fix old aggregation_group_type_index being copied to the new query #20889

Closed
wants to merge 3 commits into from

Conversation

jurajmajerik
Copy link
Contributor

@jurajmajerik jurajmajerik commented Mar 13, 2024

I've committed yesterday's solution just for reference.

Earlier discussion for reference: #20815 (comment)

Problem

After changing the "Participant type" from any group to Persons, updateQuerySource receives querySource without aggregation_group_type_index
It then creates a new query, however, it copies all the values from the existing query.source —> this is where the old aggregation_group_type_index gets introduced.

You suggested fixing this in:

  • cleanFilters - this will have no effect, as querySource received in updateQuerySource is already correctly cleaned up of aggregation_group_type_index
  • queryNodeToFilter - this won’t help either, because at this point, the old value has been added back to the querySource, and because it’s not undefined, it will stay there

So to sum up, updateQuerySource is exactly where the copying of the old value takes place. How else then should it be fixed? 🤔

@jurajmajerik jurajmajerik requested a review from neilkakkar March 13, 2024 09:30
@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.

@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

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

} as Node)
} as NodeWithSource

if (querySource['aggregation_group_type_index'] === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, the problem with this fix is that it breaks what updateQuerySource is supposed to do: i.e only do additive updates. I'm not 100% sure where the fix should go, but definitely sure this isn't the right way.

Consider how there's no problem with this in regular insights, this just introduces an exception that shouldn't be there. For example, now, whenever we call updateQuerySource without the aggregation_group_type_index, it resets it to persons aggregation, which is not ok.

The problem here that needs to be fixed is in our code: Our querySource never returns an undefined for aggregation_group_type_index, and instead omits it, because there are several 'gates' it needs to pass through:

  1. Make sure cleanFilters returns the undefined value (I think this wasn't reverted from the previous PR - we stopped passing in the aggregation group type index here)
  2. Make sure filtersToQueryNode also returns the group_type_index, which is currently removed when undefined.

Now, it doesn't make sense for me to update filtersToQueryNode - it's doing the right thing it's supposed to do, discard every random empty thing and create a clean Query node. Our problem is that experiments want to use the output of this for additive updates, where the group type index being undefined needs to pass through.

Thus, I suggest creating a helper function for experiments that:

  1. Takes the output of filtersToQueryNode and adds props we definitely want to be sent alongside. This isolates the change to our experiments code.
  2. Or, add a non-empty configuration option to filtersToQueryNode so it returns all undefined things as well.

Currently prefer (1), but filtersToQueryNode seem to be majorly used by experiments only. @thmsobrmlr since you wrote this, any ideas / is there a different filter to query function we should be using for updates? (or @mariusandra )

The problematic bits in question start here: https://github.com/PostHog/posthog/blob/master/frontend/src/scenes/experiments/experimentLogic.tsx#L386

Copy link
Contributor

Choose a reason for hiding this comment

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

Without looking deeper (1) sounds like a good suggestion. I'll try to have a look at this later as well.

is there a different filter to query function we should be using for updates?

No, there is only the filtersToQueryNode function.

Also note that we're actively working on removing all filters and the filtersToQueryNode and cleanFilters functions with it. If you're doing a bigger refactoring, transitioning all the way to queries is the way to go.

Copy link
Collaborator

@mariusandra mariusandra Mar 13, 2024

Choose a reason for hiding this comment

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

Yes, not using filters, but query directly is the way to go. All insights use query natively for example, and we're deprecating this old style.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm on the backend we're still storing filters for experiments, so not yet ready to completely get rid of them, but I'm guessing what you're suggesting is that while we're in client-side land, all interactions ought to happen using the query, and then at the end when saving we can convert it into a filter so the backend can continue using it to calculate metrics?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah exactly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

All HogQL insights use "query" in the backend natively, and once we're done with the refactor and ready to drop legacy insights, the "filters" object will no longer be used anywhere... except for the experiments backend then 😄.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Experiments backend passes on the filter to Trends / Funnel query runner, we don't do any manual custom queries, so I guess once we're ready to drop legacy insights we should easily migrate too :D - let me know when you're about ready, I'm assuming you'll have some way to convert saved insight filters to query, we'll need a similar mechanism for experiments.

(Juraj - your call to make for the frontend query changes, my suggestion would be to do this Query migration right after we've done the UI revamp (vs. now), unless in the middle of the revamp you feel things become much easier to do the query migration as well)

@neilkakkar neilkakkar self-assigned this Mar 13, 2024
@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Contributor

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@neilkakkar
Copy link
Collaborator

Done in #21220

@neilkakkar neilkakkar closed this Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants