Skip to content

Commit 4f8159a

Browse files
authored
Merge branch 'main' into kakkoyun/goroutine_leak
2 parents 71e5c81 + 20355eb commit 4f8159a

10 files changed

Lines changed: 25 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

3+
* [CHANGE] prometheus: Name validation now always uses the UTF-8 scheme instead of the deprecated `model.NameValidationScheme` global. Default behavior is unchanged; code that set `NameValidationScheme = LegacyValidation` no longer gets legacy enforcement at metric, label, and push-grouping construction. #2051
34
* [FEATURE] HTTP handlers created by `promhttp` package now support metrics filtering by providing one or more `name[]` query parameters. The default behavior when none are provided remains the same, returning all metrics. #1925
45
* [FEATURE] promhttp: Add opt-in `HandlerOpts.CoalesceGather` to deduplicate concurrent `Gather` calls so overlapping scrapes share one collection cycle, preventing goroutine pile-up when the scrape rate outpaces collection time. #1969
56
* [BUGFIX] promhttp: `InstrumentHandlerDuration` and `InstrumentHandlerCounter` no longer panic when given an observer/counter that does not implement `ExemplarObserver`/`ExemplarAdder` (e.g. a `SummaryVec`). The exemplar is dropped and the value is recorded via the plain `Observe`/`Add` path, matching the safe-cast already used by `Timer.ObserveDurationWithExemplar`. #2005

prometheus/collectors/go_collector_latest_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestWithGoCollectorDefault(t *testing.T) {
112112
expected := append(withBaseMetrics(memstatMetrics), defaultRuntimeMetrics...)
113113
sort.Strings(expected)
114114
if diff := cmp.Diff(got, expected); diff != "" {
115-
t.Errorf("[IMPORTANT, those are default metrics, can't change in 1.x] missmatch (-want +got):\n%s", diff)
115+
t.Errorf("[IMPORTANT, those are default metrics, can't change in 1.x] mismatch (-want +got):\n%s", diff)
116116
}
117117
}
118118

@@ -132,7 +132,7 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) {
132132
}
133133

134134
if diff := cmp.Diff(got, withBaseMetrics(defaultRuntimeMetrics)); diff != "" {
135-
t.Errorf("missmatch (-want +got):\n%s", diff)
135+
t.Errorf("mismatch (-want +got):\n%s", diff)
136136
}
137137
}
138138

@@ -190,7 +190,7 @@ func TestGoCollectorAllowList(t *testing.T) {
190190
}
191191

192192
if diff := cmp.Diff(got, test.expected); diff != "" {
193-
t.Errorf("missmatch (-want +got):\n%s", diff)
193+
t.Errorf("mismatch (-want +got):\n%s", diff)
194194
}
195195
})
196196
}
@@ -252,7 +252,7 @@ func TestGoCollectorDenyList(t *testing.T) {
252252
}
253253

254254
if diff := cmp.Diff(got, test.expected); diff != "" {
255-
t.Errorf("missmatch (-want +got):\n%s", diff)
255+
t.Errorf("mismatch (-want +got):\n%s", diff)
256256
}
257257
})
258258
}

prometheus/collectors/version/version_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func TestGoVersionCollector(t *testing.T) {
5656
}
5757

5858
if diff := cmp.Diff(lk, defaultLabels); diff != "" {
59-
t.Errorf("missmatch (-want +got):\n%s", diff)
59+
t.Errorf("mismatch (-want +got):\n%s", diff)
6060
}
6161

6262
}
6363

6464
if diff := cmp.Diff(got, []string{"foo_build_info"}); diff != "" {
65-
t.Errorf("missmatch (-want +got):\n%s", diff)
65+
t.Errorf("mismatch (-want +got):\n%s", diff)
6666
}
6767
}
6868

@@ -103,12 +103,12 @@ func TestGoVersionCollectorWithLabels(t *testing.T) {
103103
labels := append(defaultLabels, "z-mylabel")
104104

105105
if diff := cmp.Diff(lk, labels); diff != "" {
106-
t.Errorf("missmatch (-want +got):\n%s", diff)
106+
t.Errorf("mismatch (-want +got):\n%s", diff)
107107
}
108108

109109
}
110110

111111
if diff := cmp.Diff(got, []string{"foo_build_info"}); diff != "" {
112-
t.Errorf("missmatch (-want +got):\n%s", diff)
112+
t.Errorf("mismatch (-want +got):\n%s", diff)
113113
}
114114
}

prometheus/desc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func (v2) NewDesc(fqName, help string, variableLabels ConstrainableLabels, const
111111
for _, opt := range opts {
112112
opt(d)
113113
}
114-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
115-
if !model.NameValidationScheme.IsValidMetricName(fqName) {
114+
if !model.UTF8Validation.IsValidMetricName(fqName) {
116115
d.err = fmt.Errorf("%q is not a valid metric name", fqName)
117116
return d
118117
}

prometheus/go_collector_latest_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"reflect"
2222
"regexp"
2323
"runtime"
24+
"runtime/debug"
2425
"runtime/metrics"
2526
"strings"
2627
"sync"
@@ -270,12 +271,16 @@ func TestMemStatsEquivalence(t *testing.T) {
270271
samplesMap[descs[i].Name] = &samples[i]
271272
}
272273

273-
// Force a GC cycle to try to reach a clean slate.
274-
runtime.GC()
274+
// Reach a stable slate and hold it for a single measurement window.
275+
// FreeOSMemory runs a GC and returns freed memory to the OS, leaving the
276+
// background scavenger nothing to release; disabling GC for the window
277+
// keeps msReal and msFake observing the same runtime state. Without this,
278+
// HeapReleased could drift between the two reads and fail the comparison.
279+
debug.FreeOSMemory()
280+
defer debug.SetGCPercent(debug.SetGCPercent(-1))
275281

276-
// Populate msReal.
282+
// Populate msReal, then msFake back-to-back within the frozen window.
277283
runtime.ReadMemStats(&msReal)
278-
// Populate msFake and hope that no GC happened in between (:
279284
metrics.Read(samples)
280285

281286
memStatsFromRM(&msFake, samplesMap)

prometheus/histogram.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ func (h *histogram) maybeReset(
970970
// We are using the possibly mocked h.now() rather than
971971
// time.Since(h.lastResetTime) to enable testing.
972972
if h.nativeHistogramMinResetDuration == 0 || // No reset configured.
973-
h.resetScheduled || // Do not interefere if a reset is already scheduled.
973+
h.resetScheduled || // Do not interfere if a reset is already scheduled.
974974
h.now().Sub(h.lastResetTime) < h.nativeHistogramMinResetDuration {
975975
return false
976976
}

prometheus/internal/difflib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ type OpCode struct {
7878
// notion, pairing up elements that appear uniquely in each sequence.
7979
// That, and the method here, appear to yield more intuitive difference
8080
// reports than does diff. This method appears to be the least vulnerable
81-
// to synching up on blocks of "junk lines", though (like blank lines in
81+
// to syncing up on blocks of "junk lines", though (like blank lines in
8282
// ordinary text files, or maybe "<P>" lines in HTML files). That may be
8383
// because this is the only method of the 3 that has a *concept* of
8484
// "junk" <wink>.

prometheus/labels.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,5 @@ func validateLabelValues(vals []string, expectedNumberOfValues int) error {
184184
}
185185

186186
func checkLabelName(l string) bool {
187-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
188-
return model.NameValidationScheme.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix)
187+
return model.UTF8Validation.IsValidLabelName(l) && !strings.HasPrefix(l, reservedLabelPrefix)
189188
}

prometheus/process_collector_darwin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ func TestDarwinProcessCollector(t *testing.T) {
5555
regexp.MustCompile("\nprocess_max_fds [1-9]"),
5656
regexp.MustCompile("\nprocess_open_fds [1-9]"),
5757
regexp.MustCompile("\nprocess_virtual_memory_max_bytes (-1|[1-9])"),
58-
regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"),
58+
regexp.MustCompile("\nprocess_start_time_seconds [0-9]"),
5959
regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"),
6060
regexp.MustCompile("\nfoobar_process_max_fds [1-9]"),
6161
regexp.MustCompile("\nfoobar_process_open_fds [1-9]"),
6262
regexp.MustCompile("\nfoobar_process_virtual_memory_max_bytes (-1|[1-9])"),
63-
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"),
63+
regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9]"),
6464
} {
6565
if !re.Match(buf.Bytes()) {
6666
t.Errorf("want body to match %s\n%s", re, buf.String())

prometheus/push/push.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ func (p *Pusher) Error() error {
182182
// For convenience, this method returns a pointer to the Pusher itself.
183183
func (p *Pusher) Grouping(name, value string) *Pusher {
184184
if p.error == nil {
185-
//nolint:staticcheck // TODO: Don't use deprecated model.NameValidationScheme.
186-
if !model.NameValidationScheme.IsValidLabelName(name) {
185+
if !model.UTF8Validation.IsValidLabelName(name) {
187186
p.error = fmt.Errorf("grouping label has invalid name: %s", name)
188187
return p
189188
}

0 commit comments

Comments
 (0)