Make sure to apply escaping config

This commit is contained in:
Owen Williams 2024-02-08 14:42:40 -05:00
parent 9a3ffc86d7
commit 362f0e7d11
3 changed files with 23 additions and 1 deletions

View file

@ -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)

View file

@ -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()
}

View file

@ -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)