Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
3 changes: 3 additions & 0 deletions k8s/logging/loki-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 41 additions & 5 deletions k8s/monitoring/dashboards/sre-service.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -1080,7 +1116,7 @@
"h": 1,
"w": 24,
"x": 0,
"y": 51
"y": 59
},
"id": 18,
"panels": [],
Expand All @@ -1097,7 +1133,7 @@
"h": 12,
"w": 24,
"x": 0,
"y": 52
"y": 60
},
"id": 19,
"options": {},
Expand Down Expand Up @@ -1128,7 +1164,7 @@
"h": 12,
"w": 24,
"x": 0,
"y": 64
"y": 72
},
"id": 20,
"options": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-07
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading