fix: repair observability dashboard data (tokens 0, errors 0, KPI decimals) - #85
Merged
Merged
Conversation
The summary endpoint switches to increase() queries when a range is selected so the KPI cards show windowed counts. increase() extrapolates fractional values (e.g. 64.7826), which the observability dashboard rendered verbatim — the Events/Triggers cards showed long decimals instead of counts. Round each summary value to the nearest integer before returning; the metrics are event counts, so nothing is lost.
The chart ships a PodMonitor for agent pods, but under the default-deny ingress policy no NetworkPolicy allowed scrapes to reach them: every agent metrics endpoint silently refused connections, so agent_tokens_used_total never landed in Prometheus and the dashboard token counters stayed at 0. Add an agent-metrics ingress policy selecting agent pods via managed-by: agent-operator (same selector as the PodMonitor, so pods predating the component label are covered) and opening the named metrics port — the same open-scraping posture the hub-backend metrics rule already uses.
Failed events were only logged to the pod's console (logError) and nacked; nothing reached the hub's task_logs. The observability errors feed reads task_logs with level=error, so it stayed empty even while events were failing. Post an error-level task log alongside the nack so failures surface in the hub errors view.
The Errors KPI card read hub_routing_errors_total, a counter that only increments on router failures and was effectively always zero — so the card stayed at 0 even while events failed and the errors page (which lists error-level task logs) had entries. With a range set, report the count of error-level task logs in the window instead; the counter remains the source for the legacy range-less path and when no log store is configured.
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.
The observability dashboard showed three symptoms; this PR fixes the distinct root causes behind them.
Symptoms → root causes
1. Tokens always 0
agent_tokens_used_totalnever existed in Prometheus: the chart shipsdefault-deny-ingressand a PodMonitor for agent pods, but no ingress policy ever allowed scrapes to reach agent pods. All six agent scrape targets were down (up == 0) while the metrics servers themselves served data fine on localhost. Broken since the netpol posture shipped (2026-08-03).Fix: new chart policy
agent-metrics— ingress on the namedmetricsport for pods selected bymanaged-by: agent-operator(same selector as the PodMonitor, per the stable-selector guidance indocs/network-policies.md), matching the open-scraping posture of the hub-backend metrics rule. Verified in-cluster: after applying the policy, all agent targets flipped toup == 1and/api/v1/tokensreturns real data again (57M+ input tokens).2. Errors always 0
Two compounding issues:
logError) plus a nack. The errors feed readstask_logswithlevel=error, which had 228 info rows and 0 error rows. Fix: the runner now posts an error-level task log alongside every nack.hub_routing_errors_total— a counter that only increments on router failures, effectively always zero — so it would have stayed 0 anyway. Fix: with a range set, the card now counts error-level task logs in the window (the same entries the errors page lists); the counter remains the source for the legacy range-less path and when no log store is configured.3. Events/Triggers cards showing many decimal places
With a range selected (the dashboard always sends one, default
24h),getMetricsSummaryswitches tosum(increase(...)), andincrease()extrapolates fractional values (e.g.64.7826). The KPI cards rendered those verbatim.Fix: round each summary value (
math.Round) before returning — these are event counts. New regression test covers fractional inputs.Verification
go test ./...inservices/hub— all packages pass (incl. newTestObservability_SummaryWithRangeRoundsFractionalCounts)helm templaterenders the new policy correctlynpm test— 83/83 passagent-metricsmanually → all agent scrape targets up, token usage flowing via the hub APINote for deploy: the dev cluster already has an
agent-metricspolicy applied manually (with Helm-adoption annotations), so the nexthelm upgradeadopts it without conflict. Incident logged in AInsel/ainsel-deployment#15.