Repository navigation
Description
Problem Description
uv run devops roadmap eval grades --window 7d without --repo fails with Loki HTTP 400 (maximum number of series (500) reached for a single query).
Query 1 (GradeQueryKind.COUNTS: sum by (roadmap_job, repo, version, success, infra) (count_over_time(... [7d]))) exceeds Loki's 500-series per-query limit because count_over_time evaluates over all unaggregated extracted and stream labels across 7 days before sum by (...) runs.
Adding --repo dan-petty/devops-cli or using --window 48h stays below 500 series, while an unfiltered 7-day report across all repositories fails.
Reproduction Steps
- Port-forward Loki to local port 13104 (or set
loki.url). - Run
uv run devops roadmap eval grades --window 7d --loki-url http://127.0.0.1:13104.
Expected vs Actual Behavior
Expected: devops roadmap eval grades --window 7d returns the 7-day grade table across all managed repositories.
Actual: Loki rejects Query 1 (COUNTS over [7d]) with HTTP 400 Bad Request because the internal series count before aggregation passes 500.
Environment Diagnostics
- Query builder:
src/devops_cli/roadmap/job_grade_report.py:337-379(_lines,_query) - Verified against live cluster Loki on 2026-11-25 (
first_passesanddraftedsucceeded;countsfailed with 500-series error).
Logs, Traces, or Terminal Output
✗ Loki failed after 1 attempt in 0.9 s: HTTP 400 Bad Request: maximum number of series (500) reached for a single query; consider reducing query cardinality by adding more specific stream selectors, reducing the time range, or aggregating results with functions like sum(), count() or topk(). The service refused the request: correct the request, then try again.
Proposed design
Problem statement
Keep only the labels that each grade query uses, and split a count window when Loki still rejects it. devops roadmap eval grades --window 7d fails without --repo. Loki answers the COUNTS query with HTTP 400 and the 500-series limit. The query passes every extracted label to count_over_time, so a 7-day range holds more series than the limit. The fix removes the unused labels at the source and adds a bounded window split for the count queries.
Acceptance criteria
Requirement: Counts query label set
The COUNTS grade query MUST pass only the labels that its aggregation names to the range aggregation.
Scenario: Seven-day counts query
- WHEN a test builds the COUNTS query for the 7d window with no repo
- THEN the expression has a
keepstage before[7d]whose labels equal thesum bylabels, and no other extracted label reaches the range aggregation.
Requirement: Classes query label set
The CLASSES grade query MUST pass only the labels that its aggregation and its filters name to the range aggregation.
Scenario: Seven-day classes query
- WHEN a test builds the CLASSES query for the 7d window
- THEN the
keeplabels equal thesum bylabels plussuccessandinfra, and thesuccess="false"andinfra="false"filters stay.
Requirement: Drafted query label set
The DRAFTED grade query MUST pass only the labels that its aggregation names to the range aggregation.
Scenario: Seven-day drafted query
- WHEN a test builds the DRAFTED query for the 7d window
- THEN the
keeplabels equal thesum bylabels, and theroadmap_job,resultandinfrafilters stay.
Requirement: First-passes query label set
The FIRST_PASSES grade query MUST pass only the labels that its aggregation names to the range aggregation.
Scenario: Seven-day first-passes query
- WHEN a test builds the FIRST_PASSES query for the 7d window
- THEN the
keeplabels equal thesum bylabels, and thesuccessandinfrafilters stay.
Requirement: Efficiency query label set
Each efficiency grade query MUST pass only the labels that its template aggregates by, plus the label that it unwraps, to the range aggregation.
Scenario: Seven-day efficiency query
- WHEN a test builds each efficiency query for the 7d window
- THEN the
keeplabels equal the template'ssum bylabels plus the unwrapped count label.
Requirement: Split on the series limit
A count grade query MUST split its window in half and sum the parts when Loki rejects it for the series limit.
Scenario: Counts query on a store over the series limit
- WHEN the fake Loki answers the
[7d]COUNTS query with HTTP 400 and themaximum number of seriesmessage, and answers each[84h]part - THEN the report sends two queries and its count for each job and repo equals the sum of the two parts.
Requirement: No split on another 400
The report MUST NOT split a query when Loki answers HTTP 400 with a message that does not name the series limit.
Scenario: A query with a syntax error
- WHEN the fake Loki answers HTTP 400 with
parse error - THEN the report sends one query and returns the Loki error with its status.
Existing Tool Considered
No alternatives check has run. Grafana Loki's LogQL keep label filter covers the need: it drops extracted labels before the range aggregation, and the project already uses the sibling drop operator in k8s/devops/dashboards/roadmap-service-telemetry.json. The operator lacks control of the result series count, so the report also splits a count window when Loki rejects it for the series limit. The change adds one helper and one clause to each query in src/devops_cli/roadmap/job_grade_report.py; it builds no library.
Key questions
- Which change lowers the series count of the 7-day grade queries?: Keep only the labels that each query aggregates or filters on, with LogQL
keep. Add a bounded window split for the count queries as a fallback. Do not raise the cluster limit. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:349, k8s/devops/dashboards/roadmap-service-telemetry.json:1317]- Chosen: Keep only the used labels. It removes the unused labels from the series identity at the source, and it adds one clause to each query.
- Rejected: Raise
max_query_seriesin the Loki configuration. It changes a shared cluster limit, costs memory, and hides the next cardinality regression. - Rejected: Split every window into fixed 48h parts. It sends 45 requests for a 90-day trend before any error, and it cannot merge the average queries.
- Rejected: Remove
versionfrom the COUNTS group-by. It changes the report output and needs a second query for the version set.
- Does the deployed Loki support the
keepoperator?: Yes. The dashboard already usesdrop, and the LogQL reference documentskeepin the same label-filter section. The deployed Loki serves the dashboard query, so it has both operators. [sources: k8s/devops/dashboards/roadmap-service-telemetry.json:1317] - Does the
keepclause change the counts that the report shows?: No. Each query aggregates or filters only on the labels that it keeps. A dropped label never changes a count, a class or a first-pass value. [sources: src/devops_cli/roadmap/job_grade_report.py:349] - How does the report detect the series-limit error?: Match HTTP 400 and the substring
maximum number of seriesin the Loki message. Split only on that error. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:349, tests/support/fakes/loki.py]- Chosen: Match the status and the message. It splits only the series-limit error and lets every other 400 reach the user.
- Rejected: Split on every HTTP 400. It hides a syntax or selector error and multiplies requests.
- Rejected: Split every count query. It sends needless requests when the query is under the limit.
- How does the report split a window that exceeds the series limit?: Halve only the window that Loki rejected, and retry each half. Sum the count results. Stop at a 1h floor. (best practice) [sources: src/devops_cli/roadmap/job_grade_report.py:349]
- Chosen: Halve the rejected window, then recurse. It sends the fewest requests, and 48h is known to pass, so one or two levels usually suffice.
- Rejected: Split every window into fixed 48h parts. It sends 45 requests for a 90-day trend before any error.
- Rejected: Do not split. A result over 500 series still fails after the label fix.
- Can the split be tested offline?: Yes.
tests/support/fakes/loki.pyanswers LogQL metric queries, so a test makes it reject the full window and answer each part. [sources: tests/support/fakes/loki.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-11-25: in-use.
The repository already uses this tool.
Tool: grafana/loki (https://github.com/grafana/loki), AGPL-3.0, last activity 2026-11-25, maintained.
Reason: Searches found no separate library; the Loki the project already queries offers the LogQL keep filter, which drops unused labels before the range aggregation, but it cannot bound result series, so the report still needs its own window split.
Covers:
- keep drops extracted labels before count_over_time, shrinking the series identity
- The sibling drop operator already serves the project's dashboard queries
- sum by over the kept labels returns the same counts
Lacks:
- No per-query cap on result series count
- No client-side halving and summing of a rejected window
- No merge of average queries across split parts
Activity
dan-petty commentedon Nov 25, 2026
Both fix the 'eval grades' command, but #5481 fixes a missing-URL fallback while this candidate fixes a Loki 500-series query rejection on the 7d window.devops-cli-service commentedon Nov 25, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Nov 25, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (8)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 25, 2026
Released in v0.217.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.217.0
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 06:46 UTC