Skip to content

feat(monitoring): label pod logs with env (prod/dev) - #41

Merged
hakan-persson merged 1 commit into
mainfrom
monitoring/env-log-label
Jul 4, 2026
Merged

feat(monitoring): label pod logs with env (prod/dev)#41
hakan-persson merged 1 commit into
mainfrom
monitoring/env-log-label

Conversation

@hakan-persson

Copy link
Copy Markdown
Member

What

Adds an env label to all pod logs collected by Alloy:

  • env="prod" for logs from the j26-prod namespace
  • env="dev" for all other j26-* namespaces

Why

During camp we monitor prod but keep collecting dev+prod logs. Today dev vs prod is only distinguishable by remembering which of ~15 namespaces is which. With this label, Loki queries become {env="prod"} / {env="dev"}.

Notes

  • Low-cardinality label (2 values), safe for Loki.
  • Only affects pod logs; node/journal/event streams are unchanged.
  • Validated with alloy fmt against the running image (v1.12.0).
  • Takes effect after ArgoCD syncs and Alloy rolls.

🤖 Generated with Claude Code

Stamp env="prod" on logs from the j26-prod namespace and env="dev" on all
other j26-* namespaces, so dev and prod logs are trivially distinguishable in
Loki ({env="prod"} / {env="dev"}) without memorising which namespace is which.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 4, 2026 15:19
@hakan-persson
hakan-persson merged commit 0716c1a into main Jul 4, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Alloy (Grafana Agent/Alloy) Kubernetes pod log discovery relabeling to attach an env label, enabling Loki queries to distinguish prod vs dev logs via {env="prod"} / {env="dev"}.

Changes:

  • Add a default env="dev" relabel rule for all j26-* pod log targets.
  • Override to env="prod" when the Kubernetes namespace is j26-prod.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
rule {
source_labels = ["__meta_kubernetes_namespace"]
regex = "j26-prod"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good instinct, but this wasn't actually a bug: Prometheus/Alloy relabel regex is fully anchored (^(?:...)$), so j26-prod never matched j26-prod-foo — verified. Made the anchor explicit anyway in #43 (^j26-prod$) to document intent and pre-empt the confusion.

hakan-persson added a commit that referenced this pull request Jul 4, 2026
- alloy: anchor the env=prod relabel regex (^j26-prod$). It was already
  anchored implicitly by Prometheus relabel semantics, so this is a
  no-op in behaviour, but the explicit anchor documents intent and
  removes any doubt about substring matches (e.g. j26-prod-foo).
- notifications ServiceMonitor: set metadata.namespace explicitly for a
  deterministic rendered manifest (consistent with the other SMs in the
  repo), and note why the object is named for the app, not the Service.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants