From 06d4592b1c44364ca08ef53cf749a44ab7788340 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Fri, 11 Aug 2023 12:27:52 +0200 Subject: [PATCH] Add Go 1.21 support (#1325) * Add Go 1.21 support Signed-off-by: Kemal Akkoyun * Update README.md Signed-off-by: Kemal Akkoyun --------- Signed-off-by: Kemal Akkoyun --- .github/workflows/go.yml | 4 +- .go-version | 2 +- Makefile | 3 +- README.md | 5 +- .../collectors/go_collector_go121_test.go | 172 ++++++++++++++++++ prometheus/go_collector_metrics_go121_test.go | 81 +++++++++ 6 files changed, 260 insertions(+), 7 deletions(-) create mode 100644 prometheus/collectors/go_collector_go121_test.go create mode 100644 prometheus/go_collector_metrics_go121_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5f8d7c4..a9dfac5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,7 @@ on: push: branches: - main - - 'release-*' + - "release-*" # Minimal permissions to be inherited by any job that don't declare it's own permissions permissions: @@ -18,7 +18,7 @@ jobs: strategy: matrix: - go_version: ["1.18", "1.19", "1.20"] + go_version: ["1.19", "1.20", "1.21"] steps: - name: Checkout code diff --git a/.go-version b/.go-version index adc97d8..d2ab029 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.18 +1.21 diff --git a/Makefile b/Makefile index 490d0be..4cfdc1f 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ test: deps common-test test-short: deps common-test-short .PHONY: generate-go-collector-test-files -VERSIONS := 1.17 1.18 1.19 1.20 +VERSIONS := 1.19 1.20 1.21 generate-go-collector-test-files: for GO_VERSION in $(VERSIONS); do \ docker run --rm -v $(PWD):/workspace -w /workspace golang:$$GO_VERSION go run prometheus/gen_go_collector_metrics_set.go; \ @@ -31,4 +31,3 @@ generate-go-collector-test-files: .PHONY: fmt fmt: common-format $(GOIMPORTS) -local github.com/prometheus/client_golang -w . - \ No newline at end of file diff --git a/README.md b/README.md index 05ea7d6..21be4ee 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ This is the [Go](http://golang.org) client library for instrumenting application code, and one for creating clients that talk to the Prometheus HTTP API. -__This library requires Go1.18 or later.__ +**This library requires Go1.19 or later.** +> The library mandates the use of Go1.19 or subsequent versions. While it has demonstrated functionality with versions as old as Go 1.17, our commitment remains to offer support and rectifications for only the most recent three major releases. ## Important note about releases and stability This repository generally follows [Semantic Versioning](https://semver.org/). However, the API client in -prometheus/client_golang/api/… is still considered experimental. Breaking +`prometheus/client_golang/api/…` is still considered experimental. Breaking changes of the API client will _not_ trigger a new major release. The same is true for selected other new features explicitly marked as **EXPERIMENTAL** in CHANGELOG.md. diff --git a/prometheus/collectors/go_collector_go121_test.go b/prometheus/collectors/go_collector_go121_test.go new file mode 100644 index 0000000..2a550e6 --- /dev/null +++ b/prometheus/collectors/go_collector_go121_test.go @@ -0,0 +1,172 @@ +// 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.21 && !go1.22 +// +build go1.21,!go1.22 + +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_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_http2client_events_total", + "go_godebug_non_default_behavior_http2server_events_total", + "go_godebug_non_default_behavior_installgoroot_events_total", + "go_godebug_non_default_behavior_jstmpllitinterp_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_panicnil_events_total", + "go_godebug_non_default_behavior_randautoseed_events_total", + "go_godebug_non_default_behavior_tarinsecurepath_events_total", + "go_godebug_non_default_behavior_x509sha1_events_total", + "go_godebug_non_default_behavior_x509usefallbackroots_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_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 []string{ + "go_gc_duration_seconds", + "go_goroutines", + "go_info", + "go_memstats_last_gc_time_seconds", + "go_sched_gomaxprocs_threads", + "go_sched_goroutines_goroutines", + "go_sched_latencies_seconds", + "go_threads", + } +} + +func withDebugMetrics() []string { + return []string{ + "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_http2client_events_total", + "go_godebug_non_default_behavior_http2server_events_total", + "go_godebug_non_default_behavior_installgoroot_events_total", + "go_godebug_non_default_behavior_jstmpllitinterp_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_panicnil_events_total", + "go_godebug_non_default_behavior_randautoseed_events_total", + "go_godebug_non_default_behavior_tarinsecurepath_events_total", + "go_godebug_non_default_behavior_x509sha1_events_total", + "go_godebug_non_default_behavior_x509usefallbackroots_events_total", + "go_godebug_non_default_behavior_zipinsecurepath_events_total", + } +} diff --git a/prometheus/go_collector_metrics_go121_test.go b/prometheus/go_collector_metrics_go121_test.go new file mode 100644 index 0000000..3c2e44c --- /dev/null +++ b/prometheus/go_collector_metrics_go121_test.go @@ -0,0 +1,81 @@ +// Code generated by gen_go_collector_metrics_set.go; DO NOT EDIT. +//go:generate go run gen_go_collector_metrics_set.go go1.21 + +//go:build go1.21 && !go1.22 +// +build go1.21,!go1.22 + +package prometheus + +var expectedRuntimeMetrics = map[string]string{ + "/cgo/go-to-c-calls:calls": "go_cgo_go_to_c_calls_calls_total", + "/cpu/classes/gc/mark/assist:cpu-seconds": "go_cpu_classes_gc_mark_assist_cpu_seconds_total", + "/cpu/classes/gc/mark/dedicated:cpu-seconds": "go_cpu_classes_gc_mark_dedicated_cpu_seconds_total", + "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", + "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", + "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", + "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", + "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", + "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", + "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", + "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", + "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", + "/gc/cycles/automatic:gc-cycles": "go_gc_cycles_automatic_gc_cycles_total", + "/gc/cycles/forced:gc-cycles": "go_gc_cycles_forced_gc_cycles_total", + "/gc/cycles/total:gc-cycles": "go_gc_cycles_total_gc_cycles_total", + "/gc/gogc:percent": "go_gc_gogc_percent", + "/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", + "/gc/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes", + "/gc/heap/allocs:bytes": "go_gc_heap_allocs_bytes_total", + "/gc/heap/allocs:objects": "go_gc_heap_allocs_objects_total", + "/gc/heap/frees-by-size:bytes": "go_gc_heap_frees_by_size_bytes", + "/gc/heap/frees:bytes": "go_gc_heap_frees_bytes_total", + "/gc/heap/frees:objects": "go_gc_heap_frees_objects_total", + "/gc/heap/goal:bytes": "go_gc_heap_goal_bytes", + "/gc/heap/live:bytes": "go_gc_heap_live_bytes", + "/gc/heap/objects:objects": "go_gc_heap_objects_objects", + "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", + "/gc/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", + "/gc/pauses:seconds": "go_gc_pauses_seconds", + "/gc/scan/globals:bytes": "go_gc_scan_globals_bytes", + "/gc/scan/heap:bytes": "go_gc_scan_heap_bytes", + "/gc/scan/stack:bytes": "go_gc_scan_stack_bytes", + "/gc/scan/total:bytes": "go_gc_scan_total_bytes", + "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", + "/godebug/non-default-behavior/execerrdot:events": "go_godebug_non_default_behavior_execerrdot_events_total", + "/godebug/non-default-behavior/gocachehash:events": "go_godebug_non_default_behavior_gocachehash_events_total", + "/godebug/non-default-behavior/gocachetest:events": "go_godebug_non_default_behavior_gocachetest_events_total", + "/godebug/non-default-behavior/gocacheverify:events": "go_godebug_non_default_behavior_gocacheverify_events_total", + "/godebug/non-default-behavior/http2client:events": "go_godebug_non_default_behavior_http2client_events_total", + "/godebug/non-default-behavior/http2server:events": "go_godebug_non_default_behavior_http2server_events_total", + "/godebug/non-default-behavior/installgoroot:events": "go_godebug_non_default_behavior_installgoroot_events_total", + "/godebug/non-default-behavior/jstmpllitinterp:events": "go_godebug_non_default_behavior_jstmpllitinterp_events_total", + "/godebug/non-default-behavior/multipartmaxheaders:events": "go_godebug_non_default_behavior_multipartmaxheaders_events_total", + "/godebug/non-default-behavior/multipartmaxparts:events": "go_godebug_non_default_behavior_multipartmaxparts_events_total", + "/godebug/non-default-behavior/multipathtcp:events": "go_godebug_non_default_behavior_multipathtcp_events_total", + "/godebug/non-default-behavior/panicnil:events": "go_godebug_non_default_behavior_panicnil_events_total", + "/godebug/non-default-behavior/randautoseed:events": "go_godebug_non_default_behavior_randautoseed_events_total", + "/godebug/non-default-behavior/tarinsecurepath:events": "go_godebug_non_default_behavior_tarinsecurepath_events_total", + "/godebug/non-default-behavior/x509sha1:events": "go_godebug_non_default_behavior_x509sha1_events_total", + "/godebug/non-default-behavior/x509usefallbackroots:events": "go_godebug_non_default_behavior_x509usefallbackroots_events_total", + "/godebug/non-default-behavior/zipinsecurepath:events": "go_godebug_non_default_behavior_zipinsecurepath_events_total", + "/memory/classes/heap/free:bytes": "go_memory_classes_heap_free_bytes", + "/memory/classes/heap/objects:bytes": "go_memory_classes_heap_objects_bytes", + "/memory/classes/heap/released:bytes": "go_memory_classes_heap_released_bytes", + "/memory/classes/heap/stacks:bytes": "go_memory_classes_heap_stacks_bytes", + "/memory/classes/heap/unused:bytes": "go_memory_classes_heap_unused_bytes", + "/memory/classes/metadata/mcache/free:bytes": "go_memory_classes_metadata_mcache_free_bytes", + "/memory/classes/metadata/mcache/inuse:bytes": "go_memory_classes_metadata_mcache_inuse_bytes", + "/memory/classes/metadata/mspan/free:bytes": "go_memory_classes_metadata_mspan_free_bytes", + "/memory/classes/metadata/mspan/inuse:bytes": "go_memory_classes_metadata_mspan_inuse_bytes", + "/memory/classes/metadata/other:bytes": "go_memory_classes_metadata_other_bytes", + "/memory/classes/os-stacks:bytes": "go_memory_classes_os_stacks_bytes", + "/memory/classes/other:bytes": "go_memory_classes_other_bytes", + "/memory/classes/profiling/buckets:bytes": "go_memory_classes_profiling_buckets_bytes", + "/memory/classes/total:bytes": "go_memory_classes_total_bytes", + "/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads", + "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", + "/sched/latencies:seconds": "go_sched_latencies_seconds", + "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", +} + +const expectedRuntimeMetricsCardinality = 113