From b499f20848f3f26f91451e3ad0dcd795e0c66fc0 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Sat, 7 Nov 2026 01:43:32 +0000 Subject: [PATCH] feat(k8s): add warnings and errors above logs, narrow both by pod Issue #1357: On 2026-10-08 the owner asked for *SRE / Service Performance & Logs* (`k8s/monitoring/dashboards/sre-service.json`, uid `devops-sre-service`) to show two log panels: warnings and higher on top, and every line below it. Today, Row 11 (*Service Logs & Live Stream*) holds a single logs panel (id 12, *Live Service Logs (Loki)*) querying `{namespace=~"$namespace", pod=~"$pod"}`. The Loki datasource returns at most 1,000 lines per query, which in a typical namespace covers only the newest ~15 minutes of logs. Warning and error lines older than 15 minutes are never fetched, and those that are fetched are buried among informational logs. Furthermore, pod streams carry `pod` as structured metadata rather than an indexed label; matching `pod` inside the stream selector blanks the panel whenever a specific pod is selected. Closes #1357 Change: `openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/` --- k8s/README.md | 2 +- k8s/logging/loki-values.yaml | 3 + k8s/monitoring/dashboards/sre-service.json | 46 +++++- .../.openspec.yaml | 2 + .../design.md | 41 ++++++ .../proposal.md | 51 +++++++ .../specs/sre-service-dashboard/spec.md | 48 +++++++ .../tasks.md | 41 ++++++ openspec/specs/sre-service-dashboard/spec.md | 48 +++++++ tests/commands/k8s/test_k8s.py | 8 ++ tests/grafana/test_grafana_dashboards.py | 133 ++++++++++++++++++ 11 files changed, 417 insertions(+), 6 deletions(-) create mode 100644 openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/.openspec.yaml create mode 100644 openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/design.md create mode 100644 openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/proposal.md create mode 100644 openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/specs/sre-service-dashboard/spec.md create mode 100644 openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/tasks.md create mode 100644 openspec/specs/sre-service-dashboard/spec.md diff --git a/k8s/README.md b/k8s/README.md index c1cb3acdde..d0a0ccd603 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -291,7 +291,7 @@ The stack dashboards chart the cluster workloads and infrastructure services: | Dashboard | Exporter / Sources | How Prometheus / Loki gets its series | | :--- | :--- | :--- | -| `sre-service.json`, "SRE Service & Logs" (`devops-sre-service`) | cAdvisor container CPU, memory, network packets/drops, Loki service logs, and Pyroscope flamegraphs | Metrics scraped by Alloy from cAdvisor/Kubelet and Kube State Metrics; logs pushed to Loki via Alloy or OpenTelemetry collector; continuous profiles queried from Pyroscope datasource | +| `sre-service.json`, "SRE / Service Performance & Logs" (`devops-sre-service`) | cAdvisor container CPU, memory, network packets/drops, Loki service logs (Warnings & Errors (Loki), Live Service Logs (Loki)), and Pyroscope flamegraphs | Metrics scraped by Alloy from cAdvisor/Kubelet and Kube State Metrics; logs pushed to Loki via Alloy or OpenTelemetry collector; continuous profiles queried from Pyroscope datasource | | `ingress-tunnel.json`, "SRE / Ingress & Cloudflare Tunnel" (`devops-ingress-tunnel`) | Traefik ingress metrics (port 9100) and Cloudflare Tunnel metrics (port 2000) | Alloy's annotation autodiscovery (`annotationAutodiscovery` in `monitoring/k8s-monitoring-values.yaml`), through the pods' `prometheus.io/*` annotations; network policy allows monitoring to scrape both ports | | `llm-stack.json`, "LLM Gateway & GPUs" (`devops-llm-stack`) | LiteLLM's Prometheus callback on the gateway (`/metrics/`), the NVIDIA DCGM exporter on every GPU node, and Qdrant's `/metrics` on port 6333 | The `llm-gateway` ServiceMonitor (`llm/gateway/servicemonitor.yaml`), the `dcgm-exporter` integration (`integrations` in `monitoring/k8s-monitoring-values.yaml`), and the `qdrant` ServiceMonitor (`metrics.serviceMonitor` in `llm/values-qdrant.yaml`, authenticating with the `qdrant-api-key` Secret), run by Alloy, which remote-writes to the server | | `otel-collector.json`, "OpenTelemetry Collector" (`devops-otel-traces`) | The collector's own telemetry on port 8888 | The server's `kubernetes-pods` job, which keeps only namespace `otel`, through the `prometheus.io/scrape` and `prometheus.io/port` pod annotations in `otel/values.yaml`; not through Alloy, whose annotation autodiscovery skips `otel`, so the collector's export failures stay visible when Alloy is what fails | diff --git a/k8s/logging/loki-values.yaml b/k8s/logging/loki-values.yaml index df7ca1acd8..800ffc6368 100644 --- a/k8s/logging/loki-values.yaml +++ b/k8s/logging/loki-values.yaml @@ -34,6 +34,9 @@ loki: delete_request_store: filesystem limits_config: + # The Warnings & Errors (Loki) panel of sre-service.json depends on detected_level, + # which discover_log_levels enables (#1357). + discover_log_levels: true retention_period: 720h # 30 days # The delete-request store opens the log delete API, which needs no credentials while # auth_enabled is false. Retention does not use it, so it stays closed. diff --git a/k8s/monitoring/dashboards/sre-service.json b/k8s/monitoring/dashboards/sre-service.json index 032888fdf1..bda4e0779c 100644 --- a/k8s/monitoring/dashboards/sre-service.json +++ b/k8s/monitoring/dashboards/sre-service.json @@ -1043,13 +1043,49 @@ "type": "loki", "uid": "loki" }, - "description": "Unified live container log stream from Grafana Loki for selected service and pods.", + "description": "Unified live container log stream of lines Loki detects as warning or higher for the selected namespace and pods, including Kubernetes Warning events.", "gridPos": { - "h": 12, + "h": 8, "w": 24, "x": 0, "y": 39 }, + "id": 21, + "options": { + "dedupStrategy": "none", + "enableLogDetails": true, + "prettifyLogMessage": false, + "showCommonLabels": false, + "showLabels": false, + "showTime": true, + "sortOrder": "Descending", + "wrapLogMessage": true + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "loki" + }, + "expr": "{namespace=~\"$namespace\"} | pod=~\"$pod\" | detected_level=~\"(?i)(warn|warning|error|err|critical|fatal|panic)\"", + "refId": "A" + } + ], + "title": "Warnings & Errors (Loki)", + "type": "logs" + }, + { + "datasource": { + "type": "loki", + "uid": "loki" + }, + "description": "Unified live container log stream from Grafana Loki for selected namespace and pods.", + "gridPos": { + "h": 12, + "w": 24, + "x": 0, + "y": 47 + }, "id": 12, "options": { "dedupStrategy": "none", @@ -1080,7 +1116,7 @@ "h": 1, "w": 24, "x": 0, - "y": 51 + "y": 59 }, "id": 18, "panels": [], @@ -1097,7 +1133,7 @@ "h": 12, "w": 24, "x": 0, - "y": 52 + "y": 60 }, "id": 19, "options": {}, @@ -1128,7 +1164,7 @@ "h": 12, "w": 24, "x": 0, - "y": 64 + "y": 72 }, "id": 20, "options": {}, diff --git a/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/.openspec.yaml b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/.openspec.yaml new file mode 100644 index 0000000000..e582ee4a2c --- /dev/null +++ b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-07 diff --git a/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/design.md b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/design.md new file mode 100644 index 0000000000..b5bc55f8cd --- /dev/null +++ b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/design.md @@ -0,0 +1,41 @@ +# Design + +## Context + +`sre-service.json` provides unified performance and log telemetry for services in Kubernetes namespaces. Loki streams lack an indexed `level` label for pod logs, but Loki's `discover_log_levels` populates `detected_level` as structured metadata. Pod logs also carry `pod` in structured metadata rather than as an indexed label. + +## Goals / Non-Goals + +**Goals:** +- Provide a dedicated top log panel displaying warning and error lines over the full query time range. +- Keep the existing live log panel below it showing all log lines. +- Fix pod filtering so selecting a pod does not blank either log panel. +- Pin `discover_log_levels: true` in `loki-values.yaml` to ensure level detection remains active across chart upgrades. + +**Non-Goals:** +- Do not implement client-side browser log filtering (`showControls`), which only filters the 1,000 lines already retrieved. +- Do not filter on the indexed `level` label, which drops pod logs. +- Do not alter service variable scoping or flamegraph queries (handled by separate issues). + +## Decisions + +- **Decision: Filter on `detected_level` structured metadata with case-insensitive regex.** + *Choice:* `{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"`. + *Rejected alternative:* Filter on indexed `level` label. Pod-log streams do not have an indexed `level` label; filtering on `level` matches only Kubernetes events and drops pod warnings/errors. + *Rejected alternative:* Case-sensitive regex without `(?i)`. Drops Kubernetes `Warning` events. + +- **Decision: Separate panels instead of browser-side controls.** + *Choice:* Two full-width panels: *Warnings & Errors (Loki)* (h=8, y=39) on top, and *Live Service Logs (Loki)* (h=12, y=47) below. + *Rejected alternative:* Rely on Grafana `showControls`. That only filters lines within the 1,000-line datasource limit in the browser, losing older warnings in the requested range. + +- **Decision: Move `pod=~"$pod"` from stream selector to filter stage.** + *Choice:* `{namespace=~"$namespace"} | pod=~"$pod"`. + *Rejected alternative:* Keep `pod=~"$pod"` inside `{...}` stream selector. Pod-log streams carry `pod` as structured metadata; querying `{namespace=~"...", pod=~"..."}` yields 0 results when a specific pod is selected. + +- **Decision: Pin `discover_log_levels: true` in `loki-values.yaml`.** + *Choice:* Explicitly declare `discover_log_levels: true` under `loki.limits_config`. + *Rejected alternative:* Rely on chart default. A future chart or configuration upgrade could change or disable defaults silently. + +## Risks / Trade-offs + +- The new panel adds an additional query on dashboard refresh (every 10s). Because it targets warning/error lines using structured metadata filters, query execution is lightweight. diff --git a/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/proposal.md b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/proposal.md new file mode 100644 index 0000000000..abf68a0445 --- /dev/null +++ b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/proposal.md @@ -0,0 +1,51 @@ +# Proposal + +## Why + +Issue #1357: On 2026-10-08 the owner asked for *SRE / Service Performance & Logs* (`k8s/monitoring/dashboards/sre-service.json`, uid `devops-sre-service`) to show two log panels: warnings and higher on top, and every line below it. + +Today, Row 11 (*Service Logs & Live Stream*) holds a single logs panel (id 12, *Live Service Logs (Loki)*) querying `{namespace=~"$namespace", pod=~"$pod"}`. The Loki datasource returns at most 1,000 lines per query, which in a typical namespace covers only the newest ~15 minutes of logs. Warning and error lines older than 15 minutes are never fetched, and those that are fetched are buried among informational logs. Furthermore, pod streams carry `pod` as structured metadata rather than an indexed label; matching `pod` inside the stream selector blanks the panel whenever a specific pod is selected. + +## What Changes + +- `k8s/monitoring/dashboards/sre-service.json`: + - Add a new logs panel in Row 11 titled *Warnings & Errors (Loki)* (id 21) at `h: 8, w: 24, x: 0, y: 39` with query `{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"` and a description mentioning namespace, pods, and Kubernetes Warning events. + - Move panel 12 (*Live Service Logs (Loki)*) to `y: 47` with `h: 12`, update its query to `{namespace=~"$namespace"} | pod=~"$pod"` (moving `pod` to a LogQL label filter stage to fix the pod selection blanking defect), and remove mention of "service" from its description. + - Shift Row 18 (*Continuous Profiling & Flamegraphs (Pyroscope)*) to `y: 59`, and flamegraphs 19 and 20 to `y: 60` and `y: 72`. +- `k8s/logging/loki-values.yaml`: + - Set `discover_log_levels: true` under `loki.limits_config` with a comment naming the *Warnings & Errors (Loki)* panel that depends on it. +- `k8s/README.md`: + - Update the dashboard row to its real title *SRE / Service Performance & Logs* and list both log panels (*Warnings & Errors (Loki)* and *Live Service Logs (Loki)*). +- Tests: + - Add a test in `tests/commands/k8s/test_k8s.py` verifying `discover_log_levels: true` in `loki-values.yaml` and the comment naming the panel. + - Add a test in `tests/grafana/test_grafana_dashboards.py` asserting panel layout, grid positions, queries, options equality, and mutation detections (pod back in selector, dropping `(?i)`, swapping panel y positions, leaving Row 18 at y=51). +- Manifests and dashboards are observable, so this change carries a spec delta for the `sre-service-dashboard` capability. +- The change fits one pull request. + +## Capabilities + +### New Capabilities + +- `sre-service-dashboard`: Layout and log filtering requirements for the *SRE / Service Performance & Logs* dashboard and Loki level detection configuration. + +### Modified Capabilities + +None. + +## Impact + +- Manifests / Dashboards: `k8s/monitoring/dashboards/sre-service.json`, `k8s/logging/loki-values.yaml`. +- Documentation: `k8s/README.md`. +- Tests: `tests/commands/k8s/test_k8s.py`, `tests/grafana/test_grafana_dashboards.py`. +- No new external ports, network egress, or secret requirements. + +## Feasibility + +- Loki 3.6+ defaults `discover_log_levels: true` under `limits_config`, which normalizes pod log levels (`warn`, `error`) and preserves Kubernetes event levels (`Warning`). +- Live tests on 2026-10-08 confirmed `sum by (detected_level) (count_over_time({namespace="devops"} | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)" [1h]))` returned only Warning, error, and warn lines. +- Moving `pod=~"$pod"` out of the stream selector into a LogQL filter pipeline matches structured metadata correctly when a pod is chosen. +- Loki query syntax accepted by Loki `/loki/api/v1/format_query`. + +## Existing Tool Considered + +Grafana covers the logs panel type on a Loki datasource, LogQL stream selectors and label filters including `detected_level` and `pod` filters, and dashboard layout. It lacks nothing in capability; the work is authoring the dashboard JSON in the repository and pinning Loki's `discover_log_levels`, which are configuration steps in this repository. No internal code is deleted. diff --git a/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/specs/sre-service-dashboard/spec.md b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/specs/sre-service-dashboard/spec.md new file mode 100644 index 0000000000..2018f9aac0 --- /dev/null +++ b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/specs/sre-service-dashboard/spec.md @@ -0,0 +1,48 @@ +# sre-service-dashboard Specification + +## Purpose +The panels of the SRE service dashboard `k8s/monitoring/dashboards/sre-service.json`, "SRE / Service Performance & Logs", and the log and telemetry series that each panel shows. + +## ADDED Requirements + +### Requirement: Two log panels in row 11 +Row 11 SHALL hold two full-width logs panels on the `loki` datasource, with the top panel (id 21) at `h: 8, w: 24, x: 0, y: 39` and the lower panel (id 12) at `h: 12, w: 24, x: 0, y: 47`. + +#### Scenario: Read dashboard JSON +- **WHEN** the test reads `sre-service.json` and inspects the panels in row 11 +- **THEN** panel 21 has `gridPos` `{"h": 8, "w": 24, "x": 0, "y": 39}` and panel 12 has `gridPos` `{"h": 12, "w": 24, "x": 0, "y": 47}`, both with datasource uid `loki` and type `logs` + +### Requirement: Top panel query and description +The top panel SHALL use the query `{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"` and its description SHALL mention namespace, pods, and Kubernetes Warning events. + +#### Scenario: Verify top panel expr +- **WHEN** the test reads the expr field of panel 21's target and its description +- **THEN** the expr equals the lower panel's expr plus the level filter, and the description contains `namespace`, `pods`, and `Kubernetes Warning events` + +### Requirement: Lower panel query and description +The lower panel SHALL use the query `{namespace=~"$namespace"} | pod=~"$pod"` and its description SHALL mention namespace and pods with no mention of a service. + +#### Scenario: Verify lower panel expr +- **WHEN** the test reads the expr field of panel 12's target and its description +- **THEN** the expr is `{namespace=~"$namespace"} | pod=~"$pod"` and the description does not contain the word `service` + +### Requirement: Row 18 and flamegraph positions +Row 18 SHALL be at `y: 59`, flamegraph 19 at `y: 60`, and flamegraph 20 at `y: 72`. + +#### Scenario: Verify moved panels +- **WHEN** the test reads the `gridPos` of panels 18, 19, and 20 +- **THEN** panel 18 has `y: 59`, panel 19 has `y: 60`, and panel 20 has `y: 72` + +### Requirement: Loki discover_log_levels pinned +`k8s/logging/loki-values.yaml` SHALL set `discover_log_levels: true` under `loki.limits_config` with a comment naming the Warnings & Errors (Loki) panel. + +#### Scenario: Verify Loki values +- **WHEN** the test reads `loki-values.yaml` and checks the `limits_config` section +- **THEN** the key `discover_log_levels` has value `true` under `loki.limits_config` and the comment names the panel + +### Requirement: README dashboard entry +`k8s/README.md` SHALL give the dashboard its real title `SRE / Service Performance & Logs` and list both log panels. + +#### Scenario: Verify README +- **WHEN** the test reads `k8s/README.md` at the dashboard entry +- **THEN** the title is `SRE / Service Performance & Logs` and both panel names appear diff --git a/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/tasks.md b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/tasks.md new file mode 100644 index 0000000000..49da9f0ee7 --- /dev/null +++ b/openspec/changes/archive/2026-11-07-1357-add-warnings-and-errors-above-logs/tasks.md @@ -0,0 +1,41 @@ +# Tasks + +## 1. Pin discover_log_levels in Loki Helm values + +Reads: `k8s/logging/loki-values.yaml`. Changes: `k8s/logging/loki-values.yaml`. + +- [x] 1.1 In `k8s/logging/loki-values.yaml`, set `discover_log_levels: true` under `loki.limits_config` with a comment naming the *Warnings & Errors (Loki)* panel that depends on it + - Verification: `git grep -n "discover_log_levels: true" k8s/logging/loki-values.yaml` matches and comments name `Warnings & Errors (Loki)` + +## 2. Update SRE service dashboard layout and log panels + +Reads: `k8s/monitoring/dashboards/sre-service.json`. Changes: `k8s/monitoring/dashboards/sre-service.json`. + +- [x] 2.1 Add panel 21 *Warnings & Errors (Loki)* at `h: 8, w: 24, x: 0, y: 39` above panel 12 with query `{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"` and panel 12's options + - Verification: `uv run devops grafana dashboards lint k8s/monitoring/dashboards/sre-service.json` reports zero errors and zero warnings +- [x] 2.2 Update panel 12 *Live Service Logs (Loki)* to `y: 47, h: 12`, change query to `{namespace=~"$namespace"} | pod=~"$pod"`, and remove "service" from description + - Verification: `uv run devops grafana dashboards lint k8s/monitoring/dashboards/sre-service.json` reports zero errors and zero warnings +- [x] 2.3 Shift Row 18 to `y: 59`, flamegraph 19 to `y: 60`, and flamegraph 20 to `y: 72` + - Verification: `uv run devops grafana dashboards lint k8s/monitoring/dashboards/sre-service.json` reports zero errors and zero warnings + +## 3. Update dashboard documentation in k8s README + +Reads: `k8s/README.md`. Changes: `k8s/README.md`. + +- [x] 3.1 Update `k8s/README.md` to use the real title *SRE / Service Performance & Logs* and list both log panels + - Verification: `uv run devops ci docs` passes + +## 4. Test suite for Loki settings, dashboard structure, and mutation assertions + +Reads: `tests/commands/k8s/test_k8s.py`, `tests/grafana/test_grafana_dashboards.py`. Changes: `tests/commands/k8s/test_k8s.py`, `tests/grafana/test_grafana_dashboards.py`. + +- [x] 4.1 Add test in `tests/commands/k8s/test_k8s.py` verifying `discover_log_levels: true` and comment in `k8s/logging/loki-values.yaml` + - Verification: `uv run devops ci test tests/commands/k8s/test_k8s.py` passes +- [x] 4.2 Add test in `tests/grafana/test_grafana_dashboards.py` asserting panel positions, queries, options, relationship, and mutation detection + - Verification: `uv run devops ci test tests/grafana/test_grafana_dashboards.py` passes + +## Workflow follow-up + +- Pending a person: after merge and Argo CD sync of monitoring, open the dashboard with namespace `devops`, pod "All", over the last hour. Verify the lower panel lists every line and the top panel lists only warnings and errors. +- Pending a person: open the top panel in Explore over a fixed 1h range; verify the volume histogram shows only warn/warning/error levels. +- Pending a person: select a specific pod with warnings; verify both panels show only that pod's lines and are not empty. diff --git a/openspec/specs/sre-service-dashboard/spec.md b/openspec/specs/sre-service-dashboard/spec.md new file mode 100644 index 0000000000..073dbe2106 --- /dev/null +++ b/openspec/specs/sre-service-dashboard/spec.md @@ -0,0 +1,48 @@ +# sre-service-dashboard Specification + +## Purpose +The panels of the SRE service dashboard `k8s/monitoring/dashboards/sre-service.json`, "SRE / Service Performance & Logs", and the log and telemetry series that each panel shows. + +## Requirements + +### Requirement: Two log panels in row 11 +Row 11 SHALL hold two full-width logs panels on the `loki` datasource, with the top panel (id 21) at `h: 8, w: 24, x: 0, y: 39` and the lower panel (id 12) at `h: 12, w: 24, x: 0, y: 47`. + +#### Scenario: Read dashboard JSON +- **WHEN** the test reads `sre-service.json` and inspects the panels in row 11 +- **THEN** panel 21 has `gridPos` `{"h": 8, "w": 24, "x": 0, "y": 39}` and panel 12 has `gridPos` `{"h": 12, "w": 24, "x": 0, "y": 47}`, both with datasource uid `loki` and type `logs` + +### Requirement: Top panel query and description +The top panel SHALL use the query `{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"` and its description SHALL mention namespace, pods, and Kubernetes Warning events. + +#### Scenario: Verify top panel expr +- **WHEN** the test reads the expr field of panel 21's target and its description +- **THEN** the expr equals the lower panel's expr plus the level filter, and the description contains `namespace`, `pods`, and `Kubernetes Warning events` + +### Requirement: Lower panel query and description +The lower panel SHALL use the query `{namespace=~"$namespace"} | pod=~"$pod"` and its description SHALL mention namespace and pods with no mention of a service. + +#### Scenario: Verify lower panel expr +- **WHEN** the test reads the expr field of panel 12's target and its description +- **THEN** the expr is `{namespace=~"$namespace"} | pod=~"$pod"` and the description does not contain the word `service` + +### Requirement: Row 18 and flamegraph positions +Row 18 SHALL be at `y: 59`, flamegraph 19 at `y: 60`, and flamegraph 20 at `y: 72`. + +#### Scenario: Verify moved panels +- **WHEN** the test reads the `gridPos` of panels 18, 19, and 20 +- **THEN** panel 18 has `y: 59`, panel 19 has `y: 60`, and panel 20 has `y: 72` + +### Requirement: Loki discover_log_levels pinned +`k8s/logging/loki-values.yaml` SHALL set `discover_log_levels: true` under `loki.limits_config` with a comment naming the Warnings & Errors (Loki) panel. + +#### Scenario: Verify Loki values +- **WHEN** the test reads `loki-values.yaml` and checks the `limits_config` section +- **THEN** the key `discover_log_levels` has value `true` under `loki.limits_config` and the comment names the panel + +### Requirement: README dashboard entry +`k8s/README.md` SHALL give the dashboard its real title `SRE / Service Performance & Logs` and list both log panels. + +#### Scenario: Verify README +- **WHEN** the test reads `k8s/README.md` at the dashboard entry +- **THEN** the title is `SRE / Service Performance & Logs` and both panel names appear diff --git a/tests/commands/k8s/test_k8s.py b/tests/commands/k8s/test_k8s.py index 2c9abdfac1..e22a176445 100644 --- a/tests/commands/k8s/test_k8s.py +++ b/tests/commands/k8s/test_k8s.py @@ -1544,6 +1544,14 @@ def test_loki_deletes_logs_once_they_are_thirty_days_old() -> None: ) == (True, "filesystem", "720h", "disabled") +def test_loki_discovers_log_levels_for_the_warnings_and_errors_panel() -> None: + """The Warnings & Errors (Loki) panel of sre-service.json depends on discover_log_levels.""" + loki = _repo_yaml("k8s", "logging", "loki-values.yaml")["loki"] + assert loki["limits_config"]["discover_log_levels"] is True + raw = REPO_ROOT.joinpath("k8s", "logging", "loki-values.yaml").read_text(encoding="utf-8") + assert "Warnings & Errors (Loki)" in raw + + def test_both_volumes_hold_thirty_days_and_no_size_cap_cuts_them_short() -> None: """Loki's volume holds 30 days of logs; Prometheus keeps 30 days under a looser size cap.""" loki = _repo_yaml("k8s", "logging", "loki-values.yaml")["singleBinary"]["persistence"] diff --git a/tests/grafana/test_grafana_dashboards.py b/tests/grafana/test_grafana_dashboards.py index 4da157e851..019ad1f9dc 100644 --- a/tests/grafana/test_grafana_dashboards.py +++ b/tests/grafana/test_grafana_dashboards.py @@ -530,6 +530,139 @@ def test_sre_dashboards_contain_heatmap_and_ratio_panels() -> None: ) +def _assert_sre_service_dashboard_structure(sre_dash: dict[str, Any]) -> None: + panels = sre_dash.get("panels", []) + panel_map = {p["id"]: p for p in panels if "id" in p} + row_11 = panel_map[11] + top_logs = panel_map[21] + lower_logs = panel_map[12] + row_18 = panel_map[18] + flamegraph_19 = panel_map[19] + flamegraph_20 = panel_map[20] + + ordered_ids = [p["id"] for p in panels if p.get("id") in (11, 21, 12, 18)] + assert ordered_ids == [11, 21, 12, 18] + + assert ( + (row_11["id"], row_11["type"], row_11["title"], row_11["gridPos"]), + (top_logs["id"], top_logs["type"], top_logs["title"], top_logs["gridPos"]), + (lower_logs["id"], lower_logs["type"], lower_logs["title"], lower_logs["gridPos"]), + (row_18["id"], row_18["type"], row_18["title"], row_18["gridPos"]), + ) == ( + (11, "row", "Service Logs & Live Stream", {"h": 1, "w": 24, "x": 0, "y": 38}), + (21, "logs", "Warnings & Errors (Loki)", {"h": 8, "w": 24, "x": 0, "y": 39}), + (12, "logs", "Live Service Logs (Loki)", {"h": 12, "w": 24, "x": 0, "y": 47}), + ( + 18, + "row", + "Continuous Profiling & Flamegraphs (Pyroscope)", + {"h": 1, "w": 24, "x": 0, "y": 59}, + ), + ) + + top_target = top_logs["targets"][0] + lower_target = lower_logs["targets"][0] + top_expr = top_target["expr"] + lower_expr = lower_target["expr"] + + assert ( + top_target["datasource"]["uid"], + lower_target["datasource"]["uid"], + top_expr, + lower_expr, + ) == ( + "loki", + "loki", + '{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"', + '{namespace=~"$namespace"} | pod=~"$pod"', + ) + + level_filter = '| detected_level=~"(?i)(warn|warning|error|err|critical|fatal|panic)"' + assert top_expr == f"{lower_expr} {level_filter}" + assert "(?i)" in top_expr + assert 'pod=~"$pod"' not in top_expr.split("|")[0] + assert 'pod=~"$pod"' not in lower_expr.split("|")[0] + + assert (flamegraph_19["gridPos"], flamegraph_20["gridPos"]) == ( + {"h": 12, "w": 24, "x": 0, "y": 60}, + {"h": 12, "w": 24, "x": 0, "y": 72}, + ) + + assert top_logs["options"] == lower_logs["options"] + + top_desc = top_logs.get("description", "") + assert "namespace" in top_desc + assert "pods" in top_desc + assert "Kubernetes Warning events" in top_desc + + lower_desc = lower_logs.get("description", "") + assert "namespace" in lower_desc + assert "pods" in lower_desc + assert "service" not in lower_desc.lower() + + +def test_sre_service_dashboard_structure() -> None: + """Verify sre-service.json row 11 log panels, row 18, and flamegraphs structure.""" + sre_dash = json.loads((_REPO_DASHBOARDS / "sre-service.json").read_text(encoding="utf-8")) + _assert_sre_service_dashboard_structure(sre_dash) + + +def test_sre_service_dashboard_structure_mutations() -> None: + """Verify that each required mutation causes _assert_sre_service_dashboard_structure to fail.""" + import copy + + sre_dash = json.loads((_REPO_DASHBOARDS / "sre-service.json").read_text(encoding="utf-8")) + + # Mutation 1: putting pod=~"$pod" back inside the stream selector + m1 = copy.deepcopy(sre_dash) + for p in m1["panels"]: + if p.get("id") == 12: + p["targets"][0]["expr"] = '{namespace=~"$namespace", pod=~"$pod"}' + with pytest.raises(AssertionError, match=r'pod=~"\$pod"'): + _assert_sre_service_dashboard_structure(m1) + + # Mutation 2: dropping (?i) + m2 = copy.deepcopy(sre_dash) + for p in m2["panels"]: + if p.get("id") == 21: + p["targets"][0]["expr"] = ( + '{namespace=~"$namespace"} | pod=~"$pod" | detected_level=~"(warn|warning|error|err|critical|fatal|panic)"' + ) + with pytest.raises(AssertionError, match=r"\(\?i\)"): + _assert_sre_service_dashboard_structure(m2) + + # Mutation 3: swapping the two log panels' y + m3 = copy.deepcopy(sre_dash) + for p in m3["panels"]: + if p.get("id") == 21: + p["gridPos"]["y"] = 47 + elif p.get("id") == 12: + p["gridPos"]["y"] = 39 + with pytest.raises(AssertionError, match=r"'y': 47"): + _assert_sre_service_dashboard_structure(m3) + + # Mutation 4: leaving row 18 at y=51 + m4 = copy.deepcopy(sre_dash) + for p in m4["panels"]: + if p.get("id") == 18: + p["gridPos"]["y"] = 51 + with pytest.raises(AssertionError, match=r"'y': 51"): + _assert_sre_service_dashboard_structure(m4) + + +def test_sre_service_dashboard_readme_entry() -> None: + """k8s/README.md gives the dashboard its real title and lists both log panels.""" + readme = (REPO_ROOT / "k8s" / "README.md").read_text(encoding="utf-8") + entry = next( + line + for line in readme.splitlines() + if "sre-service.json" in line and "devops-sre-service" in line + ) + assert "SRE / Service Performance & Logs" in entry + assert "Warnings & Errors (Loki)" in entry + assert "Live Service Logs (Loki)" in entry + + def test_dashboards_contain_properly_labeled_sum_and_average_lines() -> None: """Verify service, ingress, k8s, and LLM dashboards contain properly labeled sum/avg queries.""" in_scope_panels = [