fix(monitoring): select the vmalert Service the operator creates

The VMServiceScrape selected app.kubernetes.io/instance=vmalert, while the
chart names the VMAlert vmalert-<first metricsStorages name> and the
operator puts that name into the instance label of its Service. The scrape
matched nothing, so the metrics of vmalert itself were never collected.

The instance stays in the selector so the scrape keeps pointing at the one
VMAlert this release renders.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
This commit is contained in:
Yan Bondarenko committed 2026-10-25 16:30:14 +03:00
1 parent 55aad6f914
commit 7bda2bdbc0
2 files changed
+41 -1

No files matched your search

@@ -1,3 +1,4 @@
{{- with first .Values.metricsStorages }}
---
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMServiceScrape
@@ -13,5 +14,6 @@ spec:
selector:
matchLabels:
app.kubernetes.io/component: monitoring
app.kubernetes.io/instance: vmalert
app.kubernetes.io/instance: vmalert-{{ .name }}
app.kubernetes.io/name: vmalert
{{- end }}
@@ -0,0 +1,38 @@
suite: vmalert metrics are scraped
templates:
- templates/vm/vmalert-scrape.yaml
release:
name: monitoring
namespace: tenant-root
set:
_cluster:
root-host: example.org
_namespace:
host: tenant-root.example.org
ingress: tenant-root
metricsStorages:
- name: shortterm
retentionPeriod: "3d"
deduplicationInterval: "15s"
- name: longterm
retentionPeriod: "14d"
deduplicationInterval: "5m"
tests:
- it: selects the Service of the VMAlert the chart renders
asserts:
- equal:
path: spec.selector.matchLabels
value:
app.kubernetes.io/component: monitoring
app.kubernetes.io/instance: vmalert-shortterm
app.kubernetes.io/name: vmalert
- it: renders nothing without metrics storages, like the VMAlert itself
set:
metricsStorages: []
asserts:
- hasDocuments:
count: 0