Skip to content

Commit 2c2903f

Browse files
Upgrade Golang version v1.24 (#1738)
* update golang version Signed-off-by: dongjiang <[email protected]> * fix the new tests analyzer reports common mistakes in declarations of examples name Signed-off-by: dongjiang <[email protected]> * Update .github/workflows/golangci-lint.yml Signed-off-by: dongjiang <[email protected]> * update golanglint list Signed-off-by: dongjiang <[email protected]> --------- Signed-off-by: dongjiang <[email protected]>
1 parent 2de10d2 commit 2c2903f

11 files changed

+356
-16
lines changed

.github/workflows/go.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ jobs:
6262
CI: true
6363

6464
- name: Run style and unused
65-
if: ${{ matrix.go_version == '1.21' }}
65+
if: ${{ matrix.go_version == '1.22' }}
6666
run: make style unused

.github/workflows/golangci-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ jobs:
2828
- name: Install Go
2929
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
3030
with:
31-
go-version: 1.23.x
31+
go-version: 1.24.x
3232
- name: Install snmp_exporter/generator dependencies
3333
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3434
if: github.repository == 'prometheus/snmp_exporter'
3535
- name: Lint
3636
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
3737
with:
3838
args: --verbose
39-
version: v1.63.4
39+
version: v1.64.5

.golangci.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
---
22
run:
33
timeout: 5m
4-
skip-files:
5-
# Skip autogenerated files.
6-
- ^.*\.(pb|y)\.go$
74

85
output:
96
sort-results: true
107

118
linters:
129
enable:
10+
- copyloopvar
1311
- depguard
1412
- durationcheck
1513
- errorlint
16-
- exportloopref
14+
# The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
15+
# - exportloopref
1716
- gofmt
1817
- gofumpt
1918
- goimports
@@ -38,6 +37,10 @@ issues:
3837
- errcheck
3938
- govet
4039
- structcheck
40+
# The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
41+
exclude-files:
42+
# Skip autogenerated files.
43+
- ^.*\.(pb|y)\.go$
4144

4245
linters-settings:
4346
depguard:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/prometheus/client_golang
22

3-
go 1.21
3+
go 1.22
44

55
require (
66
github.com/beorn7/perks v1.0.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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+
//go:build go1.24 && !go1.25
15+
// +build go1.24,!go1.25
16+
17+
package collectors
18+
19+
func withAllMetrics() []string {
20+
return withBaseMetrics([]string{
21+
"go_cgo_go_to_c_calls_calls_total",
22+
"go_cpu_classes_gc_mark_assist_cpu_seconds_total",
23+
"go_cpu_classes_gc_mark_dedicated_cpu_seconds_total",
24+
"go_cpu_classes_gc_mark_idle_cpu_seconds_total",
25+
"go_cpu_classes_gc_pause_cpu_seconds_total",
26+
"go_cpu_classes_gc_total_cpu_seconds_total",
27+
"go_cpu_classes_idle_cpu_seconds_total",
28+
"go_cpu_classes_scavenge_assist_cpu_seconds_total",
29+
"go_cpu_classes_scavenge_background_cpu_seconds_total",
30+
"go_cpu_classes_scavenge_total_cpu_seconds_total",
31+
"go_cpu_classes_total_cpu_seconds_total",
32+
"go_cpu_classes_user_cpu_seconds_total",
33+
"go_gc_cycles_automatic_gc_cycles_total",
34+
"go_gc_cycles_forced_gc_cycles_total",
35+
"go_gc_cycles_total_gc_cycles_total",
36+
"go_gc_gogc_percent",
37+
"go_gc_gomemlimit_bytes",
38+
"go_gc_heap_allocs_by_size_bytes",
39+
"go_gc_heap_allocs_bytes_total",
40+
"go_gc_heap_allocs_objects_total",
41+
"go_gc_heap_frees_by_size_bytes",
42+
"go_gc_heap_frees_bytes_total",
43+
"go_gc_heap_frees_objects_total",
44+
"go_gc_heap_goal_bytes",
45+
"go_gc_heap_live_bytes",
46+
"go_gc_heap_objects_objects",
47+
"go_gc_heap_tiny_allocs_objects_total",
48+
"go_gc_limiter_last_enabled_gc_cycle",
49+
"go_gc_pauses_seconds",
50+
"go_gc_scan_globals_bytes",
51+
"go_gc_scan_heap_bytes",
52+
"go_gc_scan_stack_bytes",
53+
"go_gc_scan_total_bytes",
54+
"go_gc_stack_starting_size_bytes",
55+
"go_godebug_non_default_behavior_asynctimerchan_events_total",
56+
"go_godebug_non_default_behavior_execerrdot_events_total",
57+
"go_godebug_non_default_behavior_gocachehash_events_total",
58+
"go_godebug_non_default_behavior_gocachetest_events_total",
59+
"go_godebug_non_default_behavior_gocacheverify_events_total",
60+
"go_godebug_non_default_behavior_gotestjsonbuildtext_events_total",
61+
"go_godebug_non_default_behavior_gotypesalias_events_total",
62+
"go_godebug_non_default_behavior_http2client_events_total",
63+
"go_godebug_non_default_behavior_http2server_events_total",
64+
"go_godebug_non_default_behavior_httplaxcontentlength_events_total",
65+
"go_godebug_non_default_behavior_httpmuxgo121_events_total",
66+
"go_godebug_non_default_behavior_httpservecontentkeepheaders_events_total",
67+
"go_godebug_non_default_behavior_installgoroot_events_total",
68+
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
69+
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
70+
"go_godebug_non_default_behavior_multipathtcp_events_total",
71+
"go_godebug_non_default_behavior_netedns0_events_total",
72+
"go_godebug_non_default_behavior_panicnil_events_total",
73+
"go_godebug_non_default_behavior_randautoseed_events_total",
74+
"go_godebug_non_default_behavior_randseednop_events_total",
75+
"go_godebug_non_default_behavior_rsa1024min_events_total",
76+
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
77+
"go_godebug_non_default_behavior_tls10server_events_total",
78+
"go_godebug_non_default_behavior_tls3des_events_total",
79+
"go_godebug_non_default_behavior_tlsmaxrsasize_events_total",
80+
"go_godebug_non_default_behavior_tlsrsakex_events_total",
81+
"go_godebug_non_default_behavior_tlsunsafeekm_events_total",
82+
"go_godebug_non_default_behavior_winreadlinkvolume_events_total",
83+
"go_godebug_non_default_behavior_winsymlink_events_total",
84+
"go_godebug_non_default_behavior_x509keypairleaf_events_total",
85+
"go_godebug_non_default_behavior_x509negativeserial_events_total",
86+
"go_godebug_non_default_behavior_x509rsacrt_events_total",
87+
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
88+
"go_godebug_non_default_behavior_x509usepolicies_events_total",
89+
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
90+
"go_memory_classes_heap_free_bytes",
91+
"go_memory_classes_heap_objects_bytes",
92+
"go_memory_classes_heap_released_bytes",
93+
"go_memory_classes_heap_stacks_bytes",
94+
"go_memory_classes_heap_unused_bytes",
95+
"go_memory_classes_metadata_mcache_free_bytes",
96+
"go_memory_classes_metadata_mcache_inuse_bytes",
97+
"go_memory_classes_metadata_mspan_free_bytes",
98+
"go_memory_classes_metadata_mspan_inuse_bytes",
99+
"go_memory_classes_metadata_other_bytes",
100+
"go_memory_classes_os_stacks_bytes",
101+
"go_memory_classes_other_bytes",
102+
"go_memory_classes_profiling_buckets_bytes",
103+
"go_memory_classes_total_bytes",
104+
"go_sched_gomaxprocs_threads",
105+
"go_sched_goroutines_goroutines",
106+
"go_sched_latencies_seconds",
107+
"go_sched_pauses_stopping_gc_seconds",
108+
"go_sched_pauses_stopping_other_seconds",
109+
"go_sched_pauses_total_gc_seconds",
110+
"go_sched_pauses_total_other_seconds",
111+
"go_sync_mutex_wait_total_seconds_total",
112+
})
113+
}
114+
115+
func withGCMetrics() []string {
116+
return withBaseMetrics([]string{
117+
"go_gc_cycles_automatic_gc_cycles_total",
118+
"go_gc_cycles_forced_gc_cycles_total",
119+
"go_gc_cycles_total_gc_cycles_total",
120+
"go_gc_gogc_percent",
121+
"go_gc_gomemlimit_bytes",
122+
"go_gc_heap_allocs_by_size_bytes",
123+
"go_gc_heap_allocs_bytes_total",
124+
"go_gc_heap_allocs_objects_total",
125+
"go_gc_heap_frees_by_size_bytes",
126+
"go_gc_heap_frees_bytes_total",
127+
"go_gc_heap_frees_objects_total",
128+
"go_gc_heap_goal_bytes",
129+
"go_gc_heap_live_bytes",
130+
"go_gc_heap_objects_objects",
131+
"go_gc_heap_tiny_allocs_objects_total",
132+
"go_gc_limiter_last_enabled_gc_cycle",
133+
"go_gc_pauses_seconds",
134+
"go_gc_scan_globals_bytes",
135+
"go_gc_scan_heap_bytes",
136+
"go_gc_scan_stack_bytes",
137+
"go_gc_scan_total_bytes",
138+
"go_gc_stack_starting_size_bytes",
139+
})
140+
}
141+
142+
func withMemoryMetrics() []string {
143+
return withBaseMetrics([]string{
144+
"go_memory_classes_heap_free_bytes",
145+
"go_memory_classes_heap_objects_bytes",
146+
"go_memory_classes_heap_released_bytes",
147+
"go_memory_classes_heap_stacks_bytes",
148+
"go_memory_classes_heap_unused_bytes",
149+
"go_memory_classes_metadata_mcache_free_bytes",
150+
"go_memory_classes_metadata_mcache_inuse_bytes",
151+
"go_memory_classes_metadata_mspan_free_bytes",
152+
"go_memory_classes_metadata_mspan_inuse_bytes",
153+
"go_memory_classes_metadata_other_bytes",
154+
"go_memory_classes_os_stacks_bytes",
155+
"go_memory_classes_other_bytes",
156+
"go_memory_classes_profiling_buckets_bytes",
157+
"go_memory_classes_total_bytes",
158+
})
159+
}
160+
161+
func withSchedulerMetrics() []string {
162+
return withBaseMetrics([]string{
163+
"go_sched_gomaxprocs_threads",
164+
"go_sched_goroutines_goroutines",
165+
"go_sched_latencies_seconds",
166+
"go_sched_pauses_stopping_gc_seconds",
167+
"go_sched_pauses_stopping_other_seconds",
168+
"go_sched_pauses_total_gc_seconds",
169+
"go_sched_pauses_total_other_seconds",
170+
})
171+
}
172+
173+
func withDebugMetrics() []string {
174+
return withBaseMetrics([]string{
175+
"go_godebug_non_default_behavior_asynctimerchan_events_total",
176+
"go_godebug_non_default_behavior_execerrdot_events_total",
177+
"go_godebug_non_default_behavior_gocachehash_events_total",
178+
"go_godebug_non_default_behavior_gocachetest_events_total",
179+
"go_godebug_non_default_behavior_gocacheverify_events_total",
180+
"go_godebug_non_default_behavior_gotestjsonbuildtext_events_total",
181+
"go_godebug_non_default_behavior_gotypesalias_events_total",
182+
"go_godebug_non_default_behavior_http2client_events_total",
183+
"go_godebug_non_default_behavior_http2server_events_total",
184+
"go_godebug_non_default_behavior_httplaxcontentlength_events_total",
185+
"go_godebug_non_default_behavior_httpmuxgo121_events_total",
186+
"go_godebug_non_default_behavior_httpservecontentkeepheaders_events_total",
187+
"go_godebug_non_default_behavior_installgoroot_events_total",
188+
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
189+
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
190+
"go_godebug_non_default_behavior_multipathtcp_events_total",
191+
"go_godebug_non_default_behavior_netedns0_events_total",
192+
"go_godebug_non_default_behavior_panicnil_events_total",
193+
"go_godebug_non_default_behavior_randautoseed_events_total",
194+
"go_godebug_non_default_behavior_randseednop_events_total",
195+
"go_godebug_non_default_behavior_rsa1024min_events_total",
196+
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
197+
"go_godebug_non_default_behavior_tls10server_events_total",
198+
"go_godebug_non_default_behavior_tls3des_events_total",
199+
"go_godebug_non_default_behavior_tlsmaxrsasize_events_total",
200+
"go_godebug_non_default_behavior_tlsrsakex_events_total",
201+
"go_godebug_non_default_behavior_tlsunsafeekm_events_total",
202+
"go_godebug_non_default_behavior_winreadlinkvolume_events_total",
203+
"go_godebug_non_default_behavior_winsymlink_events_total",
204+
"go_godebug_non_default_behavior_x509keypairleaf_events_total",
205+
"go_godebug_non_default_behavior_x509negativeserial_events_total",
206+
"go_godebug_non_default_behavior_x509rsacrt_events_total",
207+
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
208+
"go_godebug_non_default_behavior_x509usepolicies_events_total",
209+
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
210+
})
211+
}
212+
213+
var (
214+
defaultRuntimeMetrics = []string{
215+
"go_gc_gogc_percent",
216+
"go_gc_gomemlimit_bytes",
217+
"go_sched_gomaxprocs_threads",
218+
}
219+
onlyGCDefRuntimeMetrics = []string{
220+
"go_gc_gogc_percent",
221+
"go_gc_gomemlimit_bytes",
222+
}
223+
onlySchedDefRuntimeMetrics = []string{
224+
"go_sched_gomaxprocs_threads",
225+
}
226+
)

prometheus/collectors/go_collector_latest_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func TestGoCollectorDenyList(t *testing.T) {
258258
}
259259
}
260260

261-
func ExampleGoCollector() {
261+
func ExampleNewGoCollector() {
262262
reg := prometheus.NewPedanticRegistry()
263263

264264
// Register the GoCollector with the default options. Only the base metrics, default runtime metrics and memstats are enabled.
@@ -268,7 +268,7 @@ func ExampleGoCollector() {
268268
log.Fatal(http.ListenAndServe(":8080", nil))
269269
}
270270

271-
func ExampleGoCollector_WithAdvancedGoMetrics() {
271+
func ExampleNewGoCollector_withAdvancedGoMetrics() {
272272
reg := prometheus.NewPedanticRegistry()
273273

274274
// Enable Go metrics with pre-defined rules. Or your custom rules.
@@ -289,7 +289,7 @@ func ExampleGoCollector_WithAdvancedGoMetrics() {
289289
log.Fatal(http.ListenAndServe(":8080", nil))
290290
}
291291

292-
func ExampleGoCollector_DefaultRegister() {
292+
func ExampleNewGoCollector_defaultRegister() {
293293
// Unregister the default GoCollector.
294294
prometheus.Unregister(NewGoCollector())
295295

prometheus/examples_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func ExampleNewConstHistogramWithCreatedTimestamp() {
513513
// {"label":[{"name":"code","value":"200"},{"name":"method","value":"get"},{"name":"owner","value":"example"}],"histogram":{"sampleCount":"4711","sampleSum":403.34,"bucket":[{"cumulativeCount":"121","upperBound":25},{"cumulativeCount":"2403","upperBound":50},{"cumulativeCount":"3221","upperBound":100},{"cumulativeCount":"4233","upperBound":200}],"createdTimestamp":"2024-06-29T14:19:24.000000123Z"}}
514514
}
515515

516-
func ExampleNewConstHistogram_WithExemplar() {
516+
func ExampleNewConstHistogram_withExemplar() {
517517
desc := prometheus.NewDesc(
518518
"http_request_duration_seconds",
519519
"A histogram of the HTTP request durations.",

0 commit comments

Comments
 (0)