Infrastructure
Azure Monitor Managed Prometheus: diagnose a missing scrape target before restarting collectors
A production runbook for separating target discovery, relabeling, scrape errors, ingestion and PromQL before restarting Azure Monitor Managed Prometheus collectors on AKS.
An AKS deployment is healthy, application logs are flowing and requests succeed, but one service disappears from Azure Managed Grafana. The alert based on its Prometheus metrics moves to NoData. Restarting ama-metrics, broadening annotation-based scraping or copying another scrape job can bring a graph back while hiding whether the target was never discovered, was filtered, rejected the scrape or reached Azure Monitor under different labels.
The running case is an orders-api exposing /metrics on port 8080. It is selected by a PodMonitor after a release changed pod labels and the metrics port name. The goal is to locate the first broken boundary, canary the smallest correction and decide whether to promote it or restore the previous monitoring contract.
Freeze the monitoring contract
Start with one metric, one target and one time window. A dashboard is not the contract: it can hide a changed label, datasource or query.
incident: INC-PROM-427
cluster: aks-platform-prod-we
namespace: orders
workload: deployment/orders-api
expected_target:
discovery: PodMonitor/orders-api
selector: app.kubernetes.io/name=orders-api
port_name: metrics
path: /metrics
scheme: http
expected_series:
- up{job="orders-api"}
- http_server_requests_seconds_count{service="orders-api"}
last_known_good_utc: 2026-10-18T05:40:00Z
release: orders-api@sha256:<digest>
monitoring_change: <commit-or-none>
stop_owner: platform-on-call Retain the workload manifest, PodMonitor or ServiceMonitor, relevant ConfigMaps, image digest and UTC timestamps. Do not edit the collector until you can compare this contract with the effective state.
Prove that the series is absent
Run a narrow PromQL query in the same Azure Monitor workspace and datasource used by the alert. Keep the labels returned by a healthy target in another ring or namespace.
# Did the target report during the incident window?
count_over_time(up{job="orders-api", namespace="orders"}[15m])
# Which identities are still present?
count by (cluster, namespace, job, instance) (
up{namespace="orders"}
)
# Alert only after a bounded absence, not on one delayed sample.
absent_over_time(up{job="orders-api", namespace="orders"}[10m]) An empty result does not yet prove a collection failure. Confirm the workspace, cluster label, namespace and job name. Query a stable platform metric from the same cluster. If every series from the cluster is absent, investigate onboarding, the data collection rule and workspace path before touching the application scrape configuration.
Identify the responsible collector
Managed Prometheus uses different collectors for different targets. Cluster-level and custom resource targets are handled by the replica path; node-local targets such as kubelet, cAdvisor and node exporter use DaemonSet pods. Diagnose the pod that owns the missing target.
set -euo pipefail
kubectl get pods -n kube-system | grep ama-metrics
kubectl get podmonitor,servicemonitor -A
kubectl get podmonitor orders-api -n orders -o yaml
kubectl get pods -n orders -l app.kubernetes.io/name=orders-api -o custom-columns=NAME:.metadata.name,IP:.status.podIP,LABELS:.metadata.labels
kubectl get deployment orders-api -n orders -o yaml > orders-api-deployment.yml
kubectl get podmonitor orders-api -n orders -o yaml > orders-api-podmonitor.yml Do not treat Running as proof of correct collection. It proves the containers started, not that the intended target survived discovery and relabeling.
Walk the collection path in order
The useful sequence is configuration, discovery, scrape, ingestion and query. Stop at the first boundary that fails.
Configuration
PodMonitor, ServiceMonitor or custom ConfigMap is accepted
Selector, namespace selector, port name, path and scheme match the workload
Discovery
Expected pod or service appears in service discovery
Relabeling keeps the target and produces the expected job and instance labels
Scrape
Collector reaches the pod IP and port
Endpoint returns HTTP 200 with valid Prometheus exposition
TLS and authentication match the monitor contract
Ingestion
Collector authenticates to the intended Azure Monitor workspace
Series and events remain below workspace ingestion limits
Metric and label names satisfy supported limits
Query
Grafana datasource points to the intended workspace
PromQL uses labels that still exist after relabeling
Alert has a bounded no-data policy This order avoids using a successful direct curl as proof of end-to-end collection. It validates the application endpoint only; it says nothing about discovery, relabeling, collector identity, ingestion or the final query.
Inspect effective discovery and target errors
First read configuration and target allocator logs. Then port-forward the Prometheus Agent interface of the responsible ama-metrics pod for a short diagnostic window.
set -euo pipefail
kubectl logs -n kube-system <ama-metrics-operator-targets-pod> -c config-reader --since=30m
kubectl logs -n kube-system <ama-metrics-operator-targets-pod> -c targetallocator --since=30m
kubectl logs -n kube-system <ama-metrics-replica-pod> -c prometheus-collector --since=30m
kubectl port-forward -n kube-system <ama-metrics-replica-pod> 9090:9090 Inspect /config, /service-discovery and /targets on 127.0.0.1:9090. The target state narrows the action:
- absent from
/config: the custom resource or ConfigMap was rejected or never selected; - visible in service discovery but missing from targets: a relabeling rule dropped it;
- present and down: read the last scrape error for DNS, connection, TLS, authentication, path or exposition failure;
- up in the collector but absent from Azure Monitor: inspect export authentication, ingestion limits and label validity;
- present in the workspace under different labels: repair the query or restore the label contract.
Capture only the relevant job and error. The effective configuration can contain endpoints and metadata that do not belong in a public ticket.
Validate the application endpoint from the collection plane
Compare the monitor selector and named port with the deployed pod before adding another scrape mechanism.
kubectl get pod -n orders -l app.kubernetes.io/name=orders-api -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.podIP}{" "}{.spec.containers[*].ports[*].name}{"
"}{end}'
kubectl run metrics-probe -n orders --rm -i --restart=Never --image=curlimages/curl:8.12.1 -- curl --fail --silent --show-error --max-time 5 http://orders-api:8080/metrics | head -n 20 Use an approved diagnostic image and network path. A 404 points to path or routing mismatch; 401 or 403 points to the scrape authentication contract; timeout or refusal points to the service, port, policy or workload listener. A 200 with HTML is not valid Prometheus exposition.
When annotations drive collection, verify that the namespace is included by podannotationnamespaceregex and that prometheus.io/scrape, prometheus.io/path and prometheus.io/port are on the pod template. Do not enable annotation scraping for every namespace to repair one target: that can create an uncontrolled volume and duplicate collection.
Canary the smallest correction
Choose one correction at the first failed boundary. Examples include restoring the pod label selected by the PodMonitor, correcting a named port, reverting one relabeling rule or repairing the metrics handler.
canary:
namespace: orders-canary
workload_replicas: 1
monitor_copy: orders-api-canary
expected:
- target_is_discovered_once
- target_up_equals_1
- expected_metric_arrives_with_bounded_labels
- no_duplicate_job_or_series_appears
- collector_memory_and_ingestion_stay_within_baseline
stop_when:
- unrelated_targets_change
- duplicate_collection_appears
- collector_restarts_or_is_oomkilled
- series_volume_exceeds_the_canary_budget Keep debug mode temporary. It exposes all scraped metrics on port 9091 and can affect collector performance. Enable it only when /targets is healthy but the expected metric still cannot be located, bind it to an incident window, and remove the setting after capturing the result.
Decide promotion or rollback
PROMOTE
First broken boundary is proven
Canary target is discovered and up
Expected series reaches the intended workspace with stable labels
No duplicate scrape or cardinality increase appears
ROLL BACK MONITORING
Failure starts after a PodMonitor, ServiceMonitor, ConfigMap or relabeling change
Previous artifact restores the target in canary
New configuration changes unrelated targets or collector stability
ROLL BACK APPLICATION
Release removed or broke the metrics endpoint or its label/port contract
Previous image restores valid exposition without widening collection
Application rollback risk is accepted by the service owner
DO NOT CLOSE
Dashboard is green only after restarting all collectors
Query was broadened without finding the label change
Annotation scraping was enabled cluster-wide
Target is up but alert behavior and ingestion are unverified Restart only when the runtime must reload an accepted configuration and you have preserved the pre-change evidence. A restart is not a rollback. The rollback is the previous versioned PodMonitor, ServiceMonitor, ConfigMap or application manifest.
Validate the recovered signal
Wait for several scrape intervals. Prove up == 1, the business metric advances under controlled traffic, the alert returns from NoData without being silenced, and no second job scrapes the same target. Compare active series and events per minute with the pre-incident baseline.
Close only when the effective target, labels, workspace and query match the recorded contract; the canary correction is promoted through the normal delivery path; temporary debug access is removed; and the last known-good monitoring artifacts are still immediately restorable.
Conclusion
A missing Prometheus graph is not a collector restart instruction. It is a break somewhere between configuration, discovery, relabeling, scrape, ingestion and query.
The production decision is therefore narrow: repair the first proven boundary, validate one canary target through to PromQL, then promote; otherwise restore the last qualified monitoring or application contract. The result is not merely a green dashboard, but an observable path whose recovery and rollback are both repeatable.