Skip to content

Commit

Permalink
feat: add and handle never drop data field (#17978)
Browse files Browse the repository at this point in the history
* add and handle never drop data field

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
raquelmsmith and github-actions[bot] authored Oct 16, 2023
1 parent 27e183b commit 723238e
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 72 deletions.
20 changes: 12 additions & 8 deletions ee/api/test/__snapshots__/test_organization_resource_access.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='organization_resource_access-list',route='api/organizations/%28%3FP%3Cparent_lookup_organization_id%3E%5B%5E/.%5D%2B%29/resource_access/%3F%24'*/
Expand All @@ -62,12 +63,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='organization_resource_access-list',route='api/organizations/%28%3FP%3Cparent_lookup_organization_id%3E%5B%5E/.%5D%2B%29/resource_access/%3F%24'*/
Expand Down Expand Up @@ -143,12 +145,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='organization_resource_access-list',route='api/organizations/%28%3FP%3Cparent_lookup_organization_id%3E%5B%5E/.%5D%2B%29/resource_access/%3F%24'*/
Expand Down Expand Up @@ -250,12 +253,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='organization_resource_access-list',route='api/organizations/%28%3FP%3Cparent_lookup_organization_id%3E%5B%5E/.%5D%2B%29/resource_access/%3F%24'*/
Expand Down
5 changes: 5 additions & 0 deletions ee/billing/billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ def update_org_details(self, organization: Organization, billing_status: Billing
organization.available_product_features = data["available_product_features"]
org_modified = True

never_drop_data = data.get("never_drop_data", None)
if never_drop_data != organization.never_drop_data:
organization.never_drop_data = never_drop_data
org_modified = True

if org_modified:
organization.save()

Expand Down
5 changes: 4 additions & 1 deletion ee/billing/quota_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from posthog.models.team.team import Team
from posthog.redis import get_client
from posthog.tasks.usage_report import (
convert_team_usage_rows_to_dict,
get_teams_with_billable_event_count_in_period,
get_teams_with_recording_count_in_period,
convert_team_usage_rows_to_dict,
)
from posthog.utils import get_current_day

Expand Down Expand Up @@ -80,6 +80,9 @@ def org_quota_limited_until(organization: Organization, resource: QuotaResource)
is_quota_limited = usage + todays_usage >= limit + OVERAGE_BUFFER[resource]
billing_period_end = round(dateutil.parser.isoparse(organization.usage["period"][1]).timestamp())

if is_quota_limited and organization.never_drop_data:
return None

if is_quota_limited and billing_period_end:
return billing_period_end

Expand Down
18 changes: 17 additions & 1 deletion ee/billing/test/test_quota_limiting.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import time
from uuid import uuid4


from dateutil.relativedelta import relativedelta
from django.utils import timezone
from django.utils.timezone import now
Expand Down Expand Up @@ -185,6 +184,23 @@ def test_org_quota_limited_until(self):
self.organization.usage["recordings"]["usage"] = 1100 # Over limit + buffer
assert org_quota_limited_until(self.organization, QuotaResource.RECORDINGS) == 1612137599

def test_over_quota_but_not_dropped_org(self):
self.organization.usage = None
assert org_quota_limited_until(self.organization, QuotaResource.EVENTS) is None

self.organization.usage = {
"events": {"usage": 100, "limit": 90},
"recordings": {"usage": 100, "limit": 90},
"period": ["2021-01-01T00:00:00Z", "2021-01-31T23:59:59Z"],
}
self.organization.never_drop_data = True

assert org_quota_limited_until(self.organization, QuotaResource.EVENTS) is None
assert org_quota_limited_until(self.organization, QuotaResource.RECORDINGS) is None

# reset for subsequent tests
self.organization.never_drop_data = False

def test_sync_org_quota_limits(self):
with freeze_time("2021-01-01T12:59:59Z"):
other_team = create_team(organization=self.organization)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: ClickhouseTestExperimentSecondaryResults.test_basic_secondary_metric_results
'
/* user_id:128 celery:posthog.celery.sync_insight_caching_state */
/* user_id:126 celery:posthog.celery.sync_insight_caching_state */
SELECT team_id,
date_diff('second', max(timestamp), now()) AS age
FROM events
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/scenes/billing/billingLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ export const billingLogic = kea<billingLogicType>([
return {
status: 'error',
title: 'Usage limit exceeded',
message: `You have exceeded the usage limit for ${productOverLimit.name}. Please upgrade your plan or data loss may occur.`,
message: `You have exceeded the usage limit for ${productOverLimit.name}. Please
${productOverLimit.subscribed ? 'increase your billing limit' : 'upgrade your plan'}
or data loss may occur.`,
}
}

Expand Down
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name
ee: 0015_add_verified_properties
otp_static: 0002_throttling
otp_totp: 0002_auto_20190420_0723
posthog: 0353_add_5_minute_interval_to_batch_exports
posthog: 0354_organization_never_drop_data
sessions: 0001_initial
social_django: 0010_uid_db_index
two_factor: 0007_auto_20201201_1019
30 changes: 18 additions & 12 deletions posthog/api/test/__snapshots__/test_action.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand All @@ -263,12 +264,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand Down Expand Up @@ -368,12 +370,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand Down Expand Up @@ -402,12 +405,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand Down Expand Up @@ -557,12 +561,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand All @@ -580,12 +585,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organization"
WHERE "posthog_organization"."id" = '00000000-0000-0000-0000-000000000000'::uuid
LIMIT 21 /*controller='project_actions-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/actions/%3F%24'*/
Expand Down
15 changes: 9 additions & 6 deletions posthog/api/test/__snapshots__/test_annotation.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_annotations-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/annotations/%3F%24'*/
Expand Down Expand Up @@ -357,12 +358,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_annotations-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/annotations/%3F%24'*/
Expand Down Expand Up @@ -481,12 +483,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='project_annotations-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/annotations/%3F%24'*/
Expand Down
5 changes: 3 additions & 2 deletions posthog/api/test/__snapshots__/test_decide.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='team-detail',route='api/projects/%28%3FP%3Cid%3E%5B%5E/.%5D%2B%29/%3F%24'*/
Expand Down
5 changes: 3 additions & 2 deletions posthog/api/test/__snapshots__/test_element.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@
"posthog_organization"."is_member_join_email_enabled",
"posthog_organization"."enforce_2fa",
"posthog_organization"."customer_id",
"posthog_organization"."available_features",
"posthog_organization"."available_product_features",
"posthog_organization"."usage",
"posthog_organization"."never_drop_data",
"posthog_organization"."setup_section_2_completed",
"posthog_organization"."personalization",
"posthog_organization"."domain_whitelist"
"posthog_organization"."domain_whitelist",
"posthog_organization"."available_features"
FROM "posthog_organizationmembership"
INNER JOIN "posthog_organization" ON ("posthog_organizationmembership"."organization_id" = "posthog_organization"."id")
WHERE "posthog_organizationmembership"."user_id" = 2 /*controller='element-stats',route='api/element/stats/%3F%24'*/
Expand Down
Loading

0 comments on commit 723238e

Please sign in to comment.