Skip to content

Commit 232b949

Browse files
authored
Added support for go 1.20. (#1234)
Signed-off-by: bwplotka <[email protected]>
1 parent 3726cdd commit 232b949

File tree

7 files changed

+187
-7
lines changed

7 files changed

+187
-7
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ workflows:
4646
client_golang:
4747
jobs:
4848
# Refer to README.md for the currently supported versions.
49-
- test:
50-
name: go-1-17
51-
go_version: "1.17"
52-
run_lint: true
5349
- test:
5450
name: go-1-18
5551
go_version: "1.18"
@@ -58,6 +54,10 @@ workflows:
5854
name: go-1-19
5955
go_version: "1.19"
6056
run_lint: true
57+
- test:
58+
name: go-1-20
59+
go_version: "1.20"
60+
run_lint: true
6161
# Style and unused/missing packages are only checked against
6262
# the latest supported Go version.
6363
run_style_and_unused: true

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test: deps common-test
2020
test-short: deps common-test-short
2121

2222
.PHONY: generate-go-collector-test-files
23-
VERSIONS := 1.17 1.18 1.19
23+
VERSIONS := 1.17 1.18 1.19 1.20
2424
generate-go-collector-test-files:
2525
for GO_VERSION in $(VERSIONS); do \
2626
docker run --rm -v $(PWD):/workspace -w /workspace golang:$$GO_VERSION go run prometheus/gen_go_collector_metrics_set.go; \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This is the [Go](http://golang.org) client library for
1010
instrumenting application code, and one for creating clients that talk to the
1111
Prometheus HTTP API.
1212

13-
__This library requires Go1.17 or later.__
13+
__This library requires Go1.18 or later.__
1414

1515
## Important note about releases and stability
1616

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.20 && !go1.21
15+
// +build go1.20,!go1.21
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_cpu_classes_gc_mark_assist_cpu_seconds_total",
26+
"go_cpu_classes_gc_mark_dedicated_cpu_seconds_total",
27+
"go_cpu_classes_gc_mark_idle_cpu_seconds_total",
28+
"go_cpu_classes_gc_pause_cpu_seconds_total",
29+
"go_cpu_classes_gc_total_cpu_seconds_total",
30+
"go_cpu_classes_idle_cpu_seconds_total",
31+
"go_cpu_classes_scavenge_assist_cpu_seconds_total",
32+
"go_cpu_classes_scavenge_background_cpu_seconds_total",
33+
"go_cpu_classes_scavenge_total_cpu_seconds_total",
34+
"go_cpu_classes_total_cpu_seconds_total",
35+
"go_cpu_classes_user_cpu_seconds_total",
36+
"go_gc_heap_allocs_by_size_bytes",
37+
"go_gc_heap_allocs_bytes_total",
38+
"go_gc_heap_allocs_objects_total",
39+
"go_gc_heap_frees_by_size_bytes",
40+
"go_gc_heap_frees_bytes_total",
41+
"go_gc_heap_frees_objects_total",
42+
"go_gc_heap_goal_bytes",
43+
"go_gc_heap_objects_objects",
44+
"go_gc_heap_tiny_allocs_objects_total",
45+
"go_gc_limiter_last_enabled_gc_cycle",
46+
"go_gc_pauses_seconds",
47+
"go_gc_stack_starting_size_bytes",
48+
"go_memory_classes_heap_free_bytes",
49+
"go_memory_classes_heap_objects_bytes",
50+
"go_memory_classes_heap_released_bytes",
51+
"go_memory_classes_heap_stacks_bytes",
52+
"go_memory_classes_heap_unused_bytes",
53+
"go_memory_classes_metadata_mcache_free_bytes",
54+
"go_memory_classes_metadata_mcache_inuse_bytes",
55+
"go_memory_classes_metadata_mspan_free_bytes",
56+
"go_memory_classes_metadata_mspan_inuse_bytes",
57+
"go_memory_classes_metadata_other_bytes",
58+
"go_memory_classes_os_stacks_bytes",
59+
"go_memory_classes_other_bytes",
60+
"go_memory_classes_profiling_buckets_bytes",
61+
"go_memory_classes_total_bytes",
62+
"go_sched_gomaxprocs_threads",
63+
"go_sched_goroutines_goroutines",
64+
"go_sched_latencies_seconds",
65+
"go_sync_mutex_wait_total_seconds_total",
66+
})
67+
}
68+
69+
func withGCMetrics() []string {
70+
return withBaseMetrics([]string{
71+
"go_gc_cycles_automatic_gc_cycles_total",
72+
"go_gc_cycles_forced_gc_cycles_total",
73+
"go_gc_cycles_total_gc_cycles_total",
74+
"go_gc_heap_allocs_by_size_bytes",
75+
"go_gc_heap_allocs_bytes_total",
76+
"go_gc_heap_allocs_objects_total",
77+
"go_gc_heap_frees_by_size_bytes",
78+
"go_gc_heap_frees_bytes_total",
79+
"go_gc_heap_frees_objects_total",
80+
"go_gc_heap_goal_bytes",
81+
"go_gc_heap_objects_objects",
82+
"go_gc_heap_tiny_allocs_objects_total",
83+
"go_gc_limiter_last_enabled_gc_cycle",
84+
"go_gc_pauses_seconds",
85+
"go_gc_stack_starting_size_bytes",
86+
})
87+
}
88+
89+
func withMemoryMetrics() []string {
90+
return withBaseMetrics([]string{
91+
"go_memory_classes_heap_free_bytes",
92+
"go_memory_classes_heap_objects_bytes",
93+
"go_memory_classes_heap_released_bytes",
94+
"go_memory_classes_heap_stacks_bytes",
95+
"go_memory_classes_heap_unused_bytes",
96+
"go_memory_classes_metadata_mcache_free_bytes",
97+
"go_memory_classes_metadata_mcache_inuse_bytes",
98+
"go_memory_classes_metadata_mspan_free_bytes",
99+
"go_memory_classes_metadata_mspan_inuse_bytes",
100+
"go_memory_classes_metadata_other_bytes",
101+
"go_memory_classes_os_stacks_bytes",
102+
"go_memory_classes_other_bytes",
103+
"go_memory_classes_profiling_buckets_bytes",
104+
"go_memory_classes_total_bytes",
105+
})
106+
}
107+
108+
func withSchedulerMetrics() []string {
109+
return []string{
110+
"go_gc_duration_seconds",
111+
"go_goroutines",
112+
"go_info",
113+
"go_memstats_last_gc_time_seconds",
114+
"go_sched_gomaxprocs_threads",
115+
"go_sched_goroutines_goroutines",
116+
"go_sched_latencies_seconds",
117+
"go_threads",
118+
}
119+
}

prometheus/collectors/go_collector_latest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ var (
2828
MetricsAll = GoRuntimeMetricsRule{regexp.MustCompile("/.*")}
2929
// MetricsGC allows only GC metrics to be collected from Go runtime.
3030
// e.g. go_gc_cycles_automatic_gc_cycles_total
31+
// NOTE: This does not include new class of "/cpu/classes/gc/..." metrics.
32+
// Use custom metric rule to access those.
3133
MetricsGC = GoRuntimeMetricsRule{regexp.MustCompile(`^/gc/.*`)}
3234
// MetricsMemory allows only memory metrics to be collected from Go runtime.
3335
// e.g. go_memory_classes_heap_free_bytes

prometheus/gen_go_collector_metrics_set.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ func main() {
5050
if err != nil {
5151
log.Fatal(err)
5252
}
53-
gv, err := version.NewVersion(strings.TrimPrefix(toolVersion, "go"))
53+
54+
toolVersion = strings.Split(strings.TrimPrefix(toolVersion, "go"), " ")[0]
55+
gv, err := version.NewVersion(toolVersion)
5456
if err != nil {
5557
log.Fatal(err)
5658
}

prometheus/go_collector_metrics_go120_test.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)