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(data-warehouse): dw billing #18168

Merged
merged 93 commits into from
Nov 16, 2023
Merged

chore(data-warehouse): dw billing #18168

merged 93 commits into from
Nov 16, 2023

Conversation

EDsCODE
Copy link
Member

@EDsCODE EDsCODE commented Oct 24, 2023

Problem

  • need to set up billing for data warehouse imports

Changes

  • Adds billable_data_warehouse_rows_synced to usage reports
  • this tracking happens by directly pulling from the airbyte api to ensure exact data accuracy that is being billed on

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

How did you test this code?

@EDsCODE EDsCODE requested a review from raquelmsmith November 14, 2023 03:11
Copy link
Member

@raquelmsmith raquelmsmith left a comment

Choose a reason for hiding this comment

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

A couple optimizations (maybe?) but I think this all makes sense!

ee/billing/quota_limiting.py Outdated Show resolved Hide resolved
ee/billing/quota_limiting.py Outdated Show resolved Hide resolved
ee/billing/test/test_quota_limiting.py Outdated Show resolved Hide resolved
posthog/tasks/warehouse.py Outdated Show resolved Hide resolved
posthog/tasks/warehouse.py Show resolved Hide resolved
posthog/tasks/warehouse.py Show resolved Hide resolved
Comment on lines 89 to 100
def check_external_data_source_billing_limit_by_team(team_id: int) -> None:
from posthog.warehouse.external_data_source.connection import deactivate_connection_by_id, activate_connection_by_id
from ee.billing.quota_limiting import list_limited_team_tokens, QuotaResource

limited_teams_rows_synced = list_limited_team_tokens(QuotaResource.ROWS_SYNCED)

team = Team.objects.get(pk=team_id)
all_active_connections = ExternalDataSource.objects.filter(team=team, status__in=["running", "succeeded"])
all_inactive_connections = ExternalDataSource.objects.filter(team=team, status="inactive")

# TODO: consider more boundaries
if team_id in limited_teams_rows_synced:
Copy link
Member

Choose a reason for hiding this comment

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

If I'm understanding this correctly, this only runs every two hours. But the quota_limiting tasks run every 30 mins. So we could theoretically up to 2 hours behind in turning off their syncs. Is there a reason to do it here with the task that runs every 2 hours instead of when we check the current usage against billing limits every 30 mins?

In other words, as soon as we realize in quota_limiting.py that we should be turning them off, why don't we do it then?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah we could, then there would be no need for the tokens. I was trying to follow the pattern where we set the teams that will be limited and then use the token to determine which teams to limit (like how events and recordings are done)

Copy link
Member

Choose a reason for hiding this comment

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

ok up to you, either works 👍

@EDsCODE EDsCODE marked this pull request as ready for review November 14, 2023 19:50
@posthog-bot
Copy link
Contributor

Hey @EDsCODE! 👋
This pull request seems to contain no description. Please add useful context, rationale, and/or any other information that will help make sense of this change now and in the distant Mars-based future.

@EDsCODE EDsCODE merged commit 820e6a7 into master Nov 16, 2023
68 checks passed
@EDsCODE EDsCODE deleted the dw-airbyte-billing branch November 16, 2023 19:40
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.

4 participants