Skip to content

Commit 1e16768

Browse files
jtslearclaude
andauthored
feat(alloy): label Coder pod logs with a component (#106)
Tag pod logs as `component="coderd"`, `"provisioner"` or `"workspace"` using the existing global.coder.{coderd,provisionerd,workspaces}Selector values, so logs can be filtered by what produced them. Each stage is skipped when its selector is empty, instead of rendering an invalid Alloy selector. The level/logger parsing and multi-line joining now apply to the coderd and provisioner components rather than any pod named `coder*`, so it follows the same selectors as everything else and no longer picks up unrelated pods that happen to start with "coder". Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent b28f54f commit 1e16768

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Loki logs gain a `component` label (`coderd`, `provisioner`, `workspace`) derived from `global.coder.coderdSelector`, `provisionerdSelector` and `workspacesSelector`. Coder log parsing (`level`, `logger`, multi-line joins) now applies to the pods those selectors match instead of every pod named `coder*`; if your pods don't match the selectors, set them.
56
- BREAKING: replaces the `grafana-agent` subchart with Grafana Alloy (`alloy` chart 1.13.1). Rename any `grafana-agent:` values overrides to `alloy:`.
67
- Pod `job` label changes from `<ns>/grafana-agent/grafana-agent` to `<ns>/alloy/alloy`; update queries and alerts that match the old label.
78
- Alloy listens on port 12345 instead of 80.

‎coder-observability/templates/_collector-config.tpl‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,36 @@ loki.process "pod_logs" {
169169
values = ["tmp_container_runtime"]
170170
}
171171

172+
// tag each line with the Coder component it came from, using the same selectors as the dashboards
173+
// (global.coder.*Selector; Alloy's selector parser wants double quotes, not backticks).
174+
{{- if .Values.global.coder.coderdSelector }}
175+
stage.match {
176+
selector = {{ include "coderd-selector" . | replace "`" "\"" | printf "{%s}" | quote }}
177+
stage.static_labels {
178+
values = { component = "coderd" }
179+
}
180+
}
181+
{{- end }}
182+
{{- if .Values.global.coder.provisionerdSelector }}
183+
stage.match {
184+
selector = {{ include "provisionerd-selector" . | replace "`" "\"" | printf "{%s}" | quote }}
185+
stage.static_labels {
186+
values = { component = "provisioner" }
187+
}
188+
}
189+
{{- end }}
190+
{{- if .Values.global.coder.workspacesSelector }}
191+
stage.match {
192+
selector = {{ include "workspaces-selector" . | replace "`" "\"" | printf "{%s}" | quote }}
193+
stage.static_labels {
194+
values = { component = "workspace" }
195+
}
196+
}
197+
{{- end }}
198+
172199
// parse Coder logs and extract level & logger for efficient filtering
173200
stage.match {
174-
selector = "{pod=~\"coder.*\"}" // TODO: make configurable
201+
selector = "{component=~\"coderd|provisioner\"}"
175202

176203
stage.multiline {
177204
firstline = {{ printf `^(?P<ts>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3})` | quote }}

0 commit comments

Comments
 (0)