Repository navigation
Description
Problem
The cluster has two scrapers with two conventions. Alloy, run by k8s-monitoring, scrapes kubelet, cAdvisor, kube-state-metrics, node-exporter, DCGM and the llm gateway. The prometheus-community server (chart 29.35.0) runs its own Kubernetes service discovery beside it, mostly with chart-default jobs. No target is scraped twice today, but the server's half is unfiltered, partly dead, and hard-codes the cluster name five times. The k8s-monitoring chart already has features that cover every target the server's discovery finds. Checked through /api/v1/targets?state=any and /api/v1/status/config on 2026-10-03.
The API-server job holds three quarters of all series, and nothing reads them. scrapeConfigs.kubernetes-api-servers (k8s/monitoring/prometheus-values.yaml:112-116) is on by chart default, with only a cluster relabel.
count({job="kubernetes-api-servers"})= 52,175, whileprometheus_tsdb_head_series= 68,852 (75.8%).- The largest families:
apiserver_request_duration_seconds_bucket11,568,etcd_request_duration_seconds_bucket8,016,apiserver_request_sli_duration_seconds_bucket7,964,apiserver_request_body_size_bytes_bucket4,576. git grep -E 'apiserver_|etcd_|rest_client_|workqueue_' -- k8s/finds nothing: no dashboard, rule or provisioned dashboard (1860, 12239) uses them. The only consumer isTargetDown(up == 0).
Four jobs match nothing. These are chart defaults left on while prometheus-pushgateway.enabled is false:
kubernetes-services(blackbox probes; 85 dropped targets, 0 active);prometheus-pushgateway(85 dropped, 0 active);kubernetes-pods-slow(111 dropped, 0 active);kubernetes-service-endpoints-slow(138 dropped, 0 active).
The remaining targets are found through prometheus.io/* annotations.
kubernetes-podsfinds 2 cloudflared pods, traefik, the otel collector,loki-0andprometheus-alertmanager-0.kubernetes-service-endpointsfinds one target,kube-system/kube-dns:9153. That answers feat(k8s): coredns metrics and a coredns dashboard #822's open question: CoreDNS is already scraped. Turning onclusterMetrics.kubeDNSwithout removing this job would scrape it twice.- Loki is scraped with no allow list (3,303
loki_*series), through thepodAnnotationsink8s/logging/loki-values.yaml:48-52. - DCGM is scraped through a hand-relabelled ServiceMonitor (
k8s/monitoring/dcgm-exporter-values.yaml:42-58; the relabel copies the pod's node name tonodeandinstance). The chart'sintegrations.dcgm-exporterscrapes it natively (jobintegrations/dcgm-exporter).
The cluster label is hard-coded six times and missing once. cluster.name is set in k8s-monitoring-values.yaml, and five post_relabel_configs blocks in prometheus-values.yaml repeat the cluster name as a literal replacement (the same value as cluster.name). The server's self-scrape (job="prometheus") has no cluster label, and neither does prometheus_tsdb_head_series.
Two constraints the move must keep:
- The collector's scrape stays on the server, and not through Alloy, "so the collector's export failures stay visible when Alloy is what fails" (
k8s/README.md:181,k8s/otel/values.yaml:116-118). - The node-maintenance silence relies on the
kubernetes-podsjob settingnodefrom__meta_kubernetes_pod_node_name(k8s/README.md:275).annotationAutodiscoverysets nonodelabel by default; the DCGM rules (max by (node, gpu)) and dashboard 12239 also neednode.
No rule or dashboard selects job="kubernetes-pods", "kubernetes-api-servers" or "kubernetes-service-endpoints". Rules filter only job="prometheus", and no rule or dashboard filters job="dcgm-exporter". So the job renames need no query rewrite.
No document says which monitoring components stay outside k8s-monitoring and why. The k8s/README.md describes k8s-monitoring-values.yaml only as "Alloy, kube-state-metrics, node-exporter, node journals, and gateway monitors".
Acceptance criteria
-
In
k8s/monitoring/prometheus-values.yaml,scrapeConfigssetsenabled: falseon six jobs:kubernetes-api-servers,kubernetes-service-endpoints,kubernetes-service-endpoints-slow,kubernetes-pods-slow,kubernetes-servicesandprometheus-pushgateway. Their relabel blocks are deleted. -
kubernetes-podsstays enabled. Itspre_relabel_configskeep only namespaceotel, and a comment cites the README's independence reason. -
prometheusandkubernetes-podstake their cluster relabel from one YAML anchor in the same file. The self-scrape carriescluster. -
In
k8s/monitoring/k8s-monitoring-values.yaml,annotationAutodiscoveryis set as follows:enabled: true,collector: alloy-metrics;annotations.scrape,annotations.metricsPortNumberandannotations.metricsPathset toprometheus.io/scrape,prometheus.io/portandprometheus.io/path;excludeNamespaces: [otel]andservices.enabled: false;extraDiscoveryRulesthat copy__meta_kubernetes_pod_node_nametonode.
-
clusterMetrics.kubeDNS.enabled: trueis set. -
integrations.collector: alloy-metricsis set, with two instances:loki:labelSelectors{app.kubernetes.io/name: loki, app.kubernetes.io/component: single-binary}, with the chart's default allow list;dcgm-exporter:labelSelectors{app.kubernetes.io/name: dcgm-exporter},metrics.scrapeInterval: 15s, andextraDiscoveryRulesthat setnodeandinstancefrom__meta_kubernetes_pod_node_name.
-
k8s/logging/loki-values.yamlno longer sets theprometheus.io/*podAnnotations.k8s/monitoring/dcgm-exporter-values.yamlsetsserviceMonitor.enabled: falseand drops its relabelings. -
A test in tests/test_k8s_monitoring_integration.py asserts one structural tuple containing:
- the server's enabled jobs,
("kubernetes-pods", "prometheus"); - the namespace
kubernetes-podskeeps,otel; - the autodiscovery annotation keys,
excludeNamespacesandservices.enabled; - that the
noderule is present in autodiscovery and in the dcgm-exporter integration; clusterMetrics.kubeDNS.enabled;- the Loki and DCGM integration selectors;
- the absence of Loki's scrape annotations and of the DCGM ServiceMonitor.
- the server's enabled jobs,
-
A second test asserts that each annotated component in the repo's values has exactly one scrape owner. Verified by mutations in review, each of which must make it fail:
- Alertmanager's
prometheus.io/scrape(prometheus-values.yaml:51-53): autodiscovery only; - the collector's annotations (otel/values.yaml): the server job only;
- removing
otelfromexcludeNamespaces; - re-adding Loki's annotations.
- Alertmanager's
-
tests/test_stack_dashboards.py(_dcgm_monitored,_collector_annotated) reads the new owners. The DCGM capture fixture's job label changes tointegrations/dcgm-exporterif a test compares it. -
k8s/README.mdgains a component-ownership table, one row per component, giving the owner (a k8s-monitoring feature or a separate release) and the reason. Rows:- Prometheus server and Alertmanager;
- Grafana;
- Loki;
- Pyroscope server;
- the trace backend;
- dcgm-exporter (the integration scrapes it; the chart ships no exporter);
- otel-collector (Alloy's deltatocumulative is experimental-only, see fix(telemetry): devops-cli metrics reach prometheus in one hop, a late sample no longer drops a whole batch, and the collector runs only what its pipelines use #1132);
- prometheus-operator-crds (the llm-gateway ServiceMonitor and feat(k8s): qdrant metrics with an authenticated scrape, and its dashboard row restored #823's Qdrant monitor need it).
README:181 and README:275 describe the new scrape owners and where
nodecomes from. -
Every scrape that moves to the Alloy collectors stays reachable under the monitoring perimeter:
k8s/monitoring/networkpolicy.yamlhas exactly one egress rule per scrape port the collectors now use (for examplekube-system9153 forclusterMetrics.kubeDNS, which the Prometheus server reached before). A test reads the policy and the scrape owners from the repo and fails on a scrape port with no egress rule, or with two. -
No test reaches the network or runs
helm. Each new test's call phase is under 1 s, anduv run devops cistays within budget. Achangelog.d/<n>.mdfragment exists; CHANGELOG.md and docs/ROADMAP.md are untouched. -
Pending a person, after the infra stack is redeployed, in Grafana Explore against Prometheus 15 minutes later:
count by (job) (up)showsprometheus,kubernetes-pods(one target, the collector), the autodiscovery jobs, which take each pod'sapp.kubernetes.io/name(cloudflared, traefik, alertmanager),integrations/kubernetes/kube-dns,integrations/lokiandintegrations/dcgm-exporter, and none of the six disabled jobs;count by (job, node) (up{job!~"integrations/kubernetes/.*"})has anodeon every pod target;count by (node, gpu) (DCGM_FI_DEV_GPU_TEMP)equals the GPU count;count({cluster=""})is empty;- three hours later,
prometheus_tsdb_head_seriesis about 50k lower than before.
Key questions
- Why not let Alloy scrape everything, the collector included? Proposed: the documented design keeps the collector on the server so that an Alloy failure can't hide the collector's export failures (README:181). The narrowed
kubernetes-podsjob is the only server-side discovery left, and the ownership table records why. - Use the chart's
k8s.grafana.com/*annotation keys or the existingprometheus.io/*? Proposed:prometheus.io/*, configured throughannotationAutodiscovery.annotations. Traefik is k3s-managed and already carriesprometheus.io/*(path, port 9100, scrape), and so do cloudflared and Alertmanager. Re-annotating would need a k3s HelmChartConfig and a cloudflared manifest edit for no gain. - Why
services.enabled: false? Proposed: the only annotated Service iskube-dns, andclusterMetrics.kubeDNSscrapes it with the chart's CoreDNS allow list. Leaving service discovery on would scrape CoreDNS twice. - Should API-server health be scraped through
clusterMetrics.apiServer? Proposed: no, not in this item. No dashboard or rule reads it. If a consumer appears, enable it withmetricsTuning.includeMetricslimited to what that consumer reads (for exampleapiserver_request_total,apiserver_request_duration_seconds_sum/_count). kube-state-metrics and kubelet scrapes fail visibly when the API server is down. - Does moving DCGM to the integration keep
prometheusOperatorObjectsand the prometheus-operator-crds release? Proposed: yes. The llm-gateway ServiceMonitor (moved under fix(k8s): deploy-stack applies the llm gateway policy and narrows its egress #795) and feat(k8s): qdrant metrics with an authenticated scrape, and its dashboard row restored #823's authenticated Qdrant monitor still need both. - Can the network perimeters carry the move? Proposed: yes. Every target namespace admits the
monitoringnamespace bynamespaceSelector(cloudflared on 2000, logging on 3100), andalloy-metricsruns inmonitoringlike the server. When the planned follow-up narrows themonitoringpeer on Loki to named pods, it must keepalloy-metrics. - Is the cluster relabel on the server still needed after the move? Proposed: yes, on the two jobs that remain. Prometheus applies
external_labelsonly to remote-write, federation and alerts, not to local series, soserver.global.external_labelsis not a substitute.
Strategic alignment
- P1 bug: 76% of Prometheus's series are an unread API-server scrape, four jobs are dead, and the scrape ownership is undocumented.
- Value: high. About 50k fewer head series, one discovery convention, chart allow lists on Loki, CoreDNS and DCGM, and feat(k8s): coredns metrics and a coredns dashboard #822's question closed. Effort: M (two values files and one test file in k8s/monitoring, one each in logging and dcgm, plus the README table).
- Library-first: chart features (
annotationAutodiscovery,clusterMetrics.kubeDNS,integrations.loki,integrations.dcgm-exporter) replace server-side discovery and a hand-written relabel. - Related: fix(k8s): restore kubernetes cpu metrics and align monitoring dashboards to homelab-k3s #737 (baseline split), feat(k8s): coredns metrics and a coredns dashboard #822 (CoreDNS scrape path; this item delivers its scrape and the CoreDNS egress rule, and feat(k8s): coredns metrics and a coredns dashboard #822 keeps the dashboard), Metrics for the rest of the platform #551 (amended: cloudflared, the collector and Loki are scraped), nvidia-dcgm-exporter-dashboard shows IP addresses rather than node names #935 (DCGM relabel origin), feat(k8s): gpu throttling, power limit, pcie and allocation panels over captured dcgm and kube-state-metrics series #821 (consumes DCGM series), Metrics and logs are kept for two hours #550 (retention sizing), feat(k8s): argo cd keeps the homelab cluster at the current release branch, with automated sync, prune and self-heal that never delete data #755 (the pin removes the "unpinned default" comments in prometheus-values.yaml:101-104), fix(k8s): k8s-monitoring collectors run in the chart's preset shapes, and node-exporter keeps the series the node dashboards read #1129 (cluster label on the Alloy side), feat(k8s): the alloy collectors, grafana and pyroscope are scraped through chart integrations, and a dropped sample or log entry alerts #1131 (adds the Alloy, Grafana and Pyroscope integrations to the block this item creates).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty-bot commentedon Oct 9, 2026
Moved to v0.2.33: v0.2.33 started with fewer than its 12 items and was topped up to 12 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)
fix(k8s): the prometheus server scrapes only itself and the otel coll…
dan-petty-bot commentedon Oct 9, 2026
What changed
#1527, merged into
release/v0.2.33as 5845924.24 file(s) changed.
How it was verified
Check runs at b4f48f2:
Acceptance Criteria of
docs/agent/tasks/task-1130-prometheus-scrapes-itself-and-the-collector.md:k8s/monitoring/prometheus-values.yamlsetsenabled: falseonkubernetes-api-servers,kubernetes-service-endpoints,kubernetes-service-endpoints-slow,kubernetes-pods-slow,kubernetes-servicesandprometheus-pushgateway, with their relabel blocks deleted.kubernetes-nodesandkubernetes-nodes-cadvisorstay off.kubernetes-podsstays enabled, and itspre_relabel_configskeep only namespaceotel. Its comment cites the README's independence reason.prometheusandkubernetes-podstake their cluster relabel from one anchor (&cluster). The self-scrape carriescluster.annotationAutodiscoveryis set as follows:enabled: true,collector: alloy-metrics;prometheus.io/scrape,prometheus.io/portandprometheus.io/pathannotation keys;excludeNamespaces: [otel],services.enabled: falseandbearerToken.enabled: false;extraDiscoveryRules.clusterMetrics.kubeDNS.enabled: true, with the same node rule.integrations.collector: alloy-metrics, with two instances:loki:labelSelectors{app.kubernetes.io/name: loki, app.kubernetes.io/component: single-binary}, the chart's default allow list, andlogs.enabled: false;dcgm-exporter:labelSelectors{app.kubernetes.io/name: dcgm-exporter},metrics.scrapeInterval: 15s, and discovery rules that setnodeandinstancefrom__meta_kubernetes_pod_node_name.k8s/logging/loki-values.yamlsets nopodAnnotations.k8s/monitoring/dcgm-exporter-values.yamlsetsserviceMonitor: {enabled: false}and nothing else under it.test_scrape_ownership_moves_to_k8s_monitoringasserts all of the above as one tuple, including Alertmanager's three annotations. The enabled server jobs are computed over the 10 default jobs in prometheus 29.35.0'svalues.yaml(PROMETHEUS_DEFAULT_JOBS), so a default job that the values leave out counts as on.test_each_annotated_component_has_one_scrape_ownerasserts exactly one owner for each of cloudflared, roadmap-service, Alertmanager, the collector, Loki and DCGM. The owners are the server'skubernetes-podsjob, autodiscovery, each integration instance, and the DCGM chart's own ServiceMonitor.test_a_component_with_no_scrape_owner_or_two_failsruns the four review mutations, and each one fails the check:otelremoved fromexcludeNamespaces;test_every_scrape_port_has_one_egress_rulecounts the egress rules ink8s/monitoring/networkpolicy.yamlfor each scrape port, using one counting helper,_egress_rules_to. Each port has exactly one rule: cloudflared 2000, devops 8000,kube-system9100 (Traefik) and 9153 (CoreDNS), logging 3100, monitoring 9093 and 9400, and otel 8888. The policy needed no change.tests/test_stack_dashboards.pyreads the new owners:_dcgm_monitoredreads the k8s-monitoring dcgm-exporter integration;_collector_annotatedalso requires the server job to keep namespaceotel.The DCGM and Prometheus server capture fixtures name their new scrapes and target labels. No test compares the DCGM job label.
k8s/README.mdhas a Scrape Ownership section. Its table has one row for each of the eight components, with the owner and the reason, and the lines after it name the autodiscovered pods and whatdevops prometheus targetslists. The dashboard table, Log and Metric Retention,LokiRetentionNotRunning, Planned maintenance (wherenodecomes from, and what stops withalloy-metrics-0) and the directory listing describe the new owners.No test reaches the network or runs
helm. Each new test's call phase is at most 0.02 s (uv run pytest tests/test_k8s_monitoring_integration.py --durations=0).changelog.d/1130.mdexists; CHANGELOG.md and docs/ROADMAP.md are untouched.Review render, outside the gate:
helm templateof the cached k8s-monitoring 4.5.2 and prometheus 29.35.0 charts with the new values.bearer_token_file.annotation_autodiscovery_pods,kube_dnsand the DCGM instance. DCGM'sscrape_intervalis"15s", and no Loki log rule renders.prometheus.ymlhas only thekubernetes-podsjob, whose first rule keepsotel, and theprometheusjob. Both end with theclusterreplace rule.Pending a person, after the v0.2.33 release PR merges into main and Argo CD syncs the
prometheus,k8s-monitoring,dcgm-exporterandlokiApplications. They track main, so do not apply early withdevops k8s deploy-stackfrom the release branch: Argo CD would revert it.kubectl get application -n argocd prometheus k8s-monitoring dcgm-exporter loki -o custom-columns=NAME:.metadata.name,SYNC:.status.sync.status,HEALTH:.status.health.status,REV:.status.sync.revisionsshows each oneSyncedandHealthyat the merge commit.kubectl get servicemonitor -Alists onlyllm/llm-gateway.kubectl -n logging get pod loki-0andkubectl -n monitoring get pod prometheus-alertmanager-0show pods restarted since the sync, because their pod template annotations changed.prometheus_config_last_reload_successfulis1.Fifteen minutes later,
count by (job) (up)returns these jobs and no others besides the unchanged Alloy jobs (kubelet, cAdvisor, resources, kube-state-metrics, node_exporter, llm-gateway):prometheus1 andkubernetes-pods1;cloudflared2,traefik1,alertmanager1 androadmap-service1;integrations/kubernetes/kube-dns, equal to the CoreDNS pods inkubectl -n kube-system get pods -l k8s-app=kube-dns;logging/single-binary1;integrations/dcgm-exporter, equal to the GPU nodes inkubectl get nodes -l nvidia.com/gpu.present=true.No
kubernetes-api-servers,kubernetes-service-endpointsordcgm-exporterjob is left.count(alertmanager_build_info)is1, so Alertmanager is scraped once.count by (job) (up{node=""})lists onlyprometheus,llm-gateway,integrations/kubernetes/kube-state-metrics,integrations/node_exporterandlogging/single-binary.count by (node, gpu) (DCGM_FI_DEV_GPU_TEMP)equals the number of GPUs, and the instance variable of dashboard 12239 lists node names.loki_compactor_apply_retention_last_successful_run_timestamp_secondsandcoredns_dns_requests_totaleach return series.count({__name__=~".+", __name__!~"ALERTS.*", cluster=""})is empty.ALERTS{alertname="TargetDown"}holds no alert for the new jobs.Three hours later,
prometheus_tsdb_head_seriesis about 60k lower than before the sync (about 99.6k on 2026-10-09).feat(release): v0.2.33 (#1537)