Skip to content

Commit 6cba8d6

Browse files
authored
Merge branch 'prometheus:main' into main
2 parents 3239f2f + a9c0488 commit 6cba8d6

17 files changed

+411
-139
lines changed

CHANGELOG.md

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

3+
* [BUGFIX] histograms: Fix possible data race when appending exemplars vs metrics gather. #1623
4+
5+
## 1.20.3 / 2024-09-05
6+
7+
* [BUGFIX] histograms: Fix possible data race when appending exemplars. #1608
8+
39
## 1.20.2 / 2024-08-23
410

511
* [BUGFIX] promhttp: Unset Content-Encoding header when data is uncompressed. #1596

Makefile.common

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,9 @@ $(1)_precheck:
275275
exit 1; \
276276
fi
277277
endef
278+
279+
govulncheck: install-govulncheck
280+
govulncheck ./...
281+
282+
install-govulncheck:
283+
command -v govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest

examples/customlabels/main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2022 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
// A simple example of how to add fixed custom labels to all metrics exported by the origin collector.
15+
// For more details, see the documentation: https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#WrapRegistererWith
16+
17+
package main
18+
19+
import (
20+
"flag"
21+
"log"
22+
"net/http"
23+
24+
"github.com/prometheus/client_golang/prometheus"
25+
"github.com/prometheus/client_golang/prometheus/collectors"
26+
"github.com/prometheus/client_golang/prometheus/promhttp"
27+
)
28+
29+
var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")
30+
31+
func main() {
32+
flag.Parse()
33+
34+
// Create a new registry.
35+
reg := prometheus.NewRegistry()
36+
prometheus.WrapRegistererWith(prometheus.Labels{"serviceName": "my-service-name"}, reg).MustRegister(
37+
collectors.NewGoCollector(),
38+
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
39+
)
40+
41+
// Expose the registered metrics via HTTP.
42+
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
43+
log.Fatal(http.ListenAndServe(*addr, nil))
44+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ require (
77
github.com/cespare/xxhash/v2 v2.3.0
88
github.com/google/go-cmp v0.6.0
99
github.com/json-iterator/go v1.1.12
10-
github.com/klauspost/compress v1.17.9
10+
github.com/klauspost/compress v1.17.10
1111
github.com/kylelemons/godebug v1.1.0
1212
github.com/prometheus/client_model v0.6.1
1313
github.com/prometheus/common v0.59.1
1414
github.com/prometheus/procfs v0.15.1
15-
golang.org/x/sys v0.24.0
15+
golang.org/x/sys v0.25.0
1616
google.golang.org/protobuf v1.34.2
1717
)
1818

go.sum

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2E
1313
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
1414
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
1515
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
16-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
17-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
16+
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
17+
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
1818
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1919
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2020
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -35,10 +35,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
3535
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3636
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
3737
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
38-
github.com/prometheus/common v0.57.0 h1:Ro/rKjwdq9mZn1K5QPctzh+MA4Lp0BuYk5ZZEVhoNcY=
39-
github.com/prometheus/common v0.57.0/go.mod h1:7uRPFSUTbfZWsJ7MHY56sqt7hLQu3bxXHDnNhl8E9qI=
40-
github.com/prometheus/common v0.59.0 h1:o2eVCLbhf3sgisnD5e0/twUt25r8gNmMHNzTOAuY9bs=
41-
github.com/prometheus/common v0.59.0/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
4238
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
4339
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
4440
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
@@ -54,8 +50,8 @@ golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
5450
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
5551
golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA=
5652
golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
57-
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
58-
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
53+
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
54+
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5955
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
6056
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
6157
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=

prometheus/collectors/gen_go_collector_set.go

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,48 @@ func main() {
7878
v := goVersion(gv.Segments()[1])
7979
log.Printf("generating metrics for Go version %q", v)
8080

81-
descriptions := computeMetricsList()
81+
descriptions := computeMetricsList(metrics.All())
8282
groupedMetrics := groupMetrics(descriptions)
8383

84+
// Find default metrics.
85+
var defaultRuntimeDesc []metrics.Description
86+
for _, d := range metrics.All() {
87+
if !internal.GoCollectorDefaultRuntimeMetrics.MatchString(d.Name) {
88+
continue
89+
}
90+
defaultRuntimeDesc = append(defaultRuntimeDesc, d)
91+
}
92+
93+
defaultRuntimeMetricsList := computeMetricsList(defaultRuntimeDesc)
94+
95+
onlyGCDefRuntimeMetricsList := []string{}
96+
onlySchedDefRuntimeMetricsList := []string{}
97+
98+
for _, m := range defaultRuntimeMetricsList {
99+
if strings.HasPrefix(m, "go_gc") {
100+
onlyGCDefRuntimeMetricsList = append(onlyGCDefRuntimeMetricsList, m)
101+
}
102+
if strings.HasPrefix(m, "go_sched") {
103+
onlySchedDefRuntimeMetricsList = append(onlySchedDefRuntimeMetricsList, m)
104+
} else {
105+
continue
106+
}
107+
}
108+
84109
// Generate code.
85110
var buf bytes.Buffer
86111
err = testFile.Execute(&buf, struct {
87-
GoVersion goVersion
88-
Groups []metricGroup
112+
GoVersion goVersion
113+
Groups []metricGroup
114+
DefaultRuntimeMetricsList []string
115+
OnlyGCDefRuntimeMetricsList []string
116+
OnlySchedDefRuntimeMetricsList []string
89117
}{
90-
GoVersion: v,
91-
Groups: groupedMetrics,
118+
GoVersion: v,
119+
Groups: groupedMetrics,
120+
DefaultRuntimeMetricsList: defaultRuntimeMetricsList,
121+
OnlyGCDefRuntimeMetricsList: onlyGCDefRuntimeMetricsList,
122+
OnlySchedDefRuntimeMetricsList: onlySchedDefRuntimeMetricsList,
92123
})
93124
if err != nil {
94125
log.Fatalf("executing template: %v", err)
@@ -107,9 +138,9 @@ func main() {
107138
}
108139
}
109140

110-
func computeMetricsList() []string {
141+
func computeMetricsList(descs []metrics.Description) []string {
111142
var metricsList []string
112-
for _, d := range metrics.All() {
143+
for _, d := range descs {
113144
if trans := rm2prom(d); trans != "" {
114145
metricsList = append(metricsList, trans)
115146
}
@@ -186,4 +217,22 @@ func {{ .Name }}() []string {
186217
})
187218
}
188219
{{ end }}
220+
221+
var (
222+
defaultRuntimeMetrics = []string{
223+
{{- range $metric := .DefaultRuntimeMetricsList }}
224+
{{ $metric | printf "%q"}},
225+
{{- end }}
226+
}
227+
onlyGCDefRuntimeMetrics = []string{
228+
{{- range $metric := .OnlyGCDefRuntimeMetricsList }}
229+
{{ $metric | printf "%q"}},
230+
{{- end }}
231+
}
232+
onlySchedDefRuntimeMetrics = []string{
233+
{{- range $metric := .OnlySchedDefRuntimeMetricsList }}
234+
{{ $metric | printf "%q"}},
235+
{{- end }}
236+
}
237+
)
189238
`))

prometheus/collectors/go_collector_go120_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package collectors
1818

19-
import "sort"
20-
2119
func withAllMetrics() []string {
2220
return withBaseMetrics([]string{
2321
"go_cgo_go_to_c_calls_calls_total",
@@ -119,17 +117,12 @@ func withDebugMetrics() []string {
119117
return withBaseMetrics([]string{})
120118
}
121119

122-
var defaultRuntimeMetrics = []string{
123-
"go_sched_gomaxprocs_threads",
124-
}
125-
126-
func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string {
127-
// If withoutSched is true, exclude "go_sched_gomaxprocs_threads".
128-
if withoutSched {
129-
return metricNames
120+
var (
121+
defaultRuntimeMetrics = []string{
122+
"go_sched_gomaxprocs_threads",
130123
}
131-
metricNames = append(metricNames, defaultRuntimeMetrics...)
132-
// sorting is required
133-
sort.Strings(metricNames)
134-
return metricNames
135-
}
124+
onlyGCDefRuntimeMetrics = []string{}
125+
onlySchedDefRuntimeMetrics = []string{
126+
"go_sched_gomaxprocs_threads",
127+
}
128+
)

prometheus/collectors/go_collector_go121_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package collectors
1818

19-
import "sort"
20-
2119
func withAllMetrics() []string {
2220
return withBaseMetrics([]string{
2321
"go_cgo_go_to_c_calls_calls_total",
@@ -172,27 +170,17 @@ func withDebugMetrics() []string {
172170
})
173171
}
174172

175-
var defaultRuntimeMetrics = []string{
176-
"go_gc_gogc_percent",
177-
"go_gc_gomemlimit_bytes",
178-
"go_sched_gomaxprocs_threads",
179-
}
180-
181-
func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string {
182-
if withoutGC && withoutSched {
183-
// If both flags are true, return the metricNames as is.
184-
return metricNames
185-
} else if withoutGC && !withoutSched {
186-
// If only withoutGC is true, include "go_sched_gomaxprocs_threads" only.
187-
metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...)
188-
} else if withoutSched && !withoutGC {
189-
// If only withoutSched is true, exclude "go_sched_gomaxprocs_threads".
190-
metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...)
191-
} else {
192-
// If neither flag is true, use the default metrics.
193-
metricNames = append(metricNames, defaultRuntimeMetrics...)
173+
var (
174+
defaultRuntimeMetrics = []string{
175+
"go_gc_gogc_percent",
176+
"go_gc_gomemlimit_bytes",
177+
"go_sched_gomaxprocs_threads",
194178
}
195-
// sorting is required
196-
sort.Strings(metricNames)
197-
return metricNames
198-
}
179+
onlyGCDefRuntimeMetrics = []string{
180+
"go_gc_gogc_percent",
181+
"go_gc_gomemlimit_bytes",
182+
}
183+
onlySchedDefRuntimeMetrics = []string{
184+
"go_sched_gomaxprocs_threads",
185+
}
186+
)

prometheus/collectors/go_collector_go122_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package collectors
1818

19-
import "sort"
20-
2119
func withAllMetrics() []string {
2220
return withBaseMetrics([]string{
2321
"go_cgo_go_to_c_calls_calls_total",
@@ -194,27 +192,17 @@ func withDebugMetrics() []string {
194192
})
195193
}
196194

197-
var defaultRuntimeMetrics = []string{
198-
"go_gc_gogc_percent",
199-
"go_gc_gomemlimit_bytes",
200-
"go_sched_gomaxprocs_threads",
201-
}
202-
203-
func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string {
204-
if withoutGC && withoutSched {
205-
// If both flags are true, return the metricNames as is.
206-
return metricNames
207-
} else if withoutGC && !withoutSched {
208-
// If only withoutGC is true, include "go_sched_gomaxprocs_threads" only.
209-
metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...)
210-
} else if withoutSched && !withoutGC {
211-
// If only withoutSched is true, exclude "go_sched_gomaxprocs_threads".
212-
metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...)
213-
} else {
214-
// If neither flag is true, use the default metrics.
215-
metricNames = append(metricNames, defaultRuntimeMetrics...)
195+
var (
196+
defaultRuntimeMetrics = []string{
197+
"go_gc_gogc_percent",
198+
"go_gc_gomemlimit_bytes",
199+
"go_sched_gomaxprocs_threads",
216200
}
217-
// sorting is required
218-
sort.Strings(metricNames)
219-
return metricNames
220-
}
201+
onlyGCDefRuntimeMetrics = []string{
202+
"go_gc_gogc_percent",
203+
"go_gc_gomemlimit_bytes",
204+
}
205+
onlySchedDefRuntimeMetrics = []string{
206+
"go_sched_gomaxprocs_threads",
207+
}
208+
)

prometheus/collectors/go_collector_go123_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package collectors
1818

19-
import "sort"
20-
2119
func withAllMetrics() []string {
2220
return withBaseMetrics([]string{
2321
"go_cgo_go_to_c_calls_calls_total",
@@ -206,27 +204,17 @@ func withDebugMetrics() []string {
206204
})
207205
}
208206

209-
var defaultRuntimeMetrics = []string{
210-
"go_gc_gogc_percent",
211-
"go_gc_gomemlimit_bytes",
212-
"go_sched_gomaxprocs_threads",
213-
}
214-
215-
func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string {
216-
if withoutGC && withoutSched {
217-
// If both flags are true, return the metricNames as is.
218-
return metricNames
219-
} else if withoutGC && !withoutSched {
220-
// If only withoutGC is true, include "go_sched_gomaxprocs_threads" only.
221-
metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...)
222-
} else if withoutSched && !withoutGC {
223-
// If only withoutSched is true, exclude "go_sched_gomaxprocs_threads".
224-
metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...)
225-
} else {
226-
// If neither flag is true, use the default metrics.
227-
metricNames = append(metricNames, defaultRuntimeMetrics...)
207+
var (
208+
defaultRuntimeMetrics = []string{
209+
"go_gc_gogc_percent",
210+
"go_gc_gomemlimit_bytes",
211+
"go_sched_gomaxprocs_threads",
228212
}
229-
// sorting is required
230-
sort.Strings(metricNames)
231-
return metricNames
232-
}
213+
onlyGCDefRuntimeMetrics = []string{
214+
"go_gc_gogc_percent",
215+
"go_gc_gomemlimit_bytes",
216+
}
217+
onlySchedDefRuntimeMetrics = []string{
218+
"go_sched_gomaxprocs_threads",
219+
}
220+
)

0 commit comments

Comments
 (0)