From e074d7163b2330494a25ae784595b072cb930c51 Mon Sep 17 00:00:00 2001 From: Johannes Rauh Date: Mon, 17 Jun 2024 10:47:55 +0200 Subject: [PATCH] Fix bug: cpu.usage and memory.usage not syncing --- pkg/metrics/metrics.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 2a187ccf..699e7951 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -15,6 +15,7 @@ import ( kcache "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" "net" + "strings" "sync" "time" ) @@ -200,10 +201,14 @@ func (pms *PromMetricSync) Nodes(ctx context.Context, informer kcache.SharedInde nodeName := string(res.Metric["node"]) if nodeName == "" { - if host, _, err := net.SplitHostPort(string(res.Metric["instance"])); err == nil { - nodeName = host + if strings.Contains(string(res.Metric["instance"]), ":") { + if host, _, err := net.SplitHostPort(string(res.Metric["instance"])); err == nil { + nodeName = host + } else { + continue + } } else { - continue + nodeName = string(res.Metric["instance"]) } } uuid, exists := nodes.Load(nodeName)