From 0bdab1690b8b556b535a45030f99332251fee0e0 Mon Sep 17 00:00:00 2001 From: rashmichandrashekar Date: Fri, 23 Feb 2024 18:37:55 -0800 Subject: [PATCH] Fix for yaml unmarshal bug for keepequal/dropequal (#753) Fix for bug - https://github.com/prometheus/prometheus/issues/12534 --- otelcollector/otel-allocator/server/server.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/otelcollector/otel-allocator/server/server.go b/otelcollector/otel-allocator/server/server.go index 9dda8347a..367b7a769 100644 --- a/otelcollector/otel-allocator/server/server.go +++ b/otelcollector/otel-allocator/server/server.go @@ -16,6 +16,7 @@ package server import ( "context" + "encoding/json" "fmt" "net/http" "net/http/pprof" @@ -115,13 +116,39 @@ func (s *Server) UpdateScrapeConfigResponse(configs map[string]*promconfig.Scrap if err != nil { return err } + var jsonConfig []byte jsonConfig, err = yaml2.YAMLToJSON(configBytes) if err != nil { return err } + + var jobToScrapeConfig map[string]interface{} + err = json.Unmarshal(jsonConfig, &jobToScrapeConfig) + if jobToScrapeConfig != nil { + for _, scrapeConfig := range jobToScrapeConfig { + scrapeConfig := scrapeConfig.(map[string]interface{}) + if scrapeConfig["relabel_configs"] != nil { + relabelConfigs := scrapeConfig["relabel_configs"].([]interface{}) + for _, relabelConfig := range relabelConfigs { + relabelConfig := relabelConfig.(map[string]interface{}) + // Dropping regex key from the map since unmarshalling this on the client(metrics_receiver.go) results in error + // because of the bug here - https://github.com/prometheus/prometheus/issues/12534 + if relabelConfig["action"] == "keepequal" || relabelConfig["action"] == "dropequal" { + delete(relabelConfig, "regex") + } + } + } + } + } + + jsonConfigNew, err := json.Marshal(jobToScrapeConfig) + if err != nil { + return err + } + s.mtx.Lock() - s.scrapeConfigResponse = jsonConfig + s.scrapeConfigResponse = jsonConfigNew s.mtx.Unlock() return nil }