Skip to content

feat(k8s): alert when pod logs stop reaching loki #890

Closed

Description

@dan-petty

Context & Rationale

Split off from #548. After #548, Alloy's alloy-logs DaemonSet is the only component that ships pod logs to Loki (k8s/monitoring/k8s-monitoring-values.yaml:70-72, 142-154). If it stops, logs stop arriving and nothing reports it. It could stop because it lost API egress, is crash-looping, or Loki rejects its pushes. #548's gate test only catches configuration causes.

Nothing can alert on this today:

Scope & Deliverables

  • Deliverable:
  • Acceptance criteria:
    1. The rules sit next to Alerts fire into nothing: no Alertmanager, and k3s false positives #549's rules. A gate test asserts their names, expressions and for durations as one structural tuple. Verified by uv run pytest on that test: under 1 s, with no cluster or network.
    2. A person checks on homelab-k3s, with kubectl --context homelab-k3s port-forward -n monitoring svc/prometheus-server 9090:9090 running in another terminal:
      curl -s http://localhost:9090/api/v1/rules | jq '[.data.groups[].rules[] | select(.name | startswith("PodLogs")) | .health]'
      curl -s -G http://localhost:9090/api/v1/query --data-urlencode 'query=sum by (pod) (rate(loki_write_sent_entries_total[5m]))'
      
      Expected:
      • ["ok","ok"] from the first command;
      • one non-zero series per alloy-logs pod from the second.
    3. Neither alert is firing on a healthy cluster. Verified with curl -s http://localhost:9090/api/v1/alerts | jq '[.data.alerts[] | select(.labels.alertname | startswith("PodLogs"))] | length' printing 0.
  • Key questions:
    • Which signal? Alloy's own loki.write counters per alloy-logs pod (proposed): loki_write_sent_entries_total and loki_write_dropped_entries_total. They name the node whose shipper failed, which an ingest rate on the Loki side can't. Confirm the series names against the scraped metrics before writing the rules.
    • Where are the rules defined? With the same file and mechanism as Alerts fire into nothing: no Alertmanager, and k3s false positives #549's rules (proposed), so there is one rule source.
    • Can a quiet node fire PodLogsNotShipped falsely? It can, if no pod on the node logs for 30 minutes (proposed). Check a week of rate() once the scrape exists. If a node proves quiet, raise for rather than drop the rule.
    • Does a node in planned maintenance page? No. Alerts fire into nothing: no Alertmanager, and k3s false positives #549's maintenance silence covers it (proposed).
  • Constraint:

Strategic Alignment

Split off #548 during the v0.2.25/v0.2.26 readiness review (2026-10-01): #548 drops the runtime half of its original "check or alert" deliverable. An alert needs log-pipeline metrics in Prometheus (#551) and a receiver (#549), and both are in the backlog. Without this item, a stopped shipper goes unnoticed.

Monitoring cleanup amendment (2026-10-03): dependency update

The dependency on #551 for the scrapes is replaced: this item depends on #1131, which scrapes the Alloy collectors through integrations.alloy (bringing in loki_write_sent_entries_total and loki_write_dropped_entries_total, plus a drop alert), and on #1130 for Loki's own series (integrations.loki). The alert rules stay in this item.

#1133 disables the Loki canary. If a Loki write and read probe is still wanted, this item re-enables it with lokiCanary.push: false, a scrape of port 3500, a logging-policy rule admitting monitoring on 3500, and an alert on increase(loki_canary_missing_entries_total[15m]) > 0.

Grouping. This item is a child of #1128 and lands right after #1131.

Update 2026-10-08: refinement

#548 and #549 landed (rules in k8s/monitoring/prometheus-values.yaml:146-148). Rules may use only served series (tests/test_k8s_monitoring_alerting.py:31-75), so #1131 serves loki_write_sent_entries_total. A node silence needs a node label, joined from kube_pod_info if missing. PodLogsDropped duplicates #1131's AlloyLogEntriesDropped; keep only PodLogsNotShipped.

Proposed design

Problem statement

The Alloy 'alloy-logs' DaemonSet is the only component that ships pod logs to Loki, but there's no alerting mechanism to detect when it stops sending logs or drops entries. This means that if the shipper fails due to API egress loss, crash-looping, or Loki rejecting pushes, nothing reports this failure.

Acceptance criteria

  • Criterion 1: Two Prometheus alert rules are defined and placed next to Alerts fire into nothing: no Alertmanager, and k3s false positives #549's rules: 'PodLogsNotShipped' and 'PodLogsDropped'.
    Verification: A gate test asserts their names, expressions and 'for' durations as one structural tuple. Verified by 'uv run pytest' on that test: under 1 s, with no cluster or network.
  • Criterion 2: The rules are properly scraped by Prometheus and can be queried.
    Verification: A person checks on homelab-k3s, with 'kubectl --context homelab-k3s port-forward -n monitoring svc/prometheus-server 9090:9090' running in another terminal. The commands 'curl -s http://localhost:9090/api/v1/rules | jq '[.data.groups[].rules[] | select(.name | startswith("PodLogs")) | .health]' and 'curl -s -G http://localhost:9090/api/v1/query --data-urlencode 'query=sum by (pod) (rate(loki_write_sent_entries_total[5m]))'' return expected results: '["ok","ok"]' from the first command and one non-zero series per 'alloy-logs' pod from the second.
  • Criterion 3: Neither alert fires on a healthy cluster.
    Verification: Verified with 'curl -s http://localhost:9090/api/v1/alerts | jq '[.data.alerts[] | select(.labels.alertname | startswith("PodLogs"))] | length'' printing '0'.

Key questions

  • Which signal should be used for the alerting?: Alloy's own 'loki.write' counters per 'alloy-logs' pod (proposed): 'loki_write_sent_entries_total' and 'loki_write_dropped_entries_total'. They name the node whose shipper failed, which an ingest rate on the Loki side can't. [sources: k8s/monitoring/k8s-monitoring-values.yaml:70-72, k8s/monitoring/k8s-monitoring-values.yaml:142-154]
  • Where are the rules defined?: With the same file and mechanism as Alerts fire into nothing: no Alertmanager, and k3s false positives #549's rules (proposed), so there is one rule source. [sources: k8s/monitoring/prometheus-values.yaml]
  • Can a quiet node fire 'PodLogsNotShipped' falsely?: It can, if no pod on the node logs for 30 minutes (proposed). Check a week of 'rate()' once the scrape exists. If a node proves quiet, raise 'for' rather than drop the rule. [sources: k8s/monitoring/k8s-monitoring-values.yaml:70-72]
  • Does a node in planned maintenance page?: No. Alerts fire into nothing: no Alertmanager, and k3s false positives #549's maintenance silence covers it (proposed). [sources: k8s/monitoring/k8s-monitoring-values.yaml:70-72]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#1131

Activity

  1. added
    type/feature
    scope/k8s
    priority/p2-medium
    on Oct 1, 2026
  2. added this to the v0.2.37 milestone on Oct 17, 2026
  3. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  4. modified the milestones: v0.2.37, v0.2.38 on Oct 17, 2026
  5. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  6. modified the milestone: v0.2.38 on Oct 20, 2026
  7. dan-petty commented on Oct 21, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1780, merged into release/v0.2.38 as 6ac07af.

    Closes #890
    Part of #1128

    4 file(s) changed.

    How it was verified

    Check runs at a3cc0f9:

    • Fail-to-Pass Check: cancel
    • Fail-to-Pass Self-Check: pass
    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Dependency Freshness: skipping
    • Tests & Coverage: pass
    • Analyze (actions): pass
    • Changed-Test Independence: pass
    • Rule Pack Tests: pass
    • Analyze (python): pass
    • Static Analysis: pass
    • Service Image: skipping
    • DevContainer Image: skipping

    No task file.

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/k8stype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions