Skip to content

fix(telemetry): grafana aggregate lines sum and average the lines shown, read as dashed reference lines, and reach calls in flight #970

Closed

Description

@dan-petty

Problem Statement

#968 (PR #969, commit decb600 on release/v0.2.25) added Total (Sum) and Average (Mean) targets to thirteen breakdown panels across five dashboards under k8s/monitoring/dashboards/ (GPU Utilisation received Average (Mean) only). Three gaps remain at HEAD:

  1. The aggregates do not aggregate the lines the panel shows. On CPU Usage by Pod and Memory Working Set by Pod (sre-service.json, panel ids 7 and 8) and Ingress & Tunnel Pod CPU Usage and Ingress & Tunnel Memory Working Set (ingress-tunnel.json, ids 21 and 22), each per-pod line is sum by (pod) (or sum by (namespace, pod)) over containers, but Average (Mean) is avg(...) over the raw container series, so it is a mean per container, not per pod. Measured cluster-wide on 2026-10-02: mean per container 0.0054 cores against mean per pod 0.0065 cores, about 17% low; 12 of 62 pods run more than one container. GPU Memory Used and GPU Power (llm-stack.json, ids 14 and 15) display max by (hostname, gpu, modelName) but Total (Sum) is sum(...) over raw series, which double counts the moment the exporter emits a second series per GPU. The same shape holds on every other in-scope panel: the aggregate re-derives the breakdown's selector instead of aggregating the breakdown.
  2. No styling. No in-scope panel has an override for either aggregate line (fieldConfig.overrides is [] on the sre, ingress, nodes and pods panels and absent on the llm-stack.json panels; only CPU Usage by container in k8s-views-pods.json carries an unrelated limit override), so the aggregate lines render as two more palette-classic lines, distinguishable only by legend text. The "properly labeled" half of feat(telemetry): add properly labeled sum and average lines to service and cluster grafana graphs #968 did not land.
  3. Calls in Flight per Deployment (llm-stack.json, id 2) was in feat(telemetry): add properly labeled sum and average lines to service and cluster grafana graphs #968's scope and shipped with the breakdown target (refId A) only.

The existing test test_dashboards_contain_properly_labeled_sum_and_average_lines (tests/test_grafana_dashboards.py:524) only checks that the legend strings are present on eight of the thirteen panels; it does not look at the expressions or the overrides, so none of the three gaps fails a test today.

Proposed Solution

  • Expressions. Every aggregate line is written as sum(<base>) or avg(<base>), where <base> is the exact text of the panel's breakdown query (refId A). Total (Sum) is then the sum of the lines shown and Average (Mean) is their mean. Where the breakdown uses dashboard variables ($namespace/$pod in sre-service.json and k8s-views-pods.json, $service in Service Request Rate, $node/$cluster in k8s-views-nodes.json), the aggregate inherits them, so narrowing the selection narrows the aggregate. llm-stack.json has no templating block and the ingress CPU/memory panels use hard-coded regex selectors, so those aggregates stay cluster-wide, as their breakdowns are. On sre-service.json, refId A is the {{pod}} usage / {{pod}} working set line; the limit and request targets (B, C) are not part of the aggregate. The repository PromQL validator (src/devops_cli/prometheus/promql.py, used by the linter at src/devops_cli/grafana/linter.py:114) accepts the wrapped forms, including sum(sum(...) by (pod)) and avg(sum by (api_base) (... * on (model_id) group_left (api_base) ...)).
  • Styling. Field overrides matched by display name (matcher.id: "byName") on every in-scope panel:
    • Total (Sum): custom.lineStyle {"fill": "dash", "dash": [...]}, custom.lineWidth 2, color {"mode": "fixed", "fixedColor": "<light grey>"}
    • Average (Mean): same dash and width, color {"mode": "fixed", "fixedColor": "<amber>"}
    • No custom.axisPlacement override: both stay on the breakdown's axis. The dashboards already use lineStyle/lineWidth under fieldConfig.defaults.custom (k8s-views-nodes.json:907-910) and a byName fixed-colour override (k8s-views-pods.json, CPU Usage by container, limit), so the override property ids follow the same schema.
    • The exact hex values and dash array are the implementer's choice within "light grey" and "amber"; the test asserts lineStyle.fill == "dash", lineWidth == 2 and color.mode == "fixed", not specific values. The fixed colours only need to read as reference lines against palette-classic.
  • Calls in Flight. Add Total (Sum) (refId B) and Average (Mean) (refId C) to Calls in Flight per Deployment as sum(<A>) / avg(<A>), with the same overrides. GPU Utilisation keeps Average (Mean) only, since a sum of percentages is meaningless; its expression becomes avg(<A>).
  • Test. Replace the legend-only check in test_dashboards_contain_properly_labeled_sum_and_average_lines with an invariant over every in-scope panel (all fourteen are top-level panels, none sits inside a row): the Total (Sum) expression equals "sum(" + <refId A expr> + ")", the Average (Mean) expression equals "avg(" + <refId A expr> + ")", GPU Utilisation has no Total (Sum), and each panel's overrides contain a byName match for each aggregate present with lineStyle.fill == "dash", lineWidth == 2, color.mode == "fixed" and no custom.axisPlacement property. No lint rule in src/devops_cli/grafana/linter.py: other dashboards may legitimately aggregate differently.
  • Vocabulary. Add a Telemetry section to CONTEXT.md (none exists at HEAD; the file has Release planning, Roadmap jobs and Code review) defining Breakdown panel (a time-series panel whose refId A splits one metric by a label) and Aggregate line (a Total (Sum) or Average (Mean) target that sums or averages the breakdown's lines), with _Avoid_: baseline, overlay, summary line, reference line.
  • Rollout. Apply the dashboard ConfigMaps (kubectl apply -k k8s/, which reaches k8s/monitoring/dashboards/kustomization.yaml through k8s/kustomization.yaml:11) after merge, as feat(telemetry): add heatmap and ratio-based graphs to sre dashboards #938 and feat(telemetry): add properly labeled sum and average lines to service and cluster grafana graphs #968 did. The five touched files are in grafana-k8s-global-dashboards, grafana-k8s-node-dashboards and grafana-stack-dashboards; tests/test_k8s_monitoring_dashboards.py::test_each_configmap_fits_kubectls_last_applied_annotation keeps each under 262,144 bytes.

Scope

The same five dashboards and thirteen panels as #968, plus Calls in Flight per Deployment (fourteen panels):

  • sre-service.json: CPU Usage by Pod (id 7), Memory Working Set by Pod (id 8)
  • ingress-tunnel.json: Service Request Rate (id 16), Ingress & Tunnel Pod CPU Usage (id 21), Ingress & Tunnel Memory Working Set (id 22)
  • k8s-views-nodes.json: CPU usage by Pod (id 26), Memory usage by Pod (id 28)
  • k8s-views-pods.json: CPU Usage by container (id 29), Memory Usage by container (id 51)
  • llm-stack.json: Calls in Flight per Deployment (id 2), Requests per Deployment (id 4), GPU Utilisation (id 13, Average only), GPU Memory Used (id 14), GPU Power (id 15)

Key Questions (answered)

  • Aggregate over raw samples or over the displayed lines? Displayed lines.
  • Follow the dashboard variables or stay cluster-wide? Follow the variables. Panels whose breakdown has no variables stay cluster-wide, matching their breakdown.
  • Average on throughput panels too? Yes, uniformly on every in-scope panel.
  • Total on its own axis? No, same axis. Total dominating the scale on busy panels is accepted over a second axis that invites misreading.
  • Lint rule or test? Test on the in-scope panels only.

Acceptance Criteria

  • For each in-scope panel, the Total (Sum) expression is sum(<refId A expression>) and the Average (Mean) expression is avg(<refId A expression>), character for character; GPU Utilisation has Average (Mean) only. Shown by uv run pytest tests/test_grafana_dashboards.py -k properly_labeled_sum_and_average.
  • Calls in Flight per Deployment has both aggregate lines. Shown by the same test.
  • Each in-scope panel has byName overrides for each aggregate line present: custom.lineStyle dashed, custom.lineWidth 2, color.mode fixed, no custom.axisPlacement. Shown by the same test.
  • devops grafana dashboards lint k8s/monitoring/dashboards reports 0 errors and 0 warnings (tests/test_grafana_dashboards.py::test_repository_dashboards_lint_clean); uv run pytest tests/test_stack_dashboards.py tests/test_k8s_monitoring_dashboards.py passes (exporter coverage and ConfigMap size); uv run devops ci passes.
  • CONTEXT.md has a Telemetry section defining Breakdown panel and Aggregate line with an _Avoid_ line. Shown by grep -n "Breakdown panel\|Aggregate line" CONTEXT.md.
  • Pending a person: after merge, kubectl apply -k k8s/ and open each of the five dashboards; every in-scope panel shows the two (or one) dashed aggregate lines on the breakdown's axis, and narrowing $pod on SRE Service Performance moves Total (Sum) with the selection.

Out of Scope

Dependencies

Update 2026-10-08: refinement

Still true for panels 2, 7 and 8 and the legend-only test (tests/test_grafana_dashboards.py:524). New: rolling lines on llm-stack.json panels 4, 13 and 14, and panel 17, none built from refId A. (proposed) Each rolling line is the 30-minute mean of its aggregate, such as avg_over_time(avg(<A>)[30m:]); panel 17 drops Total (Sum).

  • The same test checks every rolling expression and panel 17.

Proposed design

Problem statement

The telemetry dashboards contain aggregate lines (Total Sum and Average Mean) that do not correctly aggregate the displayed breakdown lines. Specifically, on several panels, the sum and average calculations use raw container series instead of the per-pod breakdown shown in the panel, leading to incorrect values. Additionally, these aggregate lines lack proper styling and one panel is missing its aggregate lines entirely.

Acceptance criteria

  • Criterion 1: Each aggregate line expression correctly aggregates the breakdown's lines by using the exact text of the panel's refId A query
    Verification: Run uv run pytest tests/test_grafana_dashboards.py -k properly_labeled_sum_and_average and verify that for each in-scope panel, the Total (Sum) expression equals "sum()" and Average (Mean) equals "avg()"
  • Criterion 2: Aggregate lines are properly styled with dashed line style, specific line width, and fixed color
    Verification: Run the same test and verify that each panel's overrides contain a byName match for each aggregate line present with custom.lineStyle.fill == "dash", lineWidth == 2, color.mode == "fixed", and no custom.axisPlacement property
  • Criterion 3: The Calls in Flight per Deployment panel has both Total (Sum) and Average (Mean) aggregates
    Verification: Run the test and verify that Calls in Flight per Deployment panel shows both aggregate lines
  • Criterion 4: Dashboard linting passes with no errors or warnings for all affected dashboards
    Verification: Run devops grafana dashboards lint k8s/monitoring/dashboards and ensure it reports 0 errors and 0 warnings
  • Criterion 5: CONTEXT.md contains a Telemetry section defining Breakdown panel and Aggregate line terms
    Verification: Run grep -n "Breakdown panel\|Aggregate line" CONTEXT.md and verify both terms are defined with an Avoid line

Key questions

None.

Open questions

  • Should the aggregates be calculated over raw samples or over the displayed lines? (missing verified source)
  • Should the aggregates follow dashboard variables or stay cluster-wide? (missing verified source)
  • Should average be applied to throughput panels too? (missing verified source)
  • Should the total be on its own axis? (missing verified source)
  • Should there be a linter rule or test for aggregate lines? (missing verified source)
  • Aggregate over raw samples or over the displayed lines? Displayed lines.
  • Follow the dashboard variables or stay cluster-wide? Follow the variables. Panels whose breakdown has no variables stay cluster-wide, matching their breakdown.
  • Average on throughput panels too? Yes, uniformly on every in-scope panel.
  • Total on its own axis? No, same axis. Total dominating the scale on busy panels is accepted over a second axis that invites misreading.
  • Lint rule or test? Test on the in-scope panels only.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#974

Activity

  1. added this to the v0.2.26 milestone on Oct 2, 2026
  2. added
    scope/k8s
    scope/telemetry
    priority/p2-medium
    on Oct 2, 2026
  3. removed this from the v0.2.26 milestone on Oct 2, 2026
  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #821. Both edit the GPU row of k8s/monitoring/dashboards/llm-stack.json (row 12, panels 13-17); whichever lands second rebases. Found by the 2026-10-08 backlog review.

  5. modified the milestone: on Oct 21, 2026
  6. added a commit that references this issue on Oct 25, 2026
    2084172
  7. added
    type/bug
    and removed on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/k8sscope/telemetrytype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions