fix(monitoring): stop Loki high-memory false alerts (cgroup-v1 slab) - #232
Draft
alex-struk wants to merge 1 commit into
Draft
fix(monitoring): stop Loki high-memory false alerts (cgroup-v1 slab)#232alex-struk wants to merge 1 commit into
alex-struk wants to merge 1 commit into
Conversation
The recurring HighPodMemoryUsage critical alert on bcgov-di-plg-loki-0 is not real memory pressure. On the Silver cluster's cgroup v1 nodes, container_memory_working_set_bytes includes reclaimable kernel slab (dentry/inode caches). Loki's constant chunk create/delete churn inflates that slab until it nears the 2Gi limit, while Loki's actual Go heap is only ~100Mi. The kernel reclaims the slab before any OOM, so the pod sits near 90% working-set indefinitely with zero restarts. Prior memory-limit bumps could never fix this (slab just refills the larger limit), and cutting chunk_idle_period to 5m made it worse by increasing file churn. Two changes: - prometheus-rule-crd.yaml: exclude the Loki pod from HighPodMemoryUsage (working-set is a meaningless signal for it under cgroup v1). A real Loki OOM is still caught by the PodInErrorState (OOMKilled) alert. All other pods keep the early-warning alert. - loki-configmap.yaml: raise chunk_idle_period 5m -> 1h, add explicit max_chunk_age 2h, and enlarge chunk_target_size to 2Mi so Loki writes far fewer chunk files, reducing the dentry/inode slab churn at its source. Heap headroom (~100Mi of 2Gi) makes the longer idle period safe. Documented the cgroup-v1 accounting artifact and the exclusion rationale in docs-md/ALERTING.md. Structural fix is migrating nodes to cgroup v2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
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.
Problem
The recurring
HighPodMemoryUsagecritical alert onbcgov-di-plg-loki-0(fd34fb-prod) is a false alarm, and prior attempts (three memory-limit bumps + achunk_idle_periodcut) never resolved it.Live diagnosis on the prod pod (via
oc execinto its cgroup):memory.usage_in_bytesmemory.kmem.usage_in_bytes(kernel slab)rss(Loki's actual Go heap)Root cause: the alert uses
container_memory_working_set_bytes / limit, which on cgroup v1 includes reclaimable kernel slab (dentry/inode caches). Loki's continuous chunk create/delete churn (ingester flush + compaction + retention deletes) inflates that slab until it nears the 2 GiB limit. Loki's real footprint is ~100 MiB; the kernel reclaims the slab before any OOM — which is why the pod sits near 90% forever with zero restarts.Why the prior fixes failed:
chunk_idle_period30m→5m → made it worse (more frequent flushes = more files = more dentry churn).Corroboration: Red Hat solution 7126558 (xfs_inode/dentry slab OOM under cgroup v1); Grafana docs discourage Loki on shared/NFS filesystem stores.
Changes
prometheus-rule-crd.yaml— exclude the Loki pod fromHighPodMemoryUsage(working-set is a meaningless signal for it under cgroup v1). The exclusion is derived from theplg.loki.fullnamehelper. All other pods keep the early-warning alert. A genuine Loki OOM is still caught by the existingPodInErrorState(OOMKilled) rule.loki-configmap.yaml—chunk_idle_period5m→1h, add explicitmax_chunk_age: 2h,chunk_target_size1.5Mi→2Mi. Fewer, larger chunk files → less dentry/inode slab churn at the source. Heap headroom makes the longer idle period safe.docs-md/ALERTING.md— documents the infra-alert template location and the cgroup-v1 exclusion rationale.Validation
helm lintpasses;helm template(releasebcgov-di-plg, nsfd34fb-prod) renders the exclusion aspod!~"bcgov-di-plg-loki-.*"and the ingester block aschunk_idle_period: 1h / max_chunk_age: 2h / chunk_target_size: 2097152.Not included (deliberately)
Rollout note
Applies on next PLG
helm upgrade. The already-firing alert instance can be silenced in Alertmanager in the meantime (it's not a real risk — 0 restarts, ~99 MiB heap).🤖 Generated with Claude Code