From 443e5b4c76e715ed389d0d8a0bec4dd3e7bb08dd Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Thu, 17 Mar 2022 11:03:12 +0100 Subject: [PATCH 1/2] Add config to test against go1.18 Signed-off-by: Kemal Akkoyun --- .circleci/config.yml | 6 +++ .github/workflows/golangci-lint.yml | 2 +- prometheus/gen_go_collector_metrics_set.go | 10 ++++- prometheus/go_collector_metrics_go118_test.go | 41 +++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 prometheus/go_collector_metrics_go118_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bb9886b5..1644f3142 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,4 +59,10 @@ workflows: name: go-1-17 go_version: "1.17" run_lint: true + - test: + name: go-1-18 + go_version: "1.18" + run_lint: true + # Style and unused/missing packages are only checked against + # the latest supported Go version. run_style_and_unused: true diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 8211b9a18..22f8204eb 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,7 +20,7 @@ jobs: - name: install Go uses: actions/setup-go@v2 with: - go-version: 1.17.x + go-version: 1.18.x - name: Lint uses: golangci/golangci-lint-action@v3.1.0 with: diff --git a/prometheus/gen_go_collector_metrics_set.go b/prometheus/gen_go_collector_metrics_set.go index e33b39749..4bc127c93 100644 --- a/prometheus/gen_go_collector_metrics_set.go +++ b/prometheus/gen_go_collector_metrics_set.go @@ -38,8 +38,10 @@ func main() { log.Fatal("requires Go version (e.g. go1.17) as an argument") } toolVersion := runtime.Version() - if majorVersion := toolVersion[:strings.LastIndexByte(toolVersion, '.')]; majorVersion != os.Args[1] { - log.Fatalf("using Go version %q but expected Go version %q", majorVersion, os.Args[1]) + mtv := majorVersion(toolVersion) + mv != majorVersion(os.Args[1]) + if mtv != mv { + log.Fatalf("using Go version %q but expected Go version %q", mtv, mv) } version, err := parseVersion(os.Args[1]) if err != nil { @@ -93,6 +95,10 @@ func parseVersion(s string) (goVersion, error) { return goVersion(i), err } +func majorVersion(v string) string { + return v[:strings.LastIndexByte(v, '.')] +} + func rmCardinality() int { cardinality := 0 diff --git a/prometheus/go_collector_metrics_go118_test.go b/prometheus/go_collector_metrics_go118_test.go new file mode 100644 index 000000000..2bcf545cd --- /dev/null +++ b/prometheus/go_collector_metrics_go118_test.go @@ -0,0 +1,41 @@ +// Code generated by gen_go_collector_metrics_set.go; DO NOT EDIT. +//go:generate go run gen_go_collector_metrics_set.go go1.18 + +//go:build go1.18 && !go1.19 +// +build go1.18,!go1.19 + +package prometheus + +var expectedRuntimeMetrics = map[string]string{ + "/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/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes_total", + "/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_total", + "/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/objects:objects": "go_gc_heap_objects_objects", + "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", + "/gc/pauses:seconds": "go_gc_pauses_seconds_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/goroutines:goroutines": "go_sched_goroutines_goroutines", + "/sched/latencies:seconds": "go_sched_latencies_seconds", +} + +const expectedRuntimeMetricsCardinality = 79 From 4f78fe2fd5444f463184980c7ba30a32148c0bb5 Mon Sep 17 00:00:00 2001 From: Kemal Akkoyun Date: Thu, 17 Mar 2022 13:48:41 +0100 Subject: [PATCH 2/2] Try to fix circleci Signed-off-by: Kemal Akkoyun --- .circleci/config.yml | 5 ++--- .github/workflows/golangci-lint.yml | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1644f3142..1525318c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,6 @@ version: 2.1 orbs: - go: circleci/go@0.2.0 + go: circleci/go@1.7.1 prometheus: prometheus/prometheus@0.16.0 jobs: test: @@ -17,8 +17,7 @@ jobs: type: boolean default: true docker: - - image: circleci/golang:<< parameters.go_version >> - working_directory: /go/src/github.com/prometheus/client_golang + - image: cimg/go:<< parameters.go_version >> steps: - checkout - when: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 22f8204eb..a4622b9aa 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -20,7 +20,8 @@ jobs: - name: install Go uses: actions/setup-go@v2 with: - go-version: 1.18.x + # golangci-lint is not read for Go 1.18 (https://github.com/golangci/golangci-lint/issues/2649) + go-version: 1.17.x - name: Lint uses: golangci/golangci-lint-action@v3.1.0 with: