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: record API usage for any type of query #26259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raquelmsmith
Copy link
Member

Problem

We want to start billing for API usage against the /query endpoint so we can lift the rate limits on it. First step: measure the usage we are already seeing to this endpoint. But, currently usage reports only capture hogql queries, but we want to charge for any type of query.

Changes

Records usage for any type of query hitting the API.

Renames the usage record key because it's not for hogql specifically any more, but for any type of query hitting /query.

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

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

How did you test this code?

Updated the tests and added a new one for api-specific queries.

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.

Why not. Left in a code nit as well.

@@ -580,7 +580,7 @@ def get_teams_with_hogql_metric(
FROM clusterAllReplicas({CLICKHOUSE_CLUSTER}, system.query_log)
WHERE (type = 'QueryFinish' OR type = 'ExceptionWhileProcessing')
AND is_initial_query = 1
AND query_type IN (%(query_types)s)
AND (%(query_types)s IS NULL OR query_type IN (%(query_types)s))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: This generates some strange code like:

    AND (NULL IS NULL
         OR query_type IN (NULL))

and

    AND (['EventsQuery'] IS NULL
         OR query_type IN (['EventsQuery']))

Since query_types is a python variable, wouldn't it be better to rewrite the entire clause based on its contents?

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.

2 participants