From b785d0c8289996c6529f1f58e402b77ed0b82f5c Mon Sep 17 00:00:00 2001 From: copy rogers <40619032+rogerogers@users.noreply.github.com> Date: Tue, 8 Nov 2022 03:17:41 +0800 Subject: [PATCH] Fix go_collector_latest_test Fail on go1.19 (#1136) Signed-off-by: rogerogers Signed-off-by: rogerogers --- .../collectors/go_collector_go117_test.go | 100 ++++++++++++++++ .../collectors/go_collector_go119_test.go | 107 ++++++++++++++++++ .../collectors/go_collector_latest_test.go | 91 ++------------- 3 files changed, 219 insertions(+), 79 deletions(-) create mode 100644 prometheus/collectors/go_collector_go117_test.go create mode 100644 prometheus/collectors/go_collector_go119_test.go diff --git a/prometheus/collectors/go_collector_go117_test.go b/prometheus/collectors/go_collector_go117_test.go new file mode 100644 index 0000000..370758d --- /dev/null +++ b/prometheus/collectors/go_collector_go117_test.go @@ -0,0 +1,100 @@ +// 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.17 && !go1.19 +// +build go1.17,!go1.19 + +package collectors + +func withAllMetrics() []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_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_objects_objects", + "go_gc_heap_tiny_allocs_objects_total", + "go_gc_pauses_seconds", + "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_goroutines_goroutines", + "go_sched_latencies_seconds", + }) +} + +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_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_objects_objects", + "go_gc_heap_tiny_allocs_objects_total", + "go_gc_pauses_seconds", + }) +} + +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_goroutines_goroutines", + "go_sched_latencies_seconds", + "go_threads", + } +} diff --git a/prometheus/collectors/go_collector_go119_test.go b/prometheus/collectors/go_collector_go119_test.go new file mode 100644 index 0000000..4577a21 --- /dev/null +++ b/prometheus/collectors/go_collector_go119_test.go @@ -0,0 +1,107 @@ +// 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.19 && !go1.20 +// +build go1.19,!go1.20 + +package collectors + +func withAllMetrics() []string { + return withBaseMetrics([]string{ + "go_cgo_go_to_c_calls_calls_total", + "go_gc_cycles_automatic_gc_cycles_total", + "go_gc_cycles_forced_gc_cycles_total", + "go_gc_cycles_total_gc_cycles_total", + "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_objects_objects", + "go_gc_heap_tiny_allocs_objects_total", + "go_gc_limiter_last_enabled_gc_cycle", + "go_gc_pauses_seconds", + "go_gc_stack_starting_size_bytes", + "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", + }) +} + +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_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_objects_objects", + "go_gc_heap_tiny_allocs_objects_total", + "go_gc_limiter_last_enabled_gc_cycle", + "go_gc_pauses_seconds", + "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", + } +} diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 96cdb71..8ab3b94 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -86,91 +86,24 @@ func TestGoCollectorAllowList(t *testing.T) { expected: baseMetrics, }, { - name: "allow all", - rules: []GoRuntimeMetricsRule{MetricsAll}, - expected: 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_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_objects_objects", - "go_gc_heap_tiny_allocs_objects_total", - "go_gc_pauses_seconds", - "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_goroutines_goroutines", - "go_sched_latencies_seconds", - }), + name: "allow all", + rules: []GoRuntimeMetricsRule{MetricsAll}, + expected: withAllMetrics(), }, { - name: "allow GC", - rules: []GoRuntimeMetricsRule{MetricsGC}, - expected: 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_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_objects_objects", - "go_gc_heap_tiny_allocs_objects_total", - "go_gc_pauses_seconds", - }), + name: "allow GC", + rules: []GoRuntimeMetricsRule{MetricsGC}, + expected: withGCMetrics(), }, { - name: "allow Memory", - rules: []GoRuntimeMetricsRule{MetricsMemory}, - expected: 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", - }), + name: "allow Memory", + rules: []GoRuntimeMetricsRule{MetricsMemory}, + expected: withMemoryMetrics(), }, { - name: "allow Scheduler", - rules: []GoRuntimeMetricsRule{MetricsScheduler}, - expected: []string{ - "go_gc_duration_seconds", - "go_goroutines", - "go_info", - "go_memstats_last_gc_time_seconds", - "go_sched_goroutines_goroutines", - "go_sched_latencies_seconds", - "go_threads", - }, + name: "allow Scheduler", + rules: []GoRuntimeMetricsRule{MetricsScheduler}, + expected: withSchedulerMetrics(), }, } { t.Run(test.name, func(t *testing.T) {