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

chore(environments): Calculate cohorts for each environment #26554

Merged
merged 19 commits into from
Dec 5, 2024

Conversation

Twixes
Copy link
Member

@Twixes Twixes commented Nov 29, 2024

Problem

Appendix A of the environments implementation plan.

Changes

recalculate_cohortpeople() and clear_stale_cohortpeople() now insert and clear cohort people for every team the cohort is available in, instead of just the one the cohort was created in.

How did you test this code?

Added a test case to test_cohort.py. Definitely let me know how to improve test coverage!

@Twixes Twixes marked this pull request as draft December 2, 2024 00:39
@Twixes Twixes force-pushed the environment-cohorts branch from 6ad03fc to 7aa6034 Compare December 2, 2024 17:14
@Twixes Twixes force-pushed the environment-cohorts branch from f427eef to a34bd33 Compare December 3, 2024 18:09
@Twixes Twixes force-pushed the environment-cohorts branch from c624701 to 9ad70ee Compare December 4, 2024 08:12
@Twixes Twixes marked this pull request as ready for review December 4, 2024 13:06
@@ -240,22 +238,31 @@ def update(self, cohort: Cohort, validated_data: dict, *args: Any, **kwargs: Any

is_deletion_change = deleted_state is not None and cohort.deleted != deleted_state
if is_deletion_change:
relevant_team_ids = (
Team.objects.order_by("id").filter(project_id=cohort.team.project_id).values_list("id", flat=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

curious why we need order_by("id") here

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question, I don't remember 😄 It's definitely superfluous here, removed

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 ok to me but will let Sandy comment on how this fits in with his rewrite + maybe @dmarticus as feature flags uses behavioural cohorts

Copy link
Contributor

@aspicer aspicer left a comment

Choose a reason for hiding this comment

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

lgtm!

@Twixes Twixes merged commit dcb77c3 into master Dec 5, 2024
89 checks passed
@Twixes Twixes deleted the environment-cohorts branch December 5, 2024 22:29
Copy link

sentry-io bot commented Dec 5, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ TypeError: can only concatenate str (not "int") to str posthog.tasks.calculate_cohort.clear_stale_cohort View Issue
  • ‼️ CHQueryErrorTooManyParts: DB::Exception: Too many parts (3140 with average size of 185.43 MiB) in table 'posthog.cohortpeop... posthog.tasks.calculate_cohort.calculate_cohort_ch View Issue
  • ‼️ CHQueryErrorTimeoutExceeded: DB::Exception: Timeout exceeded: elapsed 600.042794258 seconds, maximum: 600. Stack trace: posthog.tasks.calculate_cohort.calculate_cohort_ch View Issue
  • ‼️ CHQueryErrorNotEnoughSpace: DB::Exception: Cannot reserve 1.00 MiB, not enough space. Stack trace: posthog.tasks.calculate_cohort.calculate_cohort_ch View Issue
  • ‼️ CHQueryErrorTableIsReadOnly: DB::Exception: Table is in readonly mode: replica_path=/clickhouse/tables/noshard/posthog.cohortp... posthog.tasks.calculate_cohort.calculate_cohort_ch View Issue

Did you find this useful? React with a 👍 or 👎

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