Skip to content

Commit b785d0c

Browse files
authored
Fix go_collector_latest_test Fail on go1.19 (#1136)
Signed-off-by: rogerogers <[email protected]> Signed-off-by: rogerogers <[email protected]>
1 parent 4d54769 commit b785d0c

File tree

3 files changed

+219
-79
lines changed

3 files changed

+219
-79
lines changed

Diff for: prometheus/collectors/go_collector_go117_test.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.17 && !go1.19
15+
// +build go1.17,!go1.19
16+
17+
package collectors
18+
19+
func withAllMetrics() []string {
20+
return withBaseMetrics([]string{
21+
"go_gc_cycles_automatic_gc_cycles_total",
22+
"go_gc_cycles_forced_gc_cycles_total",
23+
"go_gc_cycles_total_gc_cycles_total",
24+
"go_gc_heap_allocs_by_size_bytes",
25+
"go_gc_heap_allocs_bytes_total",
26+
"go_gc_heap_allocs_objects_total",
27+
"go_gc_heap_frees_by_size_bytes",
28+
"go_gc_heap_frees_bytes_total",
29+
"go_gc_heap_frees_objects_total",
30+
"go_gc_heap_goal_bytes",
31+
"go_gc_heap_objects_objects",
32+
"go_gc_heap_tiny_allocs_objects_total",
33+
"go_gc_pauses_seconds",
34+
"go_memory_classes_heap_free_bytes",
35+
"go_memory_classes_heap_objects_bytes",
36+
"go_memory_classes_heap_released_bytes",
37+
"go_memory_classes_heap_stacks_bytes",
38+
"go_memory_classes_heap_unused_bytes",
39+
"go_memory_classes_metadata_mcache_free_bytes",
40+
"go_memory_classes_metadata_mcache_inuse_bytes",
41+
"go_memory_classes_metadata_mspan_free_bytes",
42+
"go_memory_classes_metadata_mspan_inuse_bytes",
43+
"go_memory_classes_metadata_other_bytes",
44+
"go_memory_classes_os_stacks_bytes",
45+
"go_memory_classes_other_bytes",
46+
"go_memory_classes_profiling_buckets_bytes",
47+
"go_memory_classes_total_bytes",
48+
"go_sched_goroutines_goroutines",
49+
"go_sched_latencies_seconds",
50+
})
51+
}
52+
53+
func withGCMetrics() []string {
54+
return withBaseMetrics([]string{
55+
"go_gc_cycles_automatic_gc_cycles_total",
56+
"go_gc_cycles_forced_gc_cycles_total",
57+
"go_gc_cycles_total_gc_cycles_total",
58+
"go_gc_heap_allocs_by_size_bytes",
59+
"go_gc_heap_allocs_bytes_total",
60+
"go_gc_heap_allocs_objects_total",
61+
"go_gc_heap_frees_by_size_bytes",
62+
"go_gc_heap_frees_bytes_total",
63+
"go_gc_heap_frees_objects_total",
64+
"go_gc_heap_goal_bytes",
65+
"go_gc_heap_objects_objects",
66+
"go_gc_heap_tiny_allocs_objects_total",
67+
"go_gc_pauses_seconds",
68+
})
69+
}
70+
71+
func withMemoryMetrics() []string {
72+
return withBaseMetrics([]string{
73+
"go_memory_classes_heap_free_bytes",
74+
"go_memory_classes_heap_objects_bytes",
75+
"go_memory_classes_heap_released_bytes",
76+
"go_memory_classes_heap_stacks_bytes",
77+
"go_memory_classes_heap_unused_bytes",
78+
"go_memory_classes_metadata_mcache_free_bytes",
79+
"go_memory_classes_metadata_mcache_inuse_bytes",
80+
"go_memory_classes_metadata_mspan_free_bytes",
81+
"go_memory_classes_metadata_mspan_inuse_bytes",
82+
"go_memory_classes_metadata_other_bytes",
83+
"go_memory_classes_os_stacks_bytes",
84+
"go_memory_classes_other_bytes",
85+
"go_memory_classes_profiling_buckets_bytes",
86+
"go_memory_classes_total_bytes",
87+
})
88+
}
89+
90+
func withSchedulerMetrics() []string {
91+
return []string{
92+
"go_gc_duration_seconds",
93+
"go_goroutines",
94+
"go_info",
95+
"go_memstats_last_gc_time_seconds",
96+
"go_sched_goroutines_goroutines",
97+
"go_sched_latencies_seconds",
98+
"go_threads",
99+
}
100+
}

Diff for: prometheus/collectors/go_collector_go119_test.go

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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.19 && !go1.20
15+
// +build go1.19,!go1.20
16+
17+
package collectors
18+
19+
func withAllMetrics() []string {
20+
return withBaseMetrics([]string{
21+
"go_cgo_go_to_c_calls_calls_total",
22+
"go_gc_cycles_automatic_gc_cycles_total",
23+
"go_gc_cycles_forced_gc_cycles_total",
24+
"go_gc_cycles_total_gc_cycles_total",
25+
"go_gc_heap_allocs_by_size_bytes",
26+
"go_gc_heap_allocs_bytes_total",
27+
"go_gc_heap_allocs_objects_total",
28+
"go_gc_heap_frees_by_size_bytes",
29+
"go_gc_heap_frees_bytes_total",
30+
"go_gc_heap_frees_objects_total",
31+
"go_gc_heap_goal_bytes",
32+
"go_gc_heap_objects_objects",
33+
"go_gc_heap_tiny_allocs_objects_total",
34+
"go_gc_limiter_last_enabled_gc_cycle",
35+
"go_gc_pauses_seconds",
36+
"go_gc_stack_starting_size_bytes",
37+
"go_memory_classes_heap_free_bytes",
38+
"go_memory_classes_heap_objects_bytes",
39+
"go_memory_classes_heap_released_bytes",
40+
"go_memory_classes_heap_stacks_bytes",
41+
"go_memory_classes_heap_unused_bytes",
42+
"go_memory_classes_metadata_mcache_free_bytes",
43+
"go_memory_classes_metadata_mcache_inuse_bytes",
44+
"go_memory_classes_metadata_mspan_free_bytes",
45+
"go_memory_classes_metadata_mspan_inuse_bytes",
46+
"go_memory_classes_metadata_other_bytes",
47+
"go_memory_classes_os_stacks_bytes",
48+
"go_memory_classes_other_bytes",
49+
"go_memory_classes_profiling_buckets_bytes",
50+
"go_memory_classes_total_bytes",
51+
"go_sched_gomaxprocs_threads",
52+
"go_sched_goroutines_goroutines",
53+
"go_sched_latencies_seconds",
54+
})
55+
}
56+
57+
func withGCMetrics() []string {
58+
return withBaseMetrics([]string{
59+
"go_gc_cycles_automatic_gc_cycles_total",
60+
"go_gc_cycles_forced_gc_cycles_total",
61+
"go_gc_cycles_total_gc_cycles_total",
62+
"go_gc_heap_allocs_by_size_bytes",
63+
"go_gc_heap_allocs_bytes_total",
64+
"go_gc_heap_allocs_objects_total",
65+
"go_gc_heap_frees_by_size_bytes",
66+
"go_gc_heap_frees_bytes_total",
67+
"go_gc_heap_frees_objects_total",
68+
"go_gc_heap_goal_bytes",
69+
"go_gc_heap_objects_objects",
70+
"go_gc_heap_tiny_allocs_objects_total",
71+
"go_gc_limiter_last_enabled_gc_cycle",
72+
"go_gc_pauses_seconds",
73+
"go_gc_stack_starting_size_bytes",
74+
})
75+
}
76+
77+
func withMemoryMetrics() []string {
78+
return withBaseMetrics([]string{
79+
"go_memory_classes_heap_free_bytes",
80+
"go_memory_classes_heap_objects_bytes",
81+
"go_memory_classes_heap_released_bytes",
82+
"go_memory_classes_heap_stacks_bytes",
83+
"go_memory_classes_heap_unused_bytes",
84+
"go_memory_classes_metadata_mcache_free_bytes",
85+
"go_memory_classes_metadata_mcache_inuse_bytes",
86+
"go_memory_classes_metadata_mspan_free_bytes",
87+
"go_memory_classes_metadata_mspan_inuse_bytes",
88+
"go_memory_classes_metadata_other_bytes",
89+
"go_memory_classes_os_stacks_bytes",
90+
"go_memory_classes_other_bytes",
91+
"go_memory_classes_profiling_buckets_bytes",
92+
"go_memory_classes_total_bytes",
93+
})
94+
}
95+
96+
func withSchedulerMetrics() []string {
97+
return []string{
98+
"go_gc_duration_seconds",
99+
"go_goroutines",
100+
"go_info",
101+
"go_memstats_last_gc_time_seconds",
102+
"go_sched_gomaxprocs_threads",
103+
"go_sched_goroutines_goroutines",
104+
"go_sched_latencies_seconds",
105+
"go_threads",
106+
}
107+
}

Diff for: prometheus/collectors/go_collector_latest_test.go

+12-79
Original file line numberDiff line numberDiff line change
@@ -86,91 +86,24 @@ func TestGoCollectorAllowList(t *testing.T) {
8686
expected: baseMetrics,
8787
},
8888
{
89-
name: "allow all",
90-
rules: []GoRuntimeMetricsRule{MetricsAll},
91-
expected: withBaseMetrics([]string{
92-
"go_gc_cycles_automatic_gc_cycles_total",
93-
"go_gc_cycles_forced_gc_cycles_total",
94-
"go_gc_cycles_total_gc_cycles_total",
95-
"go_gc_heap_allocs_by_size_bytes",
96-
"go_gc_heap_allocs_bytes_total",
97-
"go_gc_heap_allocs_objects_total",
98-
"go_gc_heap_frees_by_size_bytes",
99-
"go_gc_heap_frees_bytes_total",
100-
"go_gc_heap_frees_objects_total",
101-
"go_gc_heap_goal_bytes",
102-
"go_gc_heap_objects_objects",
103-
"go_gc_heap_tiny_allocs_objects_total",
104-
"go_gc_pauses_seconds",
105-
"go_memory_classes_heap_free_bytes",
106-
"go_memory_classes_heap_objects_bytes",
107-
"go_memory_classes_heap_released_bytes",
108-
"go_memory_classes_heap_stacks_bytes",
109-
"go_memory_classes_heap_unused_bytes",
110-
"go_memory_classes_metadata_mcache_free_bytes",
111-
"go_memory_classes_metadata_mcache_inuse_bytes",
112-
"go_memory_classes_metadata_mspan_free_bytes",
113-
"go_memory_classes_metadata_mspan_inuse_bytes",
114-
"go_memory_classes_metadata_other_bytes",
115-
"go_memory_classes_os_stacks_bytes",
116-
"go_memory_classes_other_bytes",
117-
"go_memory_classes_profiling_buckets_bytes",
118-
"go_memory_classes_total_bytes",
119-
"go_sched_goroutines_goroutines",
120-
"go_sched_latencies_seconds",
121-
}),
89+
name: "allow all",
90+
rules: []GoRuntimeMetricsRule{MetricsAll},
91+
expected: withAllMetrics(),
12292
},
12393
{
124-
name: "allow GC",
125-
rules: []GoRuntimeMetricsRule{MetricsGC},
126-
expected: withBaseMetrics([]string{
127-
"go_gc_cycles_automatic_gc_cycles_total",
128-
"go_gc_cycles_forced_gc_cycles_total",
129-
"go_gc_cycles_total_gc_cycles_total",
130-
"go_gc_heap_allocs_by_size_bytes",
131-
"go_gc_heap_allocs_bytes_total",
132-
"go_gc_heap_allocs_objects_total",
133-
"go_gc_heap_frees_by_size_bytes",
134-
"go_gc_heap_frees_bytes_total",
135-
"go_gc_heap_frees_objects_total",
136-
"go_gc_heap_goal_bytes",
137-
"go_gc_heap_objects_objects",
138-
"go_gc_heap_tiny_allocs_objects_total",
139-
"go_gc_pauses_seconds",
140-
}),
94+
name: "allow GC",
95+
rules: []GoRuntimeMetricsRule{MetricsGC},
96+
expected: withGCMetrics(),
14197
},
14298
{
143-
name: "allow Memory",
144-
rules: []GoRuntimeMetricsRule{MetricsMemory},
145-
expected: withBaseMetrics([]string{
146-
"go_memory_classes_heap_free_bytes",
147-
"go_memory_classes_heap_objects_bytes",
148-
"go_memory_classes_heap_released_bytes",
149-
"go_memory_classes_heap_stacks_bytes",
150-
"go_memory_classes_heap_unused_bytes",
151-
"go_memory_classes_metadata_mcache_free_bytes",
152-
"go_memory_classes_metadata_mcache_inuse_bytes",
153-
"go_memory_classes_metadata_mspan_free_bytes",
154-
"go_memory_classes_metadata_mspan_inuse_bytes",
155-
"go_memory_classes_metadata_other_bytes",
156-
"go_memory_classes_os_stacks_bytes",
157-
"go_memory_classes_other_bytes",
158-
"go_memory_classes_profiling_buckets_bytes",
159-
"go_memory_classes_total_bytes",
160-
}),
99+
name: "allow Memory",
100+
rules: []GoRuntimeMetricsRule{MetricsMemory},
101+
expected: withMemoryMetrics(),
161102
},
162103
{
163-
name: "allow Scheduler",
164-
rules: []GoRuntimeMetricsRule{MetricsScheduler},
165-
expected: []string{
166-
"go_gc_duration_seconds",
167-
"go_goroutines",
168-
"go_info",
169-
"go_memstats_last_gc_time_seconds",
170-
"go_sched_goroutines_goroutines",
171-
"go_sched_latencies_seconds",
172-
"go_threads",
173-
},
104+
name: "allow Scheduler",
105+
rules: []GoRuntimeMetricsRule{MetricsScheduler},
106+
expected: withSchedulerMetrics(),
174107
},
175108
} {
176109
t.Run(test.name, func(t *testing.T) {

0 commit comments

Comments
 (0)