mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
feat(monitoring): stamp application identity on cluster-wide scrapes
Scoping a metrics query to one application needs the application's
identity on the series themselves, and it is only a boundary if the
scraped pod cannot choose it. A default scrape class on the cluster-wide
vmagent copies the pod's lineage labels into
apps_cozystack_io_application_{group,kind,name} at scrape time.
The target always carries all three labels, with a placeholder when the
pod has no lineage, so an exporter's own copy always collides, is
renamed to exported_* under honorLabels false, and is dropped. Without
the placeholder a pod lacking lineage could publish any identity
unchallenged. The placeholder is removed again before storage, so series
of pods without lineage look as they did before.
Scrapes with honorLabels true keep the exporter's value; none of them
scrapes a tenant-controlled exporter.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
4087218a02
commit
f98ee76d2d
2 files changed
+92
No files matched your search
@@ -20,6 +20,31 @@ spec:
|
||||
|
||||
scrapeInterval: 30s
|
||||
selectAllByDefault: true
|
||||
# The target always carries all three identity labels, "-" when the pod
|
||||
# has no lineage ("-" is not a valid Kubernetes label value, so it never
|
||||
# collides with a real one). That makes every exporter-supplied copy
|
||||
# collide and be renamed to exported_* (honorLabels false), where it is
|
||||
# dropped; the placeholder itself is removed before storage.
|
||||
scrapeClasses:
|
||||
- name: application-identity
|
||||
default: true
|
||||
relabelConfigs:
|
||||
{{- range list "group" "kind" "name" }}
|
||||
- targetLabel: apps_cozystack_io_application_{{ . }}
|
||||
replacement: "-"
|
||||
- sourceLabels: [__meta_kubernetes_pod_label_apps_cozystack_io_application_{{ . }}]
|
||||
regex: (.+)
|
||||
targetLabel: apps_cozystack_io_application_{{ . }}
|
||||
{{- end }}
|
||||
metricRelabelConfigs:
|
||||
- action: labeldrop
|
||||
regex: (exported_)+apps_cozystack_io_application_(group|kind|name)
|
||||
{{- range list "group" "kind" "name" }}
|
||||
- sourceLabels: [apps_cozystack_io_application_{{ . }}]
|
||||
regex: "-"
|
||||
targetLabel: apps_cozystack_io_application_{{ . }}
|
||||
replacement: ""
|
||||
{{- end }}
|
||||
additionalScrapeConfigs:
|
||||
name: additional-scrape-configs
|
||||
key: prometheus-additional.yaml
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
suite: cluster-wide vmagent stamps application identity on exporter series
|
||||
templates:
|
||||
- templates/vmagent.yaml
|
||||
release:
|
||||
name: monitoring-agents
|
||||
namespace: cozy-monitoring
|
||||
|
||||
# The tenant-resource-metrics proxy scopes a query to one application by
|
||||
# apps_cozystack_io_application_{group,kind,name}. The labels are only a
|
||||
# boundary if the scraped pod cannot choose them: the target always carries
|
||||
# all three (a placeholder when the pod has no lineage), so with
|
||||
# honorLabels false an exporter's own copy is renamed to exported_* and
|
||||
# dropped. The same rules live in the tenant vmagent of the monitoring
|
||||
# package and are pinned there by an identical suite.
|
||||
tests:
|
||||
- it: every scrape gets the application identity class unless it names another
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.scrapeClasses[0].name
|
||||
value: application-identity
|
||||
- equal:
|
||||
path: spec.scrapeClasses[0].default
|
||||
value: true
|
||||
- lengthEqual:
|
||||
path: spec.scrapeClasses
|
||||
count: 1
|
||||
|
||||
- it: the identity comes from the scraped pod's lineage labels, with a placeholder when the pod has none
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.scrapeClasses[0].relabelConfigs
|
||||
value:
|
||||
- targetLabel: apps_cozystack_io_application_group
|
||||
replacement: "-"
|
||||
- sourceLabels: [__meta_kubernetes_pod_label_apps_cozystack_io_application_group]
|
||||
regex: (.+)
|
||||
targetLabel: apps_cozystack_io_application_group
|
||||
- targetLabel: apps_cozystack_io_application_kind
|
||||
replacement: "-"
|
||||
- sourceLabels: [__meta_kubernetes_pod_label_apps_cozystack_io_application_kind]
|
||||
regex: (.+)
|
||||
targetLabel: apps_cozystack_io_application_kind
|
||||
- targetLabel: apps_cozystack_io_application_name
|
||||
replacement: "-"
|
||||
- sourceLabels: [__meta_kubernetes_pod_label_apps_cozystack_io_application_name]
|
||||
regex: (.+)
|
||||
targetLabel: apps_cozystack_io_application_name
|
||||
|
||||
- it: an exporter-supplied identity is dropped and the placeholder never reaches storage
|
||||
asserts:
|
||||
- equal:
|
||||
path: spec.scrapeClasses[0].metricRelabelConfigs
|
||||
value:
|
||||
- action: labeldrop
|
||||
regex: (exported_)+apps_cozystack_io_application_(group|kind|name)
|
||||
- sourceLabels: [apps_cozystack_io_application_group]
|
||||
regex: "-"
|
||||
targetLabel: apps_cozystack_io_application_group
|
||||
replacement: ""
|
||||
- sourceLabels: [apps_cozystack_io_application_kind]
|
||||
regex: "-"
|
||||
targetLabel: apps_cozystack_io_application_kind
|
||||
replacement: ""
|
||||
- sourceLabels: [apps_cozystack_io_application_name]
|
||||
regex: "-"
|
||||
targetLabel: apps_cozystack_io_application_name
|
||||
replacement: ""
|
||||
Reference in new issue
Block a user