diff --git a/charts/k8s-monitoring/charts/feature-annotation-autodiscovery/templates/_module.alloy.tpl b/charts/k8s-monitoring/charts/feature-annotation-autodiscovery/templates/_module.alloy.tpl index 2857eb8b65..91a8151ac4 100644 --- a/charts/k8s-monitoring/charts/feature-annotation-autodiscovery/templates/_module.alloy.tpl +++ b/charts/k8s-monitoring/charts/feature-annotation-autodiscovery/templates/_module.alloy.tpl @@ -60,6 +60,10 @@ declare "annotation_autodiscovery" { action = "keepequal" target_label = "__tmp_port" } + rule { + action = "labeldrop" + regex = "__tmp_port" + } // If the metrics port number annotation has a value, override the target address to use it, regardless whether it is // one of the declared ports on that Pod. diff --git a/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/nginx-static-metrics.yaml b/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/nginx-static-metrics.yaml new file mode 100644 index 0000000000..5a26f5503f --- /dev/null +++ b/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/nginx-static-metrics.yaml @@ -0,0 +1,57 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: static-metric +data: + metrics.prom: | + # HELP static_metric A static metric to serve for testing + # TYPE static_metric gauge + static_metric{} 1 +--- +apiVersion: source.toolkit.fluxcd.io/v1beta2 +kind: OCIRepository +metadata: + name: nginx +spec: + interval: 1m + url: oci://registry-1.docker.io/bitnamicharts/nginx + ref: + semver: 18.2.5 +--- +apiVersion: helm.toolkit.fluxcd.io/v2 +kind: HelmRelease +metadata: + name: nginx-static-metrics +spec: + interval: 1m + chartRef: + kind: OCIRepository + name: nginx + values: + podAnnotations: + k8s.grafana.com/scrape: "true" + k8s.grafana.com/metrics.portNumber: "8080" + replicaCount: 2 + service: + type: ClusterIP + serverBlock: |- + server { + listen 0.0.0.0:8080; + location /metrics { + default_type "text/plain"; + alias /data/metrics.prom; + } + } + extraVolumes: + - name: static-metric + configMap: + name: static-metric + extraVolumeMounts: + - name: static-metric + mountPath: /data + extraContainerPorts: + - name: a-port + containerPort: 8081 + - name: another-port + containerPort: 8082 diff --git a/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/query-test.yaml b/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/query-test.yaml index 761fcf1c6a..ef6d80da2c 100644 --- a/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/query-test.yaml +++ b/charts/k8s-monitoring/tests/integration/anntoation-autodiscovery/deployments/query-test.yaml @@ -37,10 +37,14 @@ spec: - query: grafana_kubernetes_monitoring_feature_info{cluster="$CLUSTER", feature="annotationAutodiscovery"} type: promql - # Annotation Autodiscovery by Servicell + # Annotation Autodiscovery from a Service Annotation - query: certmanager_clock_time_seconds{cluster="$CLUSTER", job="integrations/cert-manager"} type: promql + # Annotation Autodiscovery from a Pod Annotation + - query: static_metric{cluster="$CLUSTER"} + type: promql + # DPM check - query: avg(count_over_time(scrape_samples_scraped{cluster="$CLUSTER"}[1m])) type: promql