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
9 changes: 7 additions & 2 deletions k8s/monitoring/prometheus-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ serverFiles:
# through its pod to the node, so the alert moves with the volume. The result keeps the
# claim's `node` label, so a node silence covers it. HostFilesystemSpaceLow
# (homelab-storage) watches the same filesystem at the same 10% without naming a claim.
# Joining kube_pod_info on the left of group_left (persistentvolumeclaim) ensures that
# when a moving pod has series on multiple nodes in kube_pod_info, the rule still
# evaluates without a many-to-many match error (#2148).
- alert: LogOrMetricVolumeDiskLow
expr: |
min by (instance) (
Expand All @@ -354,9 +357,11 @@ serverFiles:
* on (instance) group_right ()
label_replace(
max by (node, namespace, persistentvolumeclaim) (
kube_pod_spec_volumes_persistentvolumeclaims_info{namespace=~"logging|monitoring", persistentvolumeclaim=~"storage-loki-0|prometheus-server"}
* on (namespace, pod) group_left (node)
max by (namespace, pod, node) (kube_pod_info)
* on (namespace, pod) group_left (persistentvolumeclaim)
max by (namespace, pod, persistentvolumeclaim) (
kube_pod_spec_volumes_persistentvolumeclaims_info{namespace=~"logging|monitoring", persistentvolumeclaim=~"storage-loki-0|prometheus-server"}
)
),
"instance", "$1", "node", "(.+)"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-27
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Design

## Decisions

- **Join `kube_pod_info` on the left with `group_left (persistentvolumeclaim)`.**
*Choice:* In `LogOrMetricVolumeDiskLow`, join `max by (namespace, pod, node) (kube_pod_info)` on the left with `max by (namespace, pod, persistentvolumeclaim) (kube_pod_spec_volumes_persistentvolumeclaims_info{...})` on the right using `* on (namespace, pod) group_left (persistentvolumeclaim)`.
*Evidence:* PromQL `group_left` requires at most one series per matching label on the right-hand side. While a pod moves, `kube_pod_info` can have series on multiple nodes. Placing `kube_pod_info` on the left allows many series on the left while the right-hand side has exactly one claim per pod.
- **Aggregate the claim info before joining.**
*Choice:* Wrap `kube_pod_spec_volumes_persistentvolumeclaims_info` with `max by (namespace, pod, persistentvolumeclaim)`.
*Evidence:* Strips extraneous labels (`uid`, `volume`, `ephemeral`) and guarantees at most one series per pod claim on the right side.
- **Retain `min by (instance) (...) * on (instance) group_right () (...) < 0.10`.**
*Choice:* Keep the outer filesystem join and ratio check unchanged.
*Evidence:* The left side is aggregated by `instance`, guaranteeing at most one series per instance. `group_right ()` permits multiple claim series on the right side while preserving the free ratio value.

## Rejected Alternatives

- **`and` joins on `(namespace, pod, node)`.** `kube_pod_spec_volumes_persistentvolumeclaims_info` does not have a `node` label, and `kube_pod_info` does not have `persistentvolumeclaim`. PromQL `and` returns only the labels of the left-hand vector and cannot join cross-vector labels without a binary operator with `group_left` or `group_right`.
- **`promtool test rules`.** Promtool is not installed on developer workstations or standard GitHub Actions runners, and repository decision record `2026-10-24-2194-dashboard-local-savings` rejected introducing it. Unit tests in `tests/test_k8s_monitoring_alerting.py` validate rule structure and PromQL selectors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Proposal

## Why

Issue #2148: `LogOrMetricVolumeDiskLow` in `k8s/monitoring/prometheus-values.yaml` joins `kube_pod_info` with `group_left (node)`. While a pod moves between nodes, `kube_pod_info` has a series for the pod on two nodes. Prometheus refuses the rule with "many-to-many matching not allowed", so the alert does not evaluate. On 2026-10-24 the rule `LocalPathNodeDiskHigh` (#1634) encountered the same live failure while the alloy-metrics pod moved. #1634 resolved `LocalPathNodeDiskHigh` by avoiding multiple series on the right side of a `group_left` join.

## What Changes

- Reorder the inner join in `LogOrMetricVolumeDiskLow` in `k8s/monitoring/prometheus-values.yaml`: `kube_pod_info` is placed on the left side of `group_left (persistentvolumeclaim)`. The right side is `kube_pod_spec_volumes_persistentvolumeclaims_info`, aggregated by `(namespace, pod, persistentvolumeclaim)`.
- When a pod moves between nodes, `kube_pod_info` has multiple series on the left side. The right side has at most one series for the pod's claim. Prometheus evaluates this many-to-one join without error.
- Add an alert rule test to `tests/test_k8s_monitoring_alerting.py` verifying that `LogOrMetricVolumeDiskLow` uses `group_left (persistentvolumeclaim)` rather than `group_left (node)`.
- This change fits one pull request.

## Capabilities

### New Capabilities

- `log-and-metric-retention`: alert rule evaluating storage space for log and metric local-path volumes while pods move between nodes.

### Modified Capabilities

None.

## Impact

- `k8s/monitoring/prometheus-values.yaml`
- `tests/test_k8s_monitoring_alerting.py`

## Feasibility

- Confirmed with `devops_cli.prometheus.promql.validate_promql` that the rewritten expression is structurally valid PromQL.
- Confirmed that `kube_pod_info` carries `node`, `namespace`, and `pod`, while `kube_pod_spec_volumes_persistentvolumeclaims_info` carries `namespace`, `pod`, and `persistentvolumeclaim`.
- Joining `kube_pod_info` on the left with `group_left (persistentvolumeclaim)` preserves `node` on each series from `kube_pod_info` and attaches `persistentvolumeclaim` from the right side.
- Because a pod has at most one matching persistentvolumeclaim in the target namespaces, the right side has at most one series per `(namespace, pod)`.
- Multiple series in `kube_pod_info` across nodes satisfy PromQL `group_left` semantics without many-to-many matching errors.

## Existing Tool Considered

PromQL `group_left (persistentvolumeclaim)` with `kube_pod_info` on the many side is standard Prometheus query structure. No external parser or tool is required.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Purpose

Alert rule evaluating storage space for log and metric local-path volumes while pods move between nodes.

## ADDED Requirements

### Requirement: The disk alert evaluates while a pod moves between nodes
The Prometheus alert rules SHALL include `LogOrMetricVolumeDiskLow`, severity `warning`, which alerts when a local-path volume for Loki or Prometheus has under 10% free space. The rule SHALL place `kube_pod_info` on the left of `group_left (persistentvolumeclaim)` so that multiple node series during pod transitions evaluate without many-to-many matching errors.

#### Scenario: The rule selects series for log and metric storage
- **WHEN** a test reads `LogOrMetricVolumeDiskLow` in `k8s/monitoring/prometheus-values.yaml`
- **THEN** its expression selects `node_filesystem_avail_bytes` and `node_filesystem_size_bytes` on `mountpoint`, `kube_pod_info`, and `kube_pod_spec_volumes_persistentvolumeclaims_info` on `persistentvolumeclaim=~"storage-loki-0|prometheus-server"`
- **AND** it uses `group_left (persistentvolumeclaim)`, does not use `group_left (node)`, and waits `30m`
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tasks

## 1. Alert Rule Update

- [x] Write failing test in `tests/test_k8s_monitoring_alerting.py` verifying `LogOrMetricVolumeDiskLow` join structure
- Verification: `uv run devops ci test tests/test_k8s_monitoring_alerting.py`
- [x] Update `LogOrMetricVolumeDiskLow` in `k8s/monitoring/prometheus-values.yaml` to join `kube_pod_info` with `group_left (persistentvolumeclaim)`
- Verification: `uv run devops ci test tests/test_k8s_monitoring_alerting.py tests/test_k8s.py`

## 2. Verification and Archive

- [x] Run `uv run devops ci fail-to-pass --base origin/main`
- Verification: command reports failed on base and passes on head
- [x] Archive the change
- Verification: `uv run devops openspec archive 2148-log-or-metric-volume-disk-low`
14 changes: 14 additions & 0 deletions openspec/specs/log-and-metric-retention/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# log-and-metric-retention Specification

## Purpose
Alert rule evaluating storage space for log and metric local-path volumes while pods move between nodes.

## Requirements

### Requirement: The disk alert evaluates while a pod moves between nodes
The Prometheus alert rules SHALL include `LogOrMetricVolumeDiskLow`, severity `warning`, which alerts when a local-path volume for Loki or Prometheus has under 10% free space. The rule SHALL place `kube_pod_info` on the left of `group_left (persistentvolumeclaim)` so that multiple node series during pod transitions evaluate without many-to-many matching errors.

#### Scenario: The rule selects series for log and metric storage
- **WHEN** a test reads `LogOrMetricVolumeDiskLow` in `k8s/monitoring/prometheus-values.yaml`
- **THEN** its expression selects `node_filesystem_avail_bytes` and `node_filesystem_size_bytes` on `mountpoint`, `kube_pod_info`, and `kube_pod_spec_volumes_persistentvolumeclaims_info` on `persistentvolumeclaim=~"storage-loki-0|prometheus-server"`
- **AND** it uses `group_left (persistentvolumeclaim)`, does not use `group_left (node)`, and waits `30m`
29 changes: 29 additions & 0 deletions tests/test_k8s_monitoring_alerting.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,35 @@ def test_the_image_gc_rule_warns_on_the_root_disk_of_nodes_with_local_path_pods(
)


def test_the_log_or_metric_volume_disk_rule_evaluates_while_a_pod_moves() -> None:
"""`LogOrMetricVolumeDiskLow` evaluates while a pod moves between nodes (#2148).

Joining `kube_pod_info` on the left of `group_left (persistentvolumeclaim)` ensures that
when a moving pod has series on multiple nodes in `kube_pod_info`, Prometheus allows the
many-to-one match because the right-hand side has at most one series for the pod's claim.
"""
(rule,) = [rule for rule in _rules() if rule["alert"] == "LogOrMetricVolumeDiskLow"]
assert (
[(s.metric, s.labels) for s in selectors(rule["expr"])],
"group_left (node)" in rule["expr"],
"group_left (persistentvolumeclaim)" in rule["expr"],
rule["for"],
) == (
[
("node_filesystem_avail_bytes", frozenset({"mountpoint"})),
("node_filesystem_size_bytes", frozenset({"mountpoint"})),
("kube_pod_info", frozenset()),
(
"kube_pod_spec_volumes_persistentvolumeclaims_info",
frozenset({"persistentvolumeclaim", "namespace"}),
),
],
False,
True,
"30m",
)


def test_the_size_cap_rule_reads_this_server_only() -> None:
"""#550's `PrometheusNearRetentionSizeCap` reads this server's self-scrape, by `job`.

Expand Down
Loading