feat(outcomes): Route billing referrers to daily outcomes table#7877
Draft
feat(outcomes): Route billing referrers to daily outcomes table#7877
Conversation
volokluev
reviewed
Apr 15, 2026
| outcomes_key = ( | ||
| self.daily_storage if query_settings.get_use_daily() else self.hourly_storage | ||
| ) | ||
| elif hasattr(query_settings, "referrer") and query_settings.referrer.startswith("billing."): |
Member
There was a problem hiding this comment.
the query AST has the time range in it, it would be better to inspect that and route to the daily storage if it's greater than 90d
de21b4b to
93b513a
Compare
…retention Queries whose lower timestamp bound is older than 90 days are now routed to the outcomes_daily table instead of outcomes_hourly. The hourly table only retains ~90 days of data, so older queries would return incomplete results. Uses get_time_range() to extract the lower timestamp bound from the query AST. TimeSeriesProcessor runs before storage selection in the entity pipeline, so datetime Literals are available for inspection. Existing behavior is preserved: - OutcomesQuerySettings(use_daily=True) still routes to daily - OutcomesQuerySettings(use_daily=False) still routes to hourly - Queries within the 90-day window still route to hourly
Billing queries need 13-month retention available only in the daily table. Even when the query's time range is within the 90-day hourly window, billing queries should route to daily for consistent results across the full billing history. Add a referrer-based fallback: queries with a referrer starting with "billing." are routed to the daily table. This is triggered by sentry's UsageService which uses referrer "billing.usage_service.clickhouse". Routing priority: 1. OutcomesQuerySettings — explicit use_daily flag 2. Time-range — lower timestamp bound older than 90 days 3. Referrer — starts with "billing." 4. Default — hourly
93b513a to
a67cf2c
Compare
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.
Summary
Add hybrid routing to
OutcomesStorageSelectorso queries are directed to the correct outcomes table based on both time-range and referrer:use_dailyflag (unchanged)."billing.", route to daily (billing queries need 13-month retention only available in the daily table, triggered by sentry'sUsageService).The time-range check uses
get_time_range()to extract the query's timestamp lower bound and compares it against a 90-day threshold. This ensures queries that reach beyond hourly retention are automatically served from the daily table, regardless of referrer.Test plan
OutcomesQuerySettingstest cases pass (use_daily flag routing unchanged)