Skip to content

Commit

Permalink
Upgrade Golang version v1.24 (#1738)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
dongjiang1989 authored Feb 19, 2025
1 parent 2de10d2 commit 2c2903f
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ jobs:
CI: true

- name: Run style and unused
if: ${{ matrix.go_version == '1.21' }}
if: ${{ matrix.go_version == '1.22' }}
run: make style unused
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ jobs:
- name: Install Go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: 1.23.x
go-version: 1.24.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0
with:
args: --verbose
version: v1.63.4
version: v1.64.5
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
---
run:
timeout: 5m
skip-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$

output:
sort-results: true

linters:
enable:
- copyloopvar
- depguard
- durationcheck
- errorlint
- exportloopref
# The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
# - exportloopref
- gofmt
- gofumpt
- goimports
Expand All @@ -38,6 +37,10 @@ issues:
- errcheck
- govet
- structcheck
# The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`.
exclude-files:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$

linters-settings:
depguard:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/prometheus/client_golang

go 1.21
go 1.22

require (
github.com/beorn7/perks v1.0.1
Expand Down
226 changes: 226 additions & 0 deletions prometheus/collectors/go_collector_go124_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
// Copyright 2022 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build go1.24 && !go1.25
// +build go1.24,!go1.25

package collectors

func withAllMetrics() []string {
return withBaseMetrics([]string{
"go_cgo_go_to_c_calls_calls_total",
"go_cpu_classes_gc_mark_assist_cpu_seconds_total",
"go_cpu_classes_gc_mark_dedicated_cpu_seconds_total",
"go_cpu_classes_gc_mark_idle_cpu_seconds_total",
"go_cpu_classes_gc_pause_cpu_seconds_total",
"go_cpu_classes_gc_total_cpu_seconds_total",
"go_cpu_classes_idle_cpu_seconds_total",
"go_cpu_classes_scavenge_assist_cpu_seconds_total",
"go_cpu_classes_scavenge_background_cpu_seconds_total",
"go_cpu_classes_scavenge_total_cpu_seconds_total",
"go_cpu_classes_total_cpu_seconds_total",
"go_cpu_classes_user_cpu_seconds_total",
"go_gc_cycles_automatic_gc_cycles_total",
"go_gc_cycles_forced_gc_cycles_total",
"go_gc_cycles_total_gc_cycles_total",
"go_gc_gogc_percent",
"go_gc_gomemlimit_bytes",
"go_gc_heap_allocs_by_size_bytes",
"go_gc_heap_allocs_bytes_total",
"go_gc_heap_allocs_objects_total",
"go_gc_heap_frees_by_size_bytes",
"go_gc_heap_frees_bytes_total",
"go_gc_heap_frees_objects_total",
"go_gc_heap_goal_bytes",
"go_gc_heap_live_bytes",
"go_gc_heap_objects_objects",
"go_gc_heap_tiny_allocs_objects_total",
"go_gc_limiter_last_enabled_gc_cycle",
"go_gc_pauses_seconds",
"go_gc_scan_globals_bytes",
"go_gc_scan_heap_bytes",
"go_gc_scan_stack_bytes",
"go_gc_scan_total_bytes",
"go_gc_stack_starting_size_bytes",
"go_godebug_non_default_behavior_asynctimerchan_events_total",
"go_godebug_non_default_behavior_execerrdot_events_total",
"go_godebug_non_default_behavior_gocachehash_events_total",
"go_godebug_non_default_behavior_gocachetest_events_total",
"go_godebug_non_default_behavior_gocacheverify_events_total",
"go_godebug_non_default_behavior_gotestjsonbuildtext_events_total",
"go_godebug_non_default_behavior_gotypesalias_events_total",
"go_godebug_non_default_behavior_http2client_events_total",
"go_godebug_non_default_behavior_http2server_events_total",
"go_godebug_non_default_behavior_httplaxcontentlength_events_total",
"go_godebug_non_default_behavior_httpmuxgo121_events_total",
"go_godebug_non_default_behavior_httpservecontentkeepheaders_events_total",
"go_godebug_non_default_behavior_installgoroot_events_total",
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_randseednop_events_total",
"go_godebug_non_default_behavior_rsa1024min_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
"go_godebug_non_default_behavior_tls10server_events_total",
"go_godebug_non_default_behavior_tls3des_events_total",
"go_godebug_non_default_behavior_tlsmaxrsasize_events_total",
"go_godebug_non_default_behavior_tlsrsakex_events_total",
"go_godebug_non_default_behavior_tlsunsafeekm_events_total",
"go_godebug_non_default_behavior_winreadlinkvolume_events_total",
"go_godebug_non_default_behavior_winsymlink_events_total",
"go_godebug_non_default_behavior_x509keypairleaf_events_total",
"go_godebug_non_default_behavior_x509negativeserial_events_total",
"go_godebug_non_default_behavior_x509rsacrt_events_total",
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
"go_godebug_non_default_behavior_x509usepolicies_events_total",
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
"go_memory_classes_heap_free_bytes",
"go_memory_classes_heap_objects_bytes",
"go_memory_classes_heap_released_bytes",
"go_memory_classes_heap_stacks_bytes",
"go_memory_classes_heap_unused_bytes",
"go_memory_classes_metadata_mcache_free_bytes",
"go_memory_classes_metadata_mcache_inuse_bytes",
"go_memory_classes_metadata_mspan_free_bytes",
"go_memory_classes_metadata_mspan_inuse_bytes",
"go_memory_classes_metadata_other_bytes",
"go_memory_classes_os_stacks_bytes",
"go_memory_classes_other_bytes",
"go_memory_classes_profiling_buckets_bytes",
"go_memory_classes_total_bytes",
"go_sched_gomaxprocs_threads",
"go_sched_goroutines_goroutines",
"go_sched_latencies_seconds",
"go_sched_pauses_stopping_gc_seconds",
"go_sched_pauses_stopping_other_seconds",
"go_sched_pauses_total_gc_seconds",
"go_sched_pauses_total_other_seconds",
"go_sync_mutex_wait_total_seconds_total",
})
}

func withGCMetrics() []string {
return withBaseMetrics([]string{
"go_gc_cycles_automatic_gc_cycles_total",
"go_gc_cycles_forced_gc_cycles_total",
"go_gc_cycles_total_gc_cycles_total",
"go_gc_gogc_percent",
"go_gc_gomemlimit_bytes",
"go_gc_heap_allocs_by_size_bytes",
"go_gc_heap_allocs_bytes_total",
"go_gc_heap_allocs_objects_total",
"go_gc_heap_frees_by_size_bytes",
"go_gc_heap_frees_bytes_total",
"go_gc_heap_frees_objects_total",
"go_gc_heap_goal_bytes",
"go_gc_heap_live_bytes",
"go_gc_heap_objects_objects",
"go_gc_heap_tiny_allocs_objects_total",
"go_gc_limiter_last_enabled_gc_cycle",
"go_gc_pauses_seconds",
"go_gc_scan_globals_bytes",
"go_gc_scan_heap_bytes",
"go_gc_scan_stack_bytes",
"go_gc_scan_total_bytes",
"go_gc_stack_starting_size_bytes",
})
}

func withMemoryMetrics() []string {
return withBaseMetrics([]string{
"go_memory_classes_heap_free_bytes",
"go_memory_classes_heap_objects_bytes",
"go_memory_classes_heap_released_bytes",
"go_memory_classes_heap_stacks_bytes",
"go_memory_classes_heap_unused_bytes",
"go_memory_classes_metadata_mcache_free_bytes",
"go_memory_classes_metadata_mcache_inuse_bytes",
"go_memory_classes_metadata_mspan_free_bytes",
"go_memory_classes_metadata_mspan_inuse_bytes",
"go_memory_classes_metadata_other_bytes",
"go_memory_classes_os_stacks_bytes",
"go_memory_classes_other_bytes",
"go_memory_classes_profiling_buckets_bytes",
"go_memory_classes_total_bytes",
})
}

func withSchedulerMetrics() []string {
return withBaseMetrics([]string{
"go_sched_gomaxprocs_threads",
"go_sched_goroutines_goroutines",
"go_sched_latencies_seconds",
"go_sched_pauses_stopping_gc_seconds",
"go_sched_pauses_stopping_other_seconds",
"go_sched_pauses_total_gc_seconds",
"go_sched_pauses_total_other_seconds",
})
}

func withDebugMetrics() []string {
return withBaseMetrics([]string{
"go_godebug_non_default_behavior_asynctimerchan_events_total",
"go_godebug_non_default_behavior_execerrdot_events_total",
"go_godebug_non_default_behavior_gocachehash_events_total",
"go_godebug_non_default_behavior_gocachetest_events_total",
"go_godebug_non_default_behavior_gocacheverify_events_total",
"go_godebug_non_default_behavior_gotestjsonbuildtext_events_total",
"go_godebug_non_default_behavior_gotypesalias_events_total",
"go_godebug_non_default_behavior_http2client_events_total",
"go_godebug_non_default_behavior_http2server_events_total",
"go_godebug_non_default_behavior_httplaxcontentlength_events_total",
"go_godebug_non_default_behavior_httpmuxgo121_events_total",
"go_godebug_non_default_behavior_httpservecontentkeepheaders_events_total",
"go_godebug_non_default_behavior_installgoroot_events_total",
"go_godebug_non_default_behavior_multipartmaxheaders_events_total",
"go_godebug_non_default_behavior_multipartmaxparts_events_total",
"go_godebug_non_default_behavior_multipathtcp_events_total",
"go_godebug_non_default_behavior_netedns0_events_total",
"go_godebug_non_default_behavior_panicnil_events_total",
"go_godebug_non_default_behavior_randautoseed_events_total",
"go_godebug_non_default_behavior_randseednop_events_total",
"go_godebug_non_default_behavior_rsa1024min_events_total",
"go_godebug_non_default_behavior_tarinsecurepath_events_total",
"go_godebug_non_default_behavior_tls10server_events_total",
"go_godebug_non_default_behavior_tls3des_events_total",
"go_godebug_non_default_behavior_tlsmaxrsasize_events_total",
"go_godebug_non_default_behavior_tlsrsakex_events_total",
"go_godebug_non_default_behavior_tlsunsafeekm_events_total",
"go_godebug_non_default_behavior_winreadlinkvolume_events_total",
"go_godebug_non_default_behavior_winsymlink_events_total",
"go_godebug_non_default_behavior_x509keypairleaf_events_total",
"go_godebug_non_default_behavior_x509negativeserial_events_total",
"go_godebug_non_default_behavior_x509rsacrt_events_total",
"go_godebug_non_default_behavior_x509usefallbackroots_events_total",
"go_godebug_non_default_behavior_x509usepolicies_events_total",
"go_godebug_non_default_behavior_zipinsecurepath_events_total",
})
}

var (
defaultRuntimeMetrics = []string{
"go_gc_gogc_percent",
"go_gc_gomemlimit_bytes",
"go_sched_gomaxprocs_threads",
}
onlyGCDefRuntimeMetrics = []string{
"go_gc_gogc_percent",
"go_gc_gomemlimit_bytes",
}
onlySchedDefRuntimeMetrics = []string{
"go_sched_gomaxprocs_threads",
}
)
6 changes: 3 additions & 3 deletions prometheus/collectors/go_collector_latest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestGoCollectorDenyList(t *testing.T) {
}
}

func ExampleGoCollector() {
func ExampleNewGoCollector() {
reg := prometheus.NewPedanticRegistry()

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

func ExampleGoCollector_WithAdvancedGoMetrics() {
func ExampleNewGoCollector_withAdvancedGoMetrics() {
reg := prometheus.NewPedanticRegistry()

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

func ExampleGoCollector_DefaultRegister() {
func ExampleNewGoCollector_defaultRegister() {
// Unregister the default GoCollector.
prometheus.Unregister(NewGoCollector())

Expand Down
2 changes: 1 addition & 1 deletion prometheus/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func ExampleNewConstHistogramWithCreatedTimestamp() {
// {"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"}}
}

func ExampleNewConstHistogram_WithExemplar() {
func ExampleNewConstHistogram_withExemplar() {
desc := prometheus.NewDesc(
"http_request_duration_seconds",
"A histogram of the HTTP request durations.",
Expand Down
Loading

0 comments on commit 2c2903f

Please sign in to comment.