Files
cozystack/packages/system/monitoring/tests/vmagent_application_identity_test.yaml
T
ZverGuy 7f7496c8d3 fix(monitoring): remove the identity placeholder from scrape-health series
vmagent appends up and scrape_* to each scrape after metric relabeling:
in VictoriaMetrics v1.136.0, the version operator v0.68.4 deploys,
lib/promscrape/scrapework.go addAutoMetrics passes needRelabel=false to
writeRequestCtx.addRows, so addRow attaches the target labels but skips
MetricRelabelConfigs. The "-" placeholder that the scrape class sets on
targets without lineage was removed only in metricRelabelConfigs, so it
stayed on the scrape-health series of every such target, including
nodes and kube-state-metrics.

The removal now runs in the VMAgent's inlineRelabelConfig, which the
operator passes as -remoteWrite.relabelConfig. app/vmagent/remotewrite
TryPush applies it to every series before remote write, scraped and
generated alike, so targets without lineage keep the label set they had
before the class. The exported_* drop stays in the class: only scraped
samples can carry it.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
2026-11-05 00:16:36 +07:00

74 lines
2.9 KiB
YAML

suite: tenant vmagent stamps application identity on exporter series
templates:
- templates/vm/vmagent.yaml
release:
name: monitoring
namespace: tenant-foo
# Same rules as the cluster-wide vmagent in monitoring-agents, pinned there
# by the same assertions; see that suite for why the placeholder and the
# drop exist.
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
asserts:
- equal:
path: spec.scrapeClasses[0].metricRelabelConfigs
value:
- action: labeldrop
regex: (exported_)+apps_cozystack_io_application_(group|kind|name)
# vmagent adds up and scrape_* after metric relabeling (VictoriaMetrics
# lib/promscrape addAutoMetrics calls addRows with needRelabel false), so a
# placeholder removed there would stay on those series of every target
# without lineage. The remote-write relabeling sees every series.
- it: the placeholder is removed from every series, including up and scrape_*
asserts:
- equal:
path: spec.inlineRelabelConfig
value:
- 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: ""