Addressed comments on Arianna's PR.

Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
bwplotka 2024-08-09 11:14:57 +01:00
parent b8a9eb7b75
commit 23879d69c3
8 changed files with 264 additions and 261 deletions

View File

@ -63,14 +63,27 @@ func main() {
v := goVersion(gv.Segments()[1])
log.Printf("generating metrics for Go version %q", v)
allDesc := metrics.All()
// Find default metrics.
var defaultDesc []metrics.Description
for _, d := range allDesc {
if !internal.GoCollectorDefaultRuntimeMetrics.MatchString(d.Name) {
continue
}
defaultDesc = append(defaultDesc, d)
}
// Generate code.
var buf bytes.Buffer
err = testFile.Execute(&buf, struct {
Descriptions []metrics.Description
AllDescriptions []metrics.Description
DefaultDescriptions []metrics.Description
GoVersion goVersion
Cardinality int
}{
Descriptions: metrics.All(),
AllDescriptions: allDesc,
DefaultDescriptions: defaultDesc,
GoVersion: v,
Cardinality: rmCardinality(),
})
@ -167,8 +180,9 @@ var testFile = template.Must(template.New("testFile").Funcs(map[string]interface
package prometheus
var expectedRuntimeMetrics = map[string]string{
{{- range .Descriptions -}}
var (
expectedRuntimeMetrics = map[string]string{
{{- range .AllDescriptions -}}
{{- $trans := rm2prom . -}}
{{- if ne $trans "" }}
{{.Name | printf "%q"}}: {{$trans | printf "%q"}},
@ -176,5 +190,15 @@ var expectedRuntimeMetrics = map[string]string{
{{end}}
}
expMetrics = map[string]string{
{{- range .DefaultDescriptions -}}
{{- $trans := rm2prom . -}}
{{- if ne $trans "" }}
{{.Name | printf "%q"}}: {{$trans | printf "%q"}},
{{- end -}}
{{end}}
}
)
const expectedRuntimeMetricsCardinality = {{.Cardinality}}
`))

View File

@ -19,7 +19,6 @@ package prometheus
import (
"fmt"
"math"
"regexp"
"runtime"
"runtime/metrics"
"strings"
@ -155,9 +154,8 @@ func defaultGoCollectorOptions() internal.GoCollectorOptions {
"/gc/heap/frees-by-size:bytes": goGCHeapFreesBytes,
},
RuntimeMetricRules: []internal.GoCollectorRule{
{
Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`),
},
// Recommended metrics we want by default from runtime/metrics.
{Matcher: internal.GoCollectorDefaultRuntimeMetrics},
},
}
}

View File

@ -1,21 +0,0 @@
// Copyright 2024 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
// +build !go1.21
package prometheus
var expMetrics = map[string]string{
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads",
}

View File

@ -1,23 +0,0 @@
// Copyright 2024 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
// +build go1.21
package prometheus
var expMetrics = map[string]string{
"/gc/gogc:percent": "go_gc_gogc_percent",
"/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes",
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads",
}

View File

@ -6,7 +6,8 @@
package prometheus
var expectedRuntimeMetrics = map[string]string{
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",
@ -54,4 +55,9 @@ var expectedRuntimeMetrics = map[string]string{
"/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total",
}
expMetrics = map[string]string{
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads",
}
)
const expectedRuntimeMetricsCardinality = 89

View File

@ -6,7 +6,8 @@
package prometheus
var expectedRuntimeMetrics = map[string]string{
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",
@ -52,6 +53,7 @@ var expectedRuntimeMetrics = map[string]string{
"/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/netedns0:events": "go_godebug_non_default_behavior_netedns0_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",
@ -79,4 +81,11 @@ var expectedRuntimeMetrics = map[string]string{
"/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total",
}
const expectedRuntimeMetricsCardinality = 114
expMetrics = map[string]string{
"/gc/gogc:percent": "go_gc_gogc_percent",
"/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes",
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads",
}
)
const expectedRuntimeMetricsCardinality = 115

View File

@ -6,7 +6,8 @@
package prometheus
var expectedRuntimeMetrics = map[string]string{
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",
@ -91,4 +92,11 @@ var expectedRuntimeMetrics = map[string]string{
"/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total",
}
expMetrics = map[string]string{
"/gc/gogc:percent": "go_gc_gogc_percent",
"/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes",
"/sched/gomaxprocs:threads": "go_sched_gomaxprocs_threads",
}
)
const expectedRuntimeMetricsCardinality = 162

View File

@ -30,3 +30,5 @@ type GoCollectorOptions struct {
RuntimeMetricSumForHist map[string]string
RuntimeMetricRules []GoCollectorRule
}
var GoCollectorDefaultRuntimeMetrics = regexp.MustCompile(`/gc/gogc:percent|/gc/gomemlimit:bytes|/sched/gomaxprocs:threads`)