From 362f0e7d11d9c728b4d0bb467f87d536701dc63d Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Thu, 8 Feb 2024 14:42:40 -0500 Subject: [PATCH] Make sure to apply escaping config --- cmd/prometheus/main.go | 2 ++ scrape/manager.go | 16 +++++++++++++++- scrape/scrape.go | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index 6be8cef78..e65311ebf 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -450,6 +450,8 @@ func main() { a.Flag("scrape.discovery-reload-interval", "Interval used by scrape manager to throttle target groups updates."). Hidden().Default("5s").SetValue(&cfg.scrape.DiscoveryReloadInterval) + a.Flag("scrape.name-escaping-scheme", "method to escape legacy invalid names when sending to an old version of prometheus. can be one of values (default), underscores, or dots").Default(model.DefaultNameEscapingScheme.String()).StringVar(&cfg.scrape.NameEscapingScheme) + a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: agent, exemplar-storage, expand-external-labels, memory-snapshot-on-shutdown, promql-at-modifier, promql-negative-offset, promql-per-step-stats, promql-experimental-functions, remote-write-receiver (DEPRECATED), extra-scrape-metrics, new-service-discovery-manager, auto-gomaxprocs, no-default-scrape-port, native-histograms, otlp-write-receiver, utf8-names. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details."). Default("").StringsVar(&cfg.featureList) diff --git a/scrape/manager.go b/scrape/manager.go index 660ba03f4..4e4c2fe56 100644 --- a/scrape/manager.go +++ b/scrape/manager.go @@ -81,8 +81,14 @@ type Options struct { // Option to enable the ingestion of the created timestamp as a synthetic zero sample. // See: https://github.com/prometheus/proposals/blob/main/proposals/2023-06-13_created-timestamp.md EnableCreatedTimestampZeroIngestion bool +<<<<<<< HEAD // if UTF8 is not allowed, use this method NameEscapingScheme string +||||||| parent of e18ed1b45 (Make sure to apply escaping config) +======= + // if UTF8 is not allowed, use this method + NameEscapingScheme string +>>>>>>> e18ed1b45 (Make sure to apply escaping config) // Optional HTTP client options to use when scraping. HTTPClientOptions []config_util.HTTPClientOption @@ -160,6 +166,15 @@ func (m *Manager) reloader() { func (m *Manager) reload() { m.mtxScrape.Lock() + defer m.mtxScrape.Unlock() + var err error + model.DefaultNameEscapingScheme, err = model.ToEscapingScheme(m.opts.NameEscapingScheme) + level.Info(m.logger).Log("msg", "ESCAPING SCHEME UPDATED", "scheme", m.opts.NameEscapingScheme) + if err != nil { + level.Error(m.logger).Log("msg", "error setting escaping scheme", "err", err) + return + } + var wg sync.WaitGroup for setName, groups := range m.targetSets { if _, ok := m.scrapePools[setName]; !ok { @@ -186,7 +201,6 @@ func (m *Manager) reload() { }(m.scrapePools[setName], groups) } - m.mtxScrape.Unlock() wg.Wait() } diff --git a/scrape/scrape.go b/scrape/scrape.go index 1d81b3722..55d5ab5a0 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -684,7 +684,13 @@ func acceptHeader(sps []config.ScrapeProtocol, allowUTF8Names bool) string { weight := len(config.ScrapeProtocolsHeaders) + 1 for _, sp := range sps { val := config.ScrapeProtocolsHeaders[sp] +<<<<<<< HEAD if allowUTF8Names { +||||||| parent of e18ed1b45 (Make sure to apply escaping config) + if (sp != config.PrometheusProto || sp == config.OpenMetricsText2_0_0 || sp == config.PrometheusText1_0_0) && allowUTF8Names { +======= + if (sp == config.PrometheusProto || sp == config.OpenMetricsText2_0_0 || sp == config.PrometheusText1_0_0) && allowUTF8Names { +>>>>>>> e18ed1b45 (Make sure to apply escaping config) val += ";" + config.UTF8NamesHeader } val += fmt.Sprintf(";q=0.%d", weight)