feat(monitoring): label pod logs with env (prod/dev) - #41
Merged
Conversation
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>
There was a problem hiding this comment.
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 allj26-*pod log targets. - Override to
env="prod"when the Kubernetes namespace isj26-prod.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| rule { | ||
| source_labels = ["__meta_kubernetes_namespace"] | ||
| regex = "j26-prod" |
Member
Author
There was a problem hiding this comment.
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>
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.
What
Adds an
envlabel to all pod logs collected by Alloy:env="prod"for logs from thej26-prodnamespaceenv="dev"for all otherj26-*namespacesWhy
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
alloy fmtagainst the running image (v1.12.0).🤖 Generated with Claude Code