From a65ed08885439c1f83234b498a0ecdbd335c06ce Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 6 Feb 2024 14:22:51 -0500 Subject: [PATCH 1/3] update prom/common dep, cleanup --- go.mod | 2 +- go.sum | 2 ++ model/textparse/openmetricsparse.go | 1 - model/textparse/openmetricsparse_test.go | 12 ++++++------ model/textparse/promparse.go | 1 - model/textparse/promparse_test.go | 12 ++++++------ 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 7e586580e..517cfec83 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/prometheus/alertmanager v0.26.0 github.com/prometheus/client_golang v1.18.0 github.com/prometheus/client_model v0.5.0 - github.com/prometheus/common v0.46.0 + github.com/prometheus/common v0.46.1-0.20240206181200-773d5664eb8d github.com/prometheus/common/assets v0.2.0 github.com/prometheus/common/sigv4 v0.1.0 github.com/prometheus/exporter-toolkit v0.11.0 diff --git a/go.sum b/go.sum index fd9c104ca..d3410b6a7 100644 --- a/go.sum +++ b/go.sum @@ -672,6 +672,8 @@ github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9 github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y= github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ= +github.com/prometheus/common v0.46.1-0.20240206181200-773d5664eb8d h1:cX7RXwXdSy339hITL5WeF6EeHIvAK6xUIT23xWYBSkg= +github.com/prometheus/common v0.46.1-0.20240206181200-773d5664eb8d/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= github.com/prometheus/common/assets v0.2.0 h1:0P5OrzoHrYBOSM1OigWL3mY8ZvV2N4zIE/5AahrSrfM= github.com/prometheus/common/assets v0.2.0/go.mod h1:D17UVUE12bHbim7HzwUvtqm6gwBEaDQ0F+hIGbFbccI= github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4= diff --git a/model/textparse/openmetricsparse.go b/model/textparse/openmetricsparse.go index 0b016a7f2..800e9467d 100644 --- a/model/textparse/openmetricsparse.go +++ b/model/textparse/openmetricsparse.go @@ -26,7 +26,6 @@ import ( "github.com/prometheus/common/model" - "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/exemplar" "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/labels" diff --git a/model/textparse/openmetricsparse_test.go b/model/textparse/openmetricsparse_test.go index 3afeb0c2b..63a1583b1 100644 --- a/model/textparse/openmetricsparse_test.go +++ b/model/textparse/openmetricsparse_test.go @@ -301,10 +301,10 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5` } func TestUTF8OpenMetricsParse(t *testing.T) { - // model.NameValidationScheme = model.UTF8Validation - // defer func(){ - // model.NameValidationScheme = model.LegacyValidation - // }() + model.NameValidationScheme = model.UTF8Validation + defer func(){ + model.NameValidationScheme = model.LegacyValidation + }() input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. # TYPE "go.gc_duration_seconds" summary @@ -324,7 +324,7 @@ func TestUTF8OpenMetricsParse(t *testing.T) { m string t *int64 v float64 - typ MetricType + typ model.MetricType help string unit string comment string @@ -335,7 +335,7 @@ func TestUTF8OpenMetricsParse(t *testing.T) { help: "A summary of the GC invocation durations.", }, { m: "go.gc_duration_seconds", - typ: MetricTypeSummary, + typ: model.MetricTypeSummary, }, { m: "go.gc_duration_seconds", unit: "seconds", diff --git a/model/textparse/promparse.go b/model/textparse/promparse.go index 62d354d0f..350d52166 100644 --- a/model/textparse/promparse.go +++ b/model/textparse/promparse.go @@ -28,7 +28,6 @@ import ( "github.com/prometheus/common/model" - "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/exemplar" "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/model/labels" diff --git a/model/textparse/promparse_test.go b/model/textparse/promparse_test.go index e1aecb594..504500daa 100644 --- a/model/textparse/promparse_test.go +++ b/model/textparse/promparse_test.go @@ -219,10 +219,10 @@ testmetric{label="\"bar\""} 1` } func TestUTF8PromParse(t *testing.T) { - // model.NameValidationScheme = model.UTF8Validation - // defer func() { - // model.NameValidationScheme = model.LegacyValidation - // }() + model.NameValidationScheme = model.UTF8Validation + defer func() { + model.NameValidationScheme = model.LegacyValidation + }() input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. # TYPE "go.gc_duration_seconds" summary @@ -242,7 +242,7 @@ func TestUTF8PromParse(t *testing.T) { m string t *int64 v float64 - typ MetricType + typ model.MetricType help string comment string }{ @@ -251,7 +251,7 @@ func TestUTF8PromParse(t *testing.T) { help: "A summary of the GC invocation durations.", }, { m: "go.gc_duration_seconds", - typ: MetricTypeSummary, + typ: model.MetricTypeSummary, }, { m: `{"go.gc_duration_seconds",quantile="0"}`, v: 4.9351e-05, From f6bc568d8bd943b2b6f1a69a6fcb55db267b50e2 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 6 Feb 2024 14:24:37 -0500 Subject: [PATCH 2/3] lint --- model/textparse/openmetricsparse.go | 2 +- model/textparse/openmetricsparse_test.go | 2 +- model/textparse/promparse.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) 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..2ad26a616 100644 --- a/model/textparse/openmetricsparse_test.go +++ b/model/textparse/openmetricsparse_test.go @@ -302,7 +302,7 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5` func TestUTF8OpenMetricsParse(t *testing.T) { model.NameValidationScheme = model.UTF8Validation - defer func(){ + defer func() { model.NameValidationScheme = model.LegacyValidation }() 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) From 3911f6109b03a4b540fc0e5f3b4bcb2bbc27ac16 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Tue, 6 Feb 2024 14:29:12 -0500 Subject: [PATCH 3/3] better mode setting --- model/textparse/openmetricsparse_test.go | 3 ++- model/textparse/promparse_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/model/textparse/openmetricsparse_test.go b/model/textparse/openmetricsparse_test.go index 2ad26a616..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 + model.NameValidationScheme = oldValidationScheme }() input := `# HELP "go.gc_duration_seconds" A summary of the GC invocation durations. diff --git a/model/textparse/promparse_test.go b/model/textparse/promparse_test.go index 504500daa..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.