From c0ccab59ffd1bed8c4f471ed84a24a4295aff18d Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Thu, 8 Feb 2024 14:45:08 -0500 Subject: [PATCH] fixups after rebase --- cmd/prometheus/main.go | 2 +- config/config.go | 7 ------- go.mod | 2 +- model/textparse/openmetricsparse.go | 2 +- model/textparse/openmetricsparse_test.go | 5 +++-- model/textparse/promparse.go | 4 ++-- model/textparse/promparse_test.go | 5 +++-- scrape/manager.go | 6 ------ scrape/scrape.go | 6 ------ scrape/scrape_test.go | 8 +++----- 10 files changed, 14 insertions(+), 33 deletions(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index fe8ee333f..27125f15a 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -452,7 +452,7 @@ func main() { 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(scrape.DefaultNameEscapingScheme.String()).StringVar(&cfg.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."). + a.Flag("enable-feature", "Comma separated feature names to enable. Valid options: agent, auto-gomemlimit, 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) promlogflag.AddFlags(a, &cfg.promlogConfig) diff --git a/config/config.go b/config/config.go index 19ea8c716..b3188f863 100644 --- a/config/config.go +++ b/config/config.go @@ -446,28 +446,22 @@ func (s ScrapeProtocol) Validate() error { var ( PrometheusProto ScrapeProtocol = "PrometheusProto" PrometheusText0_0_4 ScrapeProtocol = "PrometheusText0.0.4" - PrometheusText1_0_0 ScrapeProtocol = "PrometheusText1.0.0" OpenMetricsText0_0_1 ScrapeProtocol = "OpenMetricsText0.0.1" OpenMetricsText1_0_0 ScrapeProtocol = "OpenMetricsText1.0.0" - OpenMetricsText2_0_0 ScrapeProtocol = "OpenMetricsText2.0.0" UTF8NamesHeader string = model.EscapingKey+"="+model.AllowUTF8 ScrapeProtocolsHeaders = map[ScrapeProtocol]string{ PrometheusProto: "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited", PrometheusText0_0_4: "text/plain;version=0.0.4", - PrometheusText1_0_0: "text/plain;version=1_0_0", OpenMetricsText0_0_1: "application/openmetrics-text;version=0.0.1", OpenMetricsText1_0_0: "application/openmetrics-text;version=1.0.0", - OpenMetricsText2_0_0: "application/openmetrics-text;version=2.0.0", } // DefaultScrapeProtocols is the set of scrape protocols that will be proposed // to scrape target, ordered by priority. DefaultScrapeProtocols = []ScrapeProtocol{ - OpenMetricsText2_0_0, OpenMetricsText1_0_0, OpenMetricsText0_0_1, - PrometheusText1_0_0, PrometheusText0_0_4, } @@ -477,7 +471,6 @@ var ( // "native-histograms" and "created-timestamp-zero-ingestion". DefaultProtoFirstScrapeProtocols = []ScrapeProtocol{ PrometheusProto, - OpenMetricsText2_0_0, OpenMetricsText1_0_0, OpenMetricsText0_0_1, PrometheusText0_0_4, diff --git a/go.mod b/go.mod index 887ce4f8a..517cfec83 100644 --- a/go.mod +++ b/go.mod @@ -90,7 +90,7 @@ require ( k8s.io/apimachinery v0.28.6 k8s.io/client-go v0.28.6 k8s.io/klog v1.0.0 - k8s.io/klog/v2 v2.110.1 + k8s.io/klog/v2 v2.120.1 ) require ( diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index 800e9467d..c32424284 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -486,7 +486,7 @@ func (p *OpenMetricsParser) parseMetricSuffix(t token) (Entry, error) { var ts float64 // A float is enough to hold what we need for millisecond resolution. if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil { - return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) + return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i]) } if math.IsNaN(ts) || math.IsInf(ts, 0) { return EntryInvalid, fmt.Errorf("invalid timestamp %f", ts) diff --git a/model/textparse/openmetricsparse_test.go b/model/textparse/openmetricsparse_test.go index 63a1583b1..33622bf09 100644 --- a/model/textparse/openmetricsparse_test.go +++ b/model/textparse/openmetricsparse_test.go @@ -301,9 +301,10 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5` } func TestUTF8OpenMetricsParse(t *testing.T) { + oldValidationScheme := model.NameValidationScheme model.NameValidationScheme = model.UTF8Validation - defer func(){ - model.NameValidationScheme = model.LegacyValidation + defer func() { + model.NameValidationScheme = oldValidationScheme }() input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. diff --git a/model/textparse/promparse.go b/model/textparse/promparse.go index 350d52166..58129720f 100644 --- a/model/textparse/promparse.go +++ b/model/textparse/promparse.go @@ -462,7 +462,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) { } var err error if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil { - return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) + return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i]) } // Ensure canonical NaN value. if math.IsNaN(p.val) { @@ -475,7 +475,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) { case tTimestamp: p.hasTS = true if p.ts, err = strconv.ParseInt(yoloString(p.l.buf()), 10, 64); err != nil { - return EntryInvalid, fmt.Errorf("%v while parsing: %q", err, p.l.b[p.start:p.l.i]) + return EntryInvalid, fmt.Errorf("%w while parsing: %q", err, p.l.b[p.start:p.l.i]) } if t2 := p.nextToken(); t2 != tLinebreak { return EntryInvalid, p.parseError("expected next entry after timestamp", t2) diff --git a/model/textparse/promparse_test.go b/model/textparse/promparse_test.go index e43812e10..bb7d9c538 100644 --- a/model/textparse/promparse_test.go +++ b/model/textparse/promparse_test.go @@ -219,9 +219,10 @@ testmetric{label="\"bar\""} 1` } func TestUTF8PromParse(t *testing.T) { + oldValidationScheme := model.NameValidationScheme model.NameValidationScheme = model.UTF8Validation defer func() { - model.NameValidationScheme = model.LegacyValidation + model.NameValidationScheme = oldValidationScheme }() input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. @@ -597,7 +598,7 @@ func BenchmarkParse(b *testing.B) { for i := 0; i < b.N; i += promtestdataSampleCount { decSamples := make(model.Vector, 0, 50) sdec := expfmt.SampleDecoder{ - Dec: expfmt.NewDecoder(bytes.NewReader(buf), expfmt.FmtText_1_0_0), + Dec: expfmt.NewDecoder(bytes.NewReader(buf), expfmt.FmtText), Opts: &expfmt.DecodeOptions{ Timestamp: model.TimeFromUnixNano(0), }, diff --git a/scrape/manager.go b/scrape/manager.go index b27d482b6..c1363cc33 100644 --- a/scrape/manager.go +++ b/scrape/manager.go @@ -81,14 +81,8 @@ 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 diff --git a/scrape/scrape.go b/scrape/scrape.go index 55d5ab5a0..1d81b3722 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -684,13 +684,7 @@ 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) diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index d1cadbcd6..fa244418b 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -2332,12 +2332,10 @@ func TestTargetScraperScrapeOK(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { accept := r.Header.Get("Accept") if protobufParsing { - accept := r.Header.Get("Accept") - if !strings.HasPrefix(accept, "application/vnd.google.protobuf;") { - t.Errorf("Expected Accept header to prefer application/vnd.google.protobuf, got %q", accept) - } + require.True(t, strings.HasPrefix(accept, "application/vnd.google.protobuf;"), + "Expected Accept header to prefer application/vnd.google.protobuf.") } - if strings.Contains(accept, "validchars=utf8") { + if strings.Contains(accept, "escaping=allow-utf-8") { t.Errorf("Expected Accept header not to allow utf8, got %q", accept) }