From 4e9aed39af62e21be4aad89d2a446a0c1bcabe5a Mon Sep 17 00:00:00 2001 From: DingShujie Date: Mon, 15 Nov 2021 17:33:19 +0800 Subject: [PATCH] fix /metrics/cadvisor one container scrape error may lead to missing all container metrics --- metrics/prometheus.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/metrics/prometheus.go b/metrics/prometheus.go index 66846b649d..f9ced76c51 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -1865,16 +1865,24 @@ func (c *PrometheusCollector) collectContainersInfo(ch chan<- prometheus.Metric) if err != nil { c.errors.Set(1) klog.Warningf("Couldn't get containers: %s", err) - return + if containers == nil { + return + } } rawLabels := map[string]struct{}{} for _, container := range containers { + if container == nil { + continue + } for l := range c.containerLabelsFunc(container) { rawLabels[l] = struct{}{} } } for _, cont := range containers { + if cont == nil { + continue + } values := make([]string, 0, len(rawLabels)) labels := make([]string, 0, len(rawLabels)) containerLabels := c.containerLabelsFunc(cont)