Repository navigation
perf(billing): Filter usage query to billable outcomes - #127348
Merged
Merged
Conversation
Every aggregate in the billing usage query only counts ACCEPTED, FILTERED and RATE_LIMITED outcomes, but the WHERE clause didn't filter on outcome. ClickHouse read and grouped rows for every outcome type, including CLIENT_DISCARD, which has many distinct reasons. Filtering on outcome lets ClickHouse skip those rows using the outcome column in the sort key. The usage sums don't change. Two things do: last_usage_ts now reflects the latest billable outcome instead of the latest outcome of any type, and days with only non-billable outcomes no longer show up as all-zero entries.
noahsmartin
marked this pull request as ready for review
October 14, 2026 04:59
volokluev
approved these changes
Oct 14, 2026
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an
outcome IN (ACCEPTED, FILTERED, RATE_LIMITED)condition to the WHERE clause of the billing platform's usage query (_build_query). Bothget_usageandget_usage_by_projectuse this query.Every aggregate in the query (total, accepted, dropped, filtered, over_quota, spike_protection, dynamic_sampling) already counts only those three outcomes. Because the WHERE clause didn't filter on outcome, ClickHouse still read and grouped INVALID, ABUSE, CLIENT_DISCARD and CARDINALITY_LIMITED rows, then discarded them in the sums