fixups after rebase

This commit is contained in:
Owen Williams 2024-02-08 14:45:08 -05:00
parent e44335a7df
commit c0ccab59ff
10 changed files with 14 additions and 33 deletions

View file

@ -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("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) Default("").StringsVar(&cfg.featureList)
promlogflag.AddFlags(a, &cfg.promlogConfig) promlogflag.AddFlags(a, &cfg.promlogConfig)

View file

@ -446,28 +446,22 @@ func (s ScrapeProtocol) Validate() error {
var ( var (
PrometheusProto ScrapeProtocol = "PrometheusProto" PrometheusProto ScrapeProtocol = "PrometheusProto"
PrometheusText0_0_4 ScrapeProtocol = "PrometheusText0.0.4" PrometheusText0_0_4 ScrapeProtocol = "PrometheusText0.0.4"
PrometheusText1_0_0 ScrapeProtocol = "PrometheusText1.0.0"
OpenMetricsText0_0_1 ScrapeProtocol = "OpenMetricsText0.0.1" OpenMetricsText0_0_1 ScrapeProtocol = "OpenMetricsText0.0.1"
OpenMetricsText1_0_0 ScrapeProtocol = "OpenMetricsText1.0.0" OpenMetricsText1_0_0 ScrapeProtocol = "OpenMetricsText1.0.0"
OpenMetricsText2_0_0 ScrapeProtocol = "OpenMetricsText2.0.0"
UTF8NamesHeader string = model.EscapingKey+"="+model.AllowUTF8 UTF8NamesHeader string = model.EscapingKey+"="+model.AllowUTF8
ScrapeProtocolsHeaders = map[ScrapeProtocol]string{ ScrapeProtocolsHeaders = map[ScrapeProtocol]string{
PrometheusProto: "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited", PrometheusProto: "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited",
PrometheusText0_0_4: "text/plain;version=0.0.4", 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", OpenMetricsText0_0_1: "application/openmetrics-text;version=0.0.1",
OpenMetricsText1_0_0: "application/openmetrics-text;version=1.0.0", 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 // DefaultScrapeProtocols is the set of scrape protocols that will be proposed
// to scrape target, ordered by priority. // to scrape target, ordered by priority.
DefaultScrapeProtocols = []ScrapeProtocol{ DefaultScrapeProtocols = []ScrapeProtocol{
OpenMetricsText2_0_0,
OpenMetricsText1_0_0, OpenMetricsText1_0_0,
OpenMetricsText0_0_1, OpenMetricsText0_0_1,
PrometheusText1_0_0,
PrometheusText0_0_4, PrometheusText0_0_4,
} }
@ -477,7 +471,6 @@ var (
// "native-histograms" and "created-timestamp-zero-ingestion". // "native-histograms" and "created-timestamp-zero-ingestion".
DefaultProtoFirstScrapeProtocols = []ScrapeProtocol{ DefaultProtoFirstScrapeProtocols = []ScrapeProtocol{
PrometheusProto, PrometheusProto,
OpenMetricsText2_0_0,
OpenMetricsText1_0_0, OpenMetricsText1_0_0,
OpenMetricsText0_0_1, OpenMetricsText0_0_1,
PrometheusText0_0_4, PrometheusText0_0_4,

2
go.mod
View file

@ -90,7 +90,7 @@ require (
k8s.io/apimachinery v0.28.6 k8s.io/apimachinery v0.28.6
k8s.io/client-go v0.28.6 k8s.io/client-go v0.28.6
k8s.io/klog v1.0.0 k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.110.1 k8s.io/klog/v2 v2.120.1
) )
require ( require (

View file

@ -486,7 +486,7 @@ func (p *OpenMetricsParser) parseMetricSuffix(t token) (Entry, error) {
var ts float64 var ts float64
// A float is enough to hold what we need for millisecond resolution. // A float is enough to hold what we need for millisecond resolution.
if ts, err = parseFloat(yoloString(p.l.buf()[1:])); err != nil { 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) { if math.IsNaN(ts) || math.IsInf(ts, 0) {
return EntryInvalid, fmt.Errorf("invalid timestamp %f", ts) return EntryInvalid, fmt.Errorf("invalid timestamp %f", ts)

View file

@ -301,9 +301,10 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5`
} }
func TestUTF8OpenMetricsParse(t *testing.T) { func TestUTF8OpenMetricsParse(t *testing.T) {
oldValidationScheme := model.NameValidationScheme
model.NameValidationScheme = model.UTF8Validation model.NameValidationScheme = model.UTF8Validation
defer func(){ defer func() {
model.NameValidationScheme = model.LegacyValidation model.NameValidationScheme = oldValidationScheme
}() }()
input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations.

View file

@ -462,7 +462,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) {
} }
var err error var err error
if p.val, err = parseFloat(yoloString(p.l.buf())); err != nil { 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. // Ensure canonical NaN value.
if math.IsNaN(p.val) { if math.IsNaN(p.val) {
@ -475,7 +475,7 @@ func (p *PromParser) parseMetricSuffix(t token) (Entry, error) {
case tTimestamp: case tTimestamp:
p.hasTS = true p.hasTS = true
if p.ts, err = strconv.ParseInt(yoloString(p.l.buf()), 10, 64); err != nil { 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 { if t2 := p.nextToken(); t2 != tLinebreak {
return EntryInvalid, p.parseError("expected next entry after timestamp", t2) return EntryInvalid, p.parseError("expected next entry after timestamp", t2)

View file

@ -219,9 +219,10 @@ testmetric{label="\"bar\""} 1`
} }
func TestUTF8PromParse(t *testing.T) { func TestUTF8PromParse(t *testing.T) {
oldValidationScheme := model.NameValidationScheme
model.NameValidationScheme = model.UTF8Validation model.NameValidationScheme = model.UTF8Validation
defer func() { defer func() {
model.NameValidationScheme = model.LegacyValidation model.NameValidationScheme = oldValidationScheme
}() }()
input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. 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 { for i := 0; i < b.N; i += promtestdataSampleCount {
decSamples := make(model.Vector, 0, 50) decSamples := make(model.Vector, 0, 50)
sdec := expfmt.SampleDecoder{ 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{ Opts: &expfmt.DecodeOptions{
Timestamp: model.TimeFromUnixNano(0), Timestamp: model.TimeFromUnixNano(0),
}, },

View file

@ -81,14 +81,8 @@ type Options struct {
// Option to enable the ingestion of the created timestamp as a synthetic zero sample. // 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 // See: https://github.com/prometheus/proposals/blob/main/proposals/2023-06-13_created-timestamp.md
EnableCreatedTimestampZeroIngestion bool EnableCreatedTimestampZeroIngestion bool
<<<<<<< HEAD
// if UTF8 is not allowed, use this method // if UTF8 is not allowed, use this method
NameEscapingScheme string 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. // Optional HTTP client options to use when scraping.
HTTPClientOptions []config_util.HTTPClientOption HTTPClientOptions []config_util.HTTPClientOption

View file

@ -684,13 +684,7 @@ func acceptHeader(sps []config.ScrapeProtocol, allowUTF8Names bool) string {
weight := len(config.ScrapeProtocolsHeaders) + 1 weight := len(config.ScrapeProtocolsHeaders) + 1
for _, sp := range sps { for _, sp := range sps {
val := config.ScrapeProtocolsHeaders[sp] val := config.ScrapeProtocolsHeaders[sp]
<<<<<<< HEAD
if allowUTF8Names { 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 += ";" + config.UTF8NamesHeader
} }
val += fmt.Sprintf(";q=0.%d", weight) val += fmt.Sprintf(";q=0.%d", weight)

View file

@ -2332,12 +2332,10 @@ func TestTargetScraperScrapeOK(t *testing.T) {
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accept := r.Header.Get("Accept") accept := r.Header.Get("Accept")
if protobufParsing { if protobufParsing {
accept := r.Header.Get("Accept") require.True(t, strings.HasPrefix(accept, "application/vnd.google.protobuf;"),
if !strings.HasPrefix(accept, "application/vnd.google.protobuf;") { "Expected Accept header to prefer application/vnd.google.protobuf.")
t.Errorf("Expected Accept header to prefer application/vnd.google.protobuf, got %q", accept)
}
} }
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) t.Errorf("Expected Accept header not to allow utf8, got %q", accept)
} }