From cd8445b70b627d5f5e91e44d13106a224fb39d09 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Thu, 11 Jul 2024 16:36:45 +0200 Subject: [PATCH 01/13] Add go_gomaxprocs, go_gogc_percent and go_gomemlimit to the default Go runtime metrics Signed-off-by: Arianna Vespri --- go.mod | 1 + go.sum | 2 ++ .../collectors/go_collector_latest_test.go | 3 ++ prometheus/go_collector.go | 31 +++++++++++++++++++ prometheus/go_collector_latest_test.go | 3 ++ 5 files changed, 40 insertions(+) diff --git a/go.mod b/go.mod index 60f8dc1d8..afe7cd144 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( require ( github.com/golang/protobuf v1.5.3 // indirect + github.com/hashicorp/go-version v1.7.0 github.com/jpillora/backoff v1.0.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 743a74f53..1d048bdbf 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= +github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 76673f367..da2e89f94 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -31,6 +31,9 @@ import ( var baseMetrics = []string{ "go_gc_duration_seconds", + "go_gogc_percent", + "go_gomaxprocs", + "go_gomemlimit", "go_goroutines", "go_info", "go_memstats_last_gc_time_seconds", diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index ad9a71a5e..289a37def 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -16,6 +16,7 @@ package prometheus import ( "runtime" "runtime/debug" + runmetr "runtime/metrics" "time" ) @@ -211,6 +212,9 @@ type baseGoCollector struct { gcDesc *Desc gcLastTimeDesc *Desc goInfoDesc *Desc + goMaxProcs *Desc + goGogcPercent *Desc + goMemLimit *Desc } func newBaseGoCollector() baseGoCollector { @@ -235,6 +239,18 @@ func newBaseGoCollector() baseGoCollector { "go_info", "Information about the Go environment.", nil, Labels{"version": runtime.Version()}), + goMaxProcs: NewDesc( + "go_gomaxprocs", + "Value of GOMAXPROCS, i.e number of usable threads.", + nil, nil), + goGogcPercent: NewDesc( + "go_gogc_percent", + "Value of GOGC (percentage).", + nil, nil), + goMemLimit: NewDesc( + "go_gomemlimit", + "Value of GOMEMLIMIT (bytes).", + nil, nil), } } @@ -245,6 +261,9 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) { ch <- c.gcDesc ch <- c.gcLastTimeDesc ch <- c.goInfoDesc + ch <- c.goMaxProcs + ch <- c.goGogcPercent + ch <- c.goMemLimit } // Collect returns the current state of all metrics of the collector. @@ -266,6 +285,18 @@ func (c *baseGoCollector) Collect(ch chan<- Metric) { ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles) ch <- MustNewConstMetric(c.gcLastTimeDesc, GaugeValue, float64(stats.LastGC.UnixNano())/1e9) ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1) + ch <- MustNewConstMetric(c.goMaxProcs, GaugeValue, float64(runtime.NumCPU())) + + gogcSample := make([]runmetr.Sample, 1) + gogcSample[0].Name = "/gc/gogc:percent" + runmetr.Read(gogcSample) + ch <- MustNewConstMetric(c.goGogcPercent, GaugeValue, float64(gogcSample[0].Value.Uint64())) + + memLimitSample := make([]runmetr.Sample, 1) + memLimitSample[0].Name = "/gc/gomemlimit:bytes" + runmetr.Read(memLimitSample) + ch <- MustNewConstMetric(c.goMemLimit, GaugeValue, float64(memLimitSample[0].Value.Uint64())) + } func memstatNamespace(s string) string { diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index 551f49797..f2a31770c 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -54,6 +54,9 @@ func expectedBaseMetrics() map[string]struct{} { b.goroutinesDesc.fqName, b.gcLastTimeDesc.fqName, b.threadsDesc.fqName, + b.goMaxProcs.fqName, + b.goGogcPercent.fqName, + b.goMemLimit.fqName, } { metrics[m] = struct{}{} } From 5d64fb76250bccb4897c3f44d2d0dc57c31ef590 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 19 Jul 2024 15:14:03 +0200 Subject: [PATCH 02/13] Move newly added metrics out of base metrics and into goCollector Signed-off-by: Arianna Vespri --- prometheus/collectors/go_collector_latest.go | 6 ++ .../collectors/go_collector_latest_test.go | 3 - prometheus/go_collector.go | 75 +++++++++++-------- prometheus/go_collector_latest.go | 49 +++++++++--- prometheus/go_collector_latest_test.go | 3 - prometheus/internal/go_collector_options.go | 7 +- 6 files changed, 94 insertions(+), 49 deletions(-) diff --git a/prometheus/collectors/go_collector_latest.go b/prometheus/collectors/go_collector_latest.go index 771a72a90..f3179f35c 100644 --- a/prometheus/collectors/go_collector_latest.go +++ b/prometheus/collectors/go_collector_latest.go @@ -88,6 +88,12 @@ func WithGoCollectorMemStatsMetricsDisabled() func(options *internal.GoCollector } } +func WithGoCollectorRuntimeEnvVarsMetricsDisabled() func(options *internal.GoCollectorOptions) { + return func(o *internal.GoCollectorOptions) { + o.DisableRuntimeEnvVarsMetrics = true + } +} + // GoRuntimeMetricsRule allow enabling and configuring particular group of runtime/metrics. // TODO(bwplotka): Consider adding ability to adjust buckets. type GoRuntimeMetricsRule struct { diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index da2e89f94..76673f367 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -31,9 +31,6 @@ import ( var baseMetrics = []string{ "go_gc_duration_seconds", - "go_gogc_percent", - "go_gomaxprocs", - "go_gomemlimit", "go_goroutines", "go_info", "go_memstats_last_gc_time_seconds", diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index 289a37def..1d6303cc7 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -212,9 +212,6 @@ type baseGoCollector struct { gcDesc *Desc gcLastTimeDesc *Desc goInfoDesc *Desc - goMaxProcs *Desc - goGogcPercent *Desc - goMemLimit *Desc } func newBaseGoCollector() baseGoCollector { @@ -239,18 +236,6 @@ func newBaseGoCollector() baseGoCollector { "go_info", "Information about the Go environment.", nil, Labels{"version": runtime.Version()}), - goMaxProcs: NewDesc( - "go_gomaxprocs", - "Value of GOMAXPROCS, i.e number of usable threads.", - nil, nil), - goGogcPercent: NewDesc( - "go_gogc_percent", - "Value of GOGC (percentage).", - nil, nil), - goMemLimit: NewDesc( - "go_gomemlimit", - "Value of GOMEMLIMIT (bytes).", - nil, nil), } } @@ -261,9 +246,6 @@ func (c *baseGoCollector) Describe(ch chan<- *Desc) { ch <- c.gcDesc ch <- c.gcLastTimeDesc ch <- c.goInfoDesc - ch <- c.goMaxProcs - ch <- c.goGogcPercent - ch <- c.goMemLimit } // Collect returns the current state of all metrics of the collector. @@ -285,18 +267,6 @@ func (c *baseGoCollector) Collect(ch chan<- Metric) { ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles) ch <- MustNewConstMetric(c.gcLastTimeDesc, GaugeValue, float64(stats.LastGC.UnixNano())/1e9) ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1) - ch <- MustNewConstMetric(c.goMaxProcs, GaugeValue, float64(runtime.NumCPU())) - - gogcSample := make([]runmetr.Sample, 1) - gogcSample[0].Name = "/gc/gogc:percent" - runmetr.Read(gogcSample) - ch <- MustNewConstMetric(c.goGogcPercent, GaugeValue, float64(gogcSample[0].Value.Uint64())) - - memLimitSample := make([]runmetr.Sample, 1) - memLimitSample[0].Name = "/gc/gomemlimit:bytes" - runmetr.Read(memLimitSample) - ch <- MustNewConstMetric(c.goMemLimit, GaugeValue, float64(memLimitSample[0].Value.Uint64())) - } func memstatNamespace(s string) string { @@ -310,3 +280,48 @@ type memStatsMetrics []struct { eval func(*runtime.MemStats) float64 valType ValueType } + +func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { + return runtimeEnvVarsMetrics{ + { + desc: NewDesc( + "go_gogc_percent", + "Value of GOGC (percentage).", + nil, nil, + ), + eval: float64(readRunMetrSample("/gc/gogc:percent")[0].Value.Uint64()), + valType: GaugeValue, + }, + { + desc: NewDesc( + "go_gomemlimit", + "Value of GOMEMLIMIT (bytes).", + nil, nil, + ), + eval: float64(readRunMetrSample("/gc/gomemlimit:bytes")[0].Value.Uint64()), + valType: GaugeValue, + }, + { + desc: NewDesc( + "go_gomaxprocs", + "Value of GOMAXPROCS, i.e number of usable threads.", + nil, nil, + ), + eval: float64(runtime.NumCPU()), + valType: GaugeValue, + }, + } +} + +type runtimeEnvVarsMetrics []struct { // how to call this struct? + desc *Desc + eval float64 + valType ValueType +} + +func readRunMetrSample(metricName string) []runmetr.Sample { + sample := make([]runmetr.Sample, 1) + sample[0].Name = metricName + runmetr.Read(sample) + return sample +} diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 2d8d9f64f..c42420ba0 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -31,6 +31,7 @@ import ( const ( // constants for strings referenced more than once. + goGCGogcPercent = "/gc/gogc:percent" goGCHeapTinyAllocsObjects = "/gc/heap/tiny/allocs:objects" goGCHeapAllocsObjects = "/gc/heap/allocs:objects" goGCHeapFreesObjects = "/gc/heap/frees:objects" @@ -38,6 +39,7 @@ const ( goGCHeapAllocsBytes = "/gc/heap/allocs:bytes" goGCHeapObjects = "/gc/heap/objects:objects" goGCHeapGoalBytes = "/gc/heap/goal:bytes" + goGCMemLimit = "/gc/gomemlimit:bytes" goMemoryClassesTotalBytes = "/memory/classes/total:bytes" goMemoryClassesHeapObjectsBytes = "/memory/classes/heap/objects:bytes" goMemoryClassesHeapUnusedBytes = "/memory/classes/heap/unused:bytes" @@ -52,6 +54,7 @@ const ( goMemoryClassesProfilingBucketsBytes = "/memory/classes/profiling/buckets:bytes" goMemoryClassesMetadataOtherBytes = "/memory/classes/metadata/other:bytes" goMemoryClassesOtherBytes = "/memory/classes/other:bytes" + goSchedMaxProcs = "/sched/gomaxprocs:threads" ) // rmNamesForMemStatsMetrics represents runtime/metrics names required to populate goRuntimeMemStats from like logic. @@ -78,6 +81,12 @@ var rmNamesForMemStatsMetrics = []string{ goMemoryClassesOtherBytes, } +var rmNamesForEnvVarsMetrics = []string{ // how to call them??? + goGCGogcPercent, + goGCMemLimit, + goSchedMaxProcs, +} + func bestEffortLookupRM(lookup []string) []metrics.Description { ret := make([]metrics.Description, 0, len(lookup)) for _, rm := range metrics.All() { @@ -116,6 +125,9 @@ type goCollector struct { // as well. msMetrics memStatsMetrics msMetricsEnabled bool + + rmEnvVarMetrics runtimeEnvVarsMetrics // how to call them??? + rmEnvVarMetricsEnabled bool } type rmMetricDesc struct { @@ -193,7 +205,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { metricSet := make([]collectorMetric, 0, len(exposedDescriptions)) // SampleBuf is used for reading from runtime/metrics. // We are assuming the largest case to have stable pointers for sampleMap purposes. - sampleBuf := make([]metrics.Sample, 0, len(exposedDescriptions)+len(opt.RuntimeMetricSumForHist)+len(rmNamesForMemStatsMetrics)) + sampleBuf := make([]metrics.Sample, 0, len(exposedDescriptions)+len(opt.RuntimeMetricSumForHist)+len(rmNamesForMemStatsMetrics)+len(rmNamesForEnvVarsMetrics)) sampleMap := make(map[string]*metrics.Sample, len(exposedDescriptions)) for _, d := range exposedDescriptions { namespace, subsystem, name, ok := internal.RuntimeMetricsToProm(&d.Description) @@ -255,8 +267,10 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } var ( - msMetrics memStatsMetrics - msDescriptions []metrics.Description + msMetrics memStatsMetrics + msDescriptions []metrics.Description + rmEnvVarMetrics runtimeEnvVarsMetrics + rmEnvVarsDescriptions []metrics.Description ) if !opt.DisableMemStatsLikeMetrics { @@ -273,14 +287,29 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } } + if !opt.DisableRuntimeEnvVarsMetrics { + rmEnvVarMetrics = goRuntimeEnvVarsMetrics() + rmEnvVarsDescriptions = bestEffortLookupRM(rmNamesForEnvVarsMetrics) + + // Check if metric was not exposed before and if not, add to sampleBuf. + for _, rnevDesc := range rmEnvVarsDescriptions { + if _, ok := sampleMap[rnevDesc.Name]; ok { + continue + } + sampleBuf = append(sampleBuf, metrics.Sample{Name: rnevDesc.Name}) + sampleMap[rnevDesc.Name] = &sampleBuf[len(sampleBuf)-1] + } + } return &goCollector{ - base: newBaseGoCollector(), - sampleBuf: sampleBuf, - sampleMap: sampleMap, - rmExposedMetrics: metricSet, - rmExactSumMapForHist: opt.RuntimeMetricSumForHist, - msMetrics: msMetrics, - msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, + base: newBaseGoCollector(), + sampleBuf: sampleBuf, + sampleMap: sampleMap, + rmExposedMetrics: metricSet, + rmExactSumMapForHist: opt.RuntimeMetricSumForHist, + msMetrics: msMetrics, + msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, + rmEnvVarMetrics: rmEnvVarMetrics, + rmEnvVarMetricsEnabled: !opt.DisableRuntimeEnvVarsMetrics, } } diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index f2a31770c..551f49797 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -54,9 +54,6 @@ func expectedBaseMetrics() map[string]struct{} { b.goroutinesDesc.fqName, b.gcLastTimeDesc.fqName, b.threadsDesc.fqName, - b.goMaxProcs.fqName, - b.goGogcPercent.fqName, - b.goMemLimit.fqName, } { metrics[m] = struct{}{} } diff --git a/prometheus/internal/go_collector_options.go b/prometheus/internal/go_collector_options.go index 723b45d64..c2ff96e2f 100644 --- a/prometheus/internal/go_collector_options.go +++ b/prometheus/internal/go_collector_options.go @@ -26,7 +26,8 @@ type GoCollectorRule struct { // // This is internal, so external users only can use it via `collector.WithGoCollector*` methods type GoCollectorOptions struct { - DisableMemStatsLikeMetrics bool - RuntimeMetricSumForHist map[string]string - RuntimeMetricRules []GoCollectorRule + DisableMemStatsLikeMetrics bool + RuntimeMetricSumForHist map[string]string + RuntimeMetricRules []GoCollectorRule + DisableRuntimeEnvVarsMetrics bool } From 17b306559d8835ec88c48edb299220c031ae900f Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sun, 21 Jul 2024 10:17:02 +0200 Subject: [PATCH 03/13] Rethink struct for newly added metrics, adapt and add tests Signed-off-by: Arianna Vespri --- prometheus/collectors/go_collector_latest.go | 4 +++ .../collectors/go_collector_latest_test.go | 6 +++- prometheus/go_collector.go | 26 ++++++-------- prometheus/go_collector_latest.go | 8 ++++- prometheus/go_collector_latest_test.go | 36 +++++++++++++++---- 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/prometheus/collectors/go_collector_latest.go b/prometheus/collectors/go_collector_latest.go index f3179f35c..0d8df88a2 100644 --- a/prometheus/collectors/go_collector_latest.go +++ b/prometheus/collectors/go_collector_latest.go @@ -88,6 +88,10 @@ func WithGoCollectorMemStatsMetricsDisabled() func(options *internal.GoCollector } } +// WithGoCollectorRuntimeEnvVarsMetricsDisabled disables the following default metrics: +// go_gogc_percent +// go_gomemlimit +// go_gomaxprocs func WithGoCollectorRuntimeEnvVarsMetricsDisabled() func(options *internal.GoCollectorOptions) { return func(o *internal.GoCollectorOptions) { o.DisableRuntimeEnvVarsMetrics = true diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 76673f367..7a1c06c49 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -54,10 +54,11 @@ func TestGoCollectorMarshalling(t *testing.T) { } } -func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) { +func TestWithBaseMetricsOnly(t *testing.T) { reg := prometheus.NewRegistry() reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), + WithGoCollectorRuntimeEnvVarsMetricsDisabled(), )) result, err := reg.Gather() if err != nil { @@ -116,6 +117,7 @@ func TestGoCollectorAllowList(t *testing.T) { reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), WithGoCollectorRuntimeMetrics(test.rules...), + WithGoCollectorRuntimeEnvVarsMetricsDisabled(), )) result, err := reg.Gather() if err != nil { @@ -170,6 +172,7 @@ func TestGoCollectorDenyList(t *testing.T) { reg.MustRegister(NewGoCollector( WithGoCollectorMemStatsMetricsDisabled(), WithoutGoCollectorRuntimeMetrics(test.matchers...), + WithGoCollectorRuntimeEnvVarsMetricsDisabled(), )) result, err := reg.Gather() if err != nil { @@ -213,6 +216,7 @@ func ExampleGoCollector_WithAdvancedGoMetrics() { }, ), WithoutGoCollectorRuntimeMetrics(regexp.MustCompile("^/gc/.*")), + WithGoCollectorRuntimeEnvVarsMetricsDisabled(), )) http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index 1d6303cc7..6e368b2ad 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -289,8 +289,7 @@ func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { "Value of GOGC (percentage).", nil, nil, ), - eval: float64(readRunMetrSample("/gc/gogc:percent")[0].Value.Uint64()), - valType: GaugeValue, + origMetricName: "/gc/gogc:percent", }, { desc: NewDesc( @@ -298,8 +297,7 @@ func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { "Value of GOMEMLIMIT (bytes).", nil, nil, ), - eval: float64(readRunMetrSample("/gc/gomemlimit:bytes")[0].Value.Uint64()), - valType: GaugeValue, + origMetricName: "/gc/gomemlimit:bytes", }, { desc: NewDesc( @@ -307,21 +305,19 @@ func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { "Value of GOMAXPROCS, i.e number of usable threads.", nil, nil, ), - eval: float64(runtime.NumCPU()), - valType: GaugeValue, + origMetricName: "/sched/gomaxprocs:threads", }, } } -type runtimeEnvVarsMetrics []struct { // how to call this struct? - desc *Desc - eval float64 - valType ValueType +type runtimeEnvVarsMetrics []struct { // I couldn't come up with a better name. Any suggestions? + desc *Desc + origMetricName string } -func readRunMetrSample(metricName string) []runmetr.Sample { - sample := make([]runmetr.Sample, 1) - sample[0].Name = metricName - runmetr.Read(sample) - return sample +func readRunMetrSampleBuf(metricName string) []runmetr.Sample { + sampleBuf := make([]runmetr.Sample, 1) + sampleBuf[0].Name = metricName + runmetr.Read(sampleBuf) + return sampleBuf } diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index c42420ba0..7896503c1 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -81,7 +81,7 @@ var rmNamesForMemStatsMetrics = []string{ goMemoryClassesOtherBytes, } -var rmNamesForEnvVarsMetrics = []string{ // how to call them??? +var rmNamesForEnvVarsMetrics = []string{ // how to name this var??? goGCGogcPercent, goGCMemLimit, goSchedMaxProcs, @@ -389,6 +389,12 @@ func (c *goCollector) Collect(ch chan<- Metric) { ch <- MustNewConstMetric(i.desc, i.valType, i.eval(&ms)) } } + + if c.rmEnvVarMetricsEnabled { + for _, v := range c.rmEnvVarMetrics { + ch <- MustNewConstMetric(v.desc, GaugeValue, float64(readRunMetrSampleBuf(v.origMetricName)[0].Value.Uint64())) + } + } } // unwrapScalarRMValue unwraps a runtime/metrics value that is assumed diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index 551f49797..7eef31d55 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -74,6 +74,13 @@ func addExpectedRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} return metrics } +func addExpectedEnvVarsMetrics(metrics map[string]struct{}) map[string]struct{} { + for _, m := range goRuntimeEnvVarsMetrics() { + metrics[m.desc.fqName] = struct{}{} + } + return metrics +} + func TestGoCollector_ExposedMetrics(t *testing.T) { for _, tcase := range []struct { opts internal.GoCollectorOptions @@ -81,18 +88,27 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { }{ { opts: internal.GoCollectorOptions{ - DisableMemStatsLikeMetrics: true, + DisableMemStatsLikeMetrics: true, + DisableRuntimeEnvVarsMetrics: true, }, expectedFQNameSet: expectedBaseMetrics(), }, { - // Default, only MemStats. + // Default, only Memstats and RuntimeEnvVars. + expectedFQNameSet: addExpectedEnvVarsMetrics(addExpectedRuntimeMemStats(expectedBaseMetrics())), + }, + { + // Only MemStats. + opts: internal.GoCollectorOptions{ + DisableRuntimeEnvVarsMetrics: true, + }, expectedFQNameSet: addExpectedRuntimeMemStats(expectedBaseMetrics()), }, { - // Get all runtime/metrics without MemStats. + // Get all runtime/metrics without MemStats nor RuntimeEnvVars. opts: internal.GoCollectorOptions{ - DisableMemStatsLikeMetrics: true, + DisableMemStatsLikeMetrics: true, + DisableRuntimeEnvVarsMetrics: true, RuntimeMetricRules: []internal.GoCollectorRule{ {Matcher: regexp.MustCompile("/.*")}, }, @@ -100,13 +116,20 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { expectedFQNameSet: addExpectedRuntimeMetrics(expectedBaseMetrics()), }, { - // Get all runtime/metrics and MemStats. + // Get all runtime/metrics, MemStats and RuntimeEnvVars. opts: internal.GoCollectorOptions{ RuntimeMetricRules: []internal.GoCollectorRule{ {Matcher: regexp.MustCompile("/.*")}, }, }, - expectedFQNameSet: addExpectedRuntimeMemStats(addExpectedRuntimeMetrics(expectedBaseMetrics())), + expectedFQNameSet: addExpectedEnvVarsMetrics(addExpectedRuntimeMemStats(addExpectedRuntimeMetrics(expectedBaseMetrics()))), + }, + { + // Only RuntimeEnvVars. + opts: internal.GoCollectorOptions{ + DisableMemStatsLikeMetrics: true, + }, + expectedFQNameSet: addExpectedEnvVarsMetrics(expectedBaseMetrics()), }, } { if ok := t.Run("", func(t *testing.T) { @@ -229,6 +252,7 @@ func collectGoMetrics(t *testing.T, opts internal.GoCollectorOptions) []Metric { o.DisableMemStatsLikeMetrics = opts.DisableMemStatsLikeMetrics o.RuntimeMetricSumForHist = opts.RuntimeMetricSumForHist o.RuntimeMetricRules = opts.RuntimeMetricRules + o.DisableRuntimeEnvVarsMetrics = opts.DisableRuntimeEnvVarsMetrics }).(*goCollector) // Collect all metrics. From 5d9b680e77388aae7cbdcf6ba6a5549d5c45d111 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Sun, 21 Jul 2024 18:15:48 +0200 Subject: [PATCH 04/13] Simplify new metrics reading Signed-off-by: Arianna Vespri --- prometheus/go_collector.go | 8 ------- prometheus/go_collector_latest.go | 35 +++++++++++++++++-------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index 6e368b2ad..5d6fe6037 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -16,7 +16,6 @@ package prometheus import ( "runtime" "runtime/debug" - runmetr "runtime/metrics" "time" ) @@ -314,10 +313,3 @@ type runtimeEnvVarsMetrics []struct { // I couldn't come up with a better name. desc *Desc origMetricName string } - -func readRunMetrSampleBuf(metricName string) []runmetr.Sample { - sampleBuf := make([]runmetr.Sample, 1) - sampleBuf[0].Name = metricName - runmetr.Read(sampleBuf) - return sampleBuf -} diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 7896503c1..9d2ce1d22 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -126,8 +126,8 @@ type goCollector struct { msMetrics memStatsMetrics msMetricsEnabled bool - rmEnvVarMetrics runtimeEnvVarsMetrics // how to call them??? - rmEnvVarMetricsEnabled bool + rmEnvVarsMetrics runtimeEnvVarsMetrics // how to call them??? + rmEnvVarsMetricsEnabled bool } type rmMetricDesc struct { @@ -269,7 +269,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { var ( msMetrics memStatsMetrics msDescriptions []metrics.Description - rmEnvVarMetrics runtimeEnvVarsMetrics + rmEnvVarsMetrics runtimeEnvVarsMetrics rmEnvVarsDescriptions []metrics.Description ) @@ -288,7 +288,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } if !opt.DisableRuntimeEnvVarsMetrics { - rmEnvVarMetrics = goRuntimeEnvVarsMetrics() + rmEnvVarsMetrics = goRuntimeEnvVarsMetrics() rmEnvVarsDescriptions = bestEffortLookupRM(rmNamesForEnvVarsMetrics) // Check if metric was not exposed before and if not, add to sampleBuf. @@ -301,15 +301,15 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } } return &goCollector{ - base: newBaseGoCollector(), - sampleBuf: sampleBuf, - sampleMap: sampleMap, - rmExposedMetrics: metricSet, - rmExactSumMapForHist: opt.RuntimeMetricSumForHist, - msMetrics: msMetrics, - msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, - rmEnvVarMetrics: rmEnvVarMetrics, - rmEnvVarMetricsEnabled: !opt.DisableRuntimeEnvVarsMetrics, + base: newBaseGoCollector(), + sampleBuf: sampleBuf, + sampleMap: sampleMap, + rmExposedMetrics: metricSet, + rmExactSumMapForHist: opt.RuntimeMetricSumForHist, + msMetrics: msMetrics, + msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, + rmEnvVarsMetrics: rmEnvVarsMetrics, + rmEnvVarsMetricsEnabled: !opt.DisableRuntimeEnvVarsMetrics, } } @@ -390,9 +390,12 @@ func (c *goCollector) Collect(ch chan<- Metric) { } } - if c.rmEnvVarMetricsEnabled { - for _, v := range c.rmEnvVarMetrics { - ch <- MustNewConstMetric(v.desc, GaugeValue, float64(readRunMetrSampleBuf(v.origMetricName)[0].Value.Uint64())) + if c.rmEnvVarsMetricsEnabled { + sampleBuf := make([]metrics.Sample, len(c.rmEnvVarsMetrics)) + for i, v := range c.rmEnvVarsMetrics { + sampleBuf[i].Name = v.origMetricName + metrics.Read(sampleBuf) + ch <- MustNewConstMetric(v.desc, GaugeValue, unwrapScalarRMValue(sampleBuf[i].Value)) } } } From 4490f8d9b8cf4ba6595f3642261bf723f05d7605 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Mon, 22 Jul 2024 13:42:49 +0200 Subject: [PATCH 05/13] Correct loop, add debugging lines Signed-off-by: Arianna Vespri --- prometheus/go_collector_latest.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 9d2ce1d22..5596004f7 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -17,6 +17,7 @@ package prometheus import ( + "fmt" "math" "runtime" "runtime/metrics" @@ -393,8 +394,11 @@ func (c *goCollector) Collect(ch chan<- Metric) { if c.rmEnvVarsMetricsEnabled { sampleBuf := make([]metrics.Sample, len(c.rmEnvVarsMetrics)) for i, v := range c.rmEnvVarsMetrics { + fmt.Printf("Reading metric %d: %q, %#v\n", i, v.origMetricName, *v.desc) sampleBuf[i].Name = v.origMetricName - metrics.Read(sampleBuf) + } + metrics.Read(sampleBuf) + for i, v := range c.rmEnvVarsMetrics { ch <- MustNewConstMetric(v.desc, GaugeValue, unwrapScalarRMValue(sampleBuf[i].Value)) } } @@ -414,13 +418,13 @@ func unwrapScalarRMValue(v metrics.Value) float64 { // // This should never happen because we always populate our metric // set from the runtime/metrics package. - panic("unexpected unsupported metric") + panic("unexpected bad kind metric") default: // Unsupported metric kind. // // This should never happen because we check for this during initialization // and flag and filter metrics whose kinds we don't understand. - panic("unexpected unsupported metric kind") + panic(fmt.Sprintf("unexpected unsupported metric: %v", v.Kind())) } } From fb0afbe40d1082de16ab50068dc8803b419acca8 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Mon, 22 Jul 2024 14:10:45 +0200 Subject: [PATCH 06/13] Make goRuntimeEnvVarsMetrics function Go version dependent Signed-off-by: Arianna Vespri --- prometheus/go_collector.go | 29 -------------------- prometheus/go_collector_go120.go | 30 +++++++++++++++++++++ prometheus/go_collector_go121.go | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 prometheus/go_collector_go120.go create mode 100644 prometheus/go_collector_go121.go diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index 5d6fe6037..69e2ec8c8 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -280,35 +280,6 @@ type memStatsMetrics []struct { valType ValueType } -func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { - return runtimeEnvVarsMetrics{ - { - desc: NewDesc( - "go_gogc_percent", - "Value of GOGC (percentage).", - nil, nil, - ), - origMetricName: "/gc/gogc:percent", - }, - { - desc: NewDesc( - "go_gomemlimit", - "Value of GOMEMLIMIT (bytes).", - nil, nil, - ), - origMetricName: "/gc/gomemlimit:bytes", - }, - { - desc: NewDesc( - "go_gomaxprocs", - "Value of GOMAXPROCS, i.e number of usable threads.", - nil, nil, - ), - origMetricName: "/sched/gomaxprocs:threads", - }, - } -} - type runtimeEnvVarsMetrics []struct { // I couldn't come up with a better name. Any suggestions? desc *Desc origMetricName string diff --git a/prometheus/go_collector_go120.go b/prometheus/go_collector_go120.go new file mode 100644 index 000000000..5a98df74a --- /dev/null +++ b/prometheus/go_collector_go120.go @@ -0,0 +1,30 @@ +// 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 + +func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { + return runtimeEnvVarsMetrics{ + { + desc: NewDesc( + "go_gomaxprocs", + "Value of GOMAXPROCS, i.e number of usable threads.", + nil, nil, + ), + origMetricName: "/sched/gomaxprocs:threads", + }, + } +} diff --git a/prometheus/go_collector_go121.go b/prometheus/go_collector_go121.go new file mode 100644 index 000000000..42500d04c --- /dev/null +++ b/prometheus/go_collector_go121.go @@ -0,0 +1,46 @@ +// 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 + +func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { + return runtimeEnvVarsMetrics{ + { + desc: NewDesc( + "go_gogc_percent", + "Value of GOGC (percentage).", + nil, nil, + ), + origMetricName: "/gc/gogc:percent", + }, + { + desc: NewDesc( + "go_gomemlimit", + "Value of GOMEMLIMIT (bytes).", + nil, nil, + ), + origMetricName: "/gc/gomemlimit:bytes", + }, + { + desc: NewDesc( + "go_gomaxprocs", + "Value of GOMAXPROCS, i.e number of usable threads.", + nil, nil, + ), + origMetricName: "/sched/gomaxprocs:threads", + }, + } +} From 0b3a6f04f88cd137e8e640e2b7eb135ecc268459 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Mon, 22 Jul 2024 14:16:56 +0200 Subject: [PATCH 07/13] Fix go mod Signed-off-by: Arianna Vespri --- go.mod | 1 - go.sum | 2 -- 2 files changed, 3 deletions(-) diff --git a/go.mod b/go.mod index afe7cd144..60f8dc1d8 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( require ( github.com/golang/protobuf v1.5.3 // indirect - github.com/hashicorp/go-version v1.7.0 github.com/jpillora/backoff v1.0.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/go.sum b/go.sum index 1d048bdbf..743a74f53 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= -github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= From 6478f56935c73f23b38144dc33cae75ed10554ac Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Mon, 22 Jul 2024 14:23:35 +0200 Subject: [PATCH 08/13] Remove debuggin line Signed-off-by: Arianna Vespri --- prometheus/go_collector_latest.go | 1 - 1 file changed, 1 deletion(-) diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index 5596004f7..ce4af331c 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -394,7 +394,6 @@ func (c *goCollector) Collect(ch chan<- Metric) { if c.rmEnvVarsMetricsEnabled { sampleBuf := make([]metrics.Sample, len(c.rmEnvVarsMetrics)) for i, v := range c.rmEnvVarsMetrics { - fmt.Printf("Reading metric %d: %q, %#v\n", i, v.origMetricName, *v.desc) sampleBuf[i].Name = v.origMetricName } metrics.Read(sampleBuf) From 20ebd6ccd2da79f9e2d3bd46938fc382a3ce572a Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Tue, 6 Aug 2024 16:44:57 +0200 Subject: [PATCH 09/13] Move default runtime metrics into the runtime metrics flow, change tests accordingly Signed-off-by: Arianna Vespri --- .../collectors/go_collector_go117_test.go | 6 ++ .../collectors/go_collector_go119_test.go | 17 +++++ .../collectors/go_collector_go120_test.go | 17 +++++ .../collectors/go_collector_go121_test.go | 27 ++++++++ .../collectors/go_collector_go122_test.go | 27 ++++++++ prometheus/collectors/go_collector_latest.go | 10 --- .../collectors/go_collector_latest_test.go | 28 +++++--- prometheus/go_collector.go | 5 -- prometheus/go_collector_go120.go | 30 --------- prometheus/go_collector_go121.go | 46 ------------- prometheus/go_collector_latest.go | 65 ++++--------------- prometheus/go_collector_latest_test.go | 43 +++++------- prometheus/internal/go_collector_options.go | 7 +- 13 files changed, 148 insertions(+), 180 deletions(-) delete mode 100644 prometheus/go_collector_go120.go delete mode 100644 prometheus/go_collector_go121.go diff --git a/prometheus/collectors/go_collector_go117_test.go b/prometheus/collectors/go_collector_go117_test.go index 760ad046b..f378d4097 100644 --- a/prometheus/collectors/go_collector_go117_test.go +++ b/prometheus/collectors/go_collector_go117_test.go @@ -102,3 +102,9 @@ func withSchedulerMetrics() []string { func withDebugMetrics() []string { return withBaseMetrics([]string{}) } + +var defaultRuntimeMetrics = []string{} + +func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { + return metricNames +} diff --git a/prometheus/collectors/go_collector_go119_test.go b/prometheus/collectors/go_collector_go119_test.go index 1ef9a4cf0..4febad2ce 100644 --- a/prometheus/collectors/go_collector_go119_test.go +++ b/prometheus/collectors/go_collector_go119_test.go @@ -16,6 +16,8 @@ package collectors +import "sort" + func withAllMetrics() []string { return withBaseMetrics([]string{ "go_cgo_go_to_c_calls_calls_total", @@ -109,3 +111,18 @@ func withSchedulerMetrics() []string { func withDebugMetrics() []string { return withBaseMetrics([]string{}) } + +var defaultRuntimeMetrics = []string{ + "go_sched_gomaxprocs_threads", +} + +func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { + // If withoutSched is true, exclude "go_sched_gomaxprocs_threads". + if withoutSched { + return metricNames + } + metricNames = append(metricNames, defaultRuntimeMetrics...) + // sorting is required + sort.Strings(metricNames) + return metricNames +} diff --git a/prometheus/collectors/go_collector_go120_test.go b/prometheus/collectors/go_collector_go120_test.go index 723cbf826..968a016ab 100644 --- a/prometheus/collectors/go_collector_go120_test.go +++ b/prometheus/collectors/go_collector_go120_test.go @@ -16,6 +16,8 @@ package collectors +import "sort" + func withAllMetrics() []string { return withBaseMetrics([]string{ "go_cgo_go_to_c_calls_calls_total", @@ -116,3 +118,18 @@ func withSchedulerMetrics() []string { func withDebugMetrics() []string { return withBaseMetrics([]string{}) } + +var defaultRuntimeMetrics = []string{ + "go_sched_gomaxprocs_threads", +} + +func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { + // If withoutSched is true, exclude "go_sched_gomaxprocs_threads". + if withoutSched { + return metricNames + } + metricNames = append(metricNames, defaultRuntimeMetrics...) + // sorting is required + sort.Strings(metricNames) + return metricNames +} diff --git a/prometheus/collectors/go_collector_go121_test.go b/prometheus/collectors/go_collector_go121_test.go index b105f7107..f9cc318cc 100644 --- a/prometheus/collectors/go_collector_go121_test.go +++ b/prometheus/collectors/go_collector_go121_test.go @@ -16,6 +16,8 @@ package collectors +import "sort" + func withAllMetrics() []string { return withBaseMetrics([]string{ "go_cgo_go_to_c_calls_calls_total", @@ -169,3 +171,28 @@ func withDebugMetrics() []string { "go_godebug_non_default_behavior_zipinsecurepath_events_total", }) } + +var defaultRuntimeMetrics = []string{ + "go_gc_gogc_percent", + "go_gc_gomemlimit_bytes", + "go_sched_gomaxprocs_threads", +} + +func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { + if withoutGC && withoutSched { + // If both flags are true, return the metricNames as is. + return metricNames + } else if withoutGC && !withoutSched { + // If only withoutGC is true, include "go_sched_gomaxprocs_threads" only. + metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...) + } else if withoutSched && !withoutGC { + // If only withoutSched is true, exclude "go_sched_gomaxprocs_threads". + metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...) + } else { + // If neither flag is true, use the default metrics. + metricNames = append(metricNames, defaultRuntimeMetrics...) + } + // sorting is required + sort.Strings(metricNames) + return metricNames +} diff --git a/prometheus/collectors/go_collector_go122_test.go b/prometheus/collectors/go_collector_go122_test.go index 0c863f1ee..2413c2750 100644 --- a/prometheus/collectors/go_collector_go122_test.go +++ b/prometheus/collectors/go_collector_go122_test.go @@ -16,6 +16,8 @@ package collectors +import "sort" + func withAllMetrics() []string { return withBaseMetrics([]string{ "go_cgo_go_to_c_calls_calls_total", @@ -191,3 +193,28 @@ func withDebugMetrics() []string { "go_godebug_non_default_behavior_zipinsecurepath_events_total", }) } + +var defaultRuntimeMetrics = []string{ + "go_gc_gogc_percent", + "go_gc_gomemlimit_bytes", + "go_sched_gomaxprocs_threads", +} + +func withDefaultRuntimeMetrics(metricNames []string, withoutGC, withoutSched bool) []string { + if withoutGC && withoutSched { + // If both flags are true, return the metricNames as is. + return metricNames + } else if withoutGC && !withoutSched { + // If only withoutGC is true, include "go_sched_gomaxprocs_threads" only. + metricNames = append(metricNames, []string{"go_sched_gomaxprocs_threads"}...) + } else if withoutSched && !withoutGC { + // If only withoutSched is true, exclude "go_sched_gomaxprocs_threads". + metricNames = append(metricNames, []string{"go_gc_gogc_percent", "go_gc_gomemlimit_bytes"}...) + } else { + // If neither flag is true, use the default metrics. + metricNames = append(metricNames, defaultRuntimeMetrics...) + } + // sorting is required + sort.Strings(metricNames) + return metricNames +} diff --git a/prometheus/collectors/go_collector_latest.go b/prometheus/collectors/go_collector_latest.go index 0d8df88a2..771a72a90 100644 --- a/prometheus/collectors/go_collector_latest.go +++ b/prometheus/collectors/go_collector_latest.go @@ -88,16 +88,6 @@ func WithGoCollectorMemStatsMetricsDisabled() func(options *internal.GoCollector } } -// WithGoCollectorRuntimeEnvVarsMetricsDisabled disables the following default metrics: -// go_gogc_percent -// go_gomemlimit -// go_gomaxprocs -func WithGoCollectorRuntimeEnvVarsMetricsDisabled() func(options *internal.GoCollectorOptions) { - return func(o *internal.GoCollectorOptions) { - o.DisableRuntimeEnvVarsMetrics = true - } -} - // GoRuntimeMetricsRule allow enabling and configuring particular group of runtime/metrics. // TODO(bwplotka): Consider adding ability to adjust buckets. type GoRuntimeMetricsRule struct { diff --git a/prometheus/collectors/go_collector_latest_test.go b/prometheus/collectors/go_collector_latest_test.go index 11331ed87..a7e7e1071 100644 --- a/prometheus/collectors/go_collector_latest_test.go +++ b/prometheus/collectors/go_collector_latest_test.go @@ -93,7 +93,9 @@ func TestWithGoCollectorDefault(t *testing.T) { got = append(got, r.GetName()) } - if diff := cmp.Diff(got, withBaseMetrics(memstatMetrics)); diff != "" { + expected := append(withBaseMetrics(memstatMetrics), defaultRuntimeMetrics...) + sort.Strings(expected) + if diff := cmp.Diff(got, expected); diff != "" { t.Errorf("[IMPORTANT, those are default metrics, can't change in 1.x] missmatch (-want +got):\n%s", diff) } } @@ -113,7 +115,7 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) { got = append(got, r.GetName()) } - if diff := cmp.Diff(got, baseMetrics); diff != "" { + if diff := cmp.Diff(got, withBaseMetrics(defaultRuntimeMetrics)); diff != "" { t.Errorf("missmatch (-want +got):\n%s", diff) } } @@ -127,7 +129,7 @@ func TestGoCollectorAllowList(t *testing.T) { { name: "Without any rules", rules: nil, - expected: baseMetrics, + expected: withBaseMetrics(defaultRuntimeMetrics), }, { name: "allow all", @@ -137,22 +139,22 @@ func TestGoCollectorAllowList(t *testing.T) { { name: "allow GC", rules: []GoRuntimeMetricsRule{MetricsGC}, - expected: withGCMetrics(), + expected: withDefaultRuntimeMetrics(withGCMetrics(), true, false), }, { name: "allow Memory", rules: []GoRuntimeMetricsRule{MetricsMemory}, - expected: withMemoryMetrics(), + expected: withDefaultRuntimeMetrics(withMemoryMetrics(), false, false), }, { name: "allow Scheduler", rules: []GoRuntimeMetricsRule{MetricsScheduler}, - expected: withSchedulerMetrics(), + expected: withDefaultRuntimeMetrics(withSchedulerMetrics(), false, true), }, { name: "allow debug", rules: []GoRuntimeMetricsRule{MetricsDebug}, - expected: withDebugMetrics(), + expected: withDefaultRuntimeMetrics(withDebugMetrics(), false, false), }, } { t.Run(test.name, func(t *testing.T) { @@ -193,7 +195,7 @@ func TestGoCollectorDenyList(t *testing.T) { { name: "Without any matchers", matchers: nil, - expected: baseMetrics, + expected: withBaseMetrics(defaultRuntimeMetrics), }, { name: "deny all", @@ -206,6 +208,14 @@ func TestGoCollectorDenyList(t *testing.T) { regexp.MustCompile("^/gc/.*"), regexp.MustCompile("^/sched/latencies:.*"), }, + expected: withDefaultRuntimeMetrics(baseMetrics, true, false), + }, + { + name: "deny gc and scheduler", + matchers: []*regexp.Regexp{ + regexp.MustCompile("^/gc/.*"), + regexp.MustCompile("^/sched/.*"), + }, expected: baseMetrics, }, } { @@ -235,7 +245,7 @@ func TestGoCollectorDenyList(t *testing.T) { func ExampleGoCollector() { reg := prometheus.NewRegistry() - // Register the GoCollector with the default options. Only the base metrics and memstats are enabled. + // Register the GoCollector with the default options. Only the base metrics, default runtime metrics and memstats are enabled. reg.MustRegister(NewGoCollector()) http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index d8b1bd29f..f29708b16 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -280,8 +280,3 @@ type memStatsMetrics []struct { eval func(*runtime.MemStats) float64 valType ValueType } - -type runtimeEnvVarsMetrics []struct { // I couldn't come up with a better name. Any suggestions? - desc *Desc - origMetricName string -} diff --git a/prometheus/go_collector_go120.go b/prometheus/go_collector_go120.go deleted file mode 100644 index 5a98df74a..000000000 --- a/prometheus/go_collector_go120.go +++ /dev/null @@ -1,30 +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 - -func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { - return runtimeEnvVarsMetrics{ - { - desc: NewDesc( - "go_gomaxprocs", - "Value of GOMAXPROCS, i.e number of usable threads.", - nil, nil, - ), - origMetricName: "/sched/gomaxprocs:threads", - }, - } -} diff --git a/prometheus/go_collector_go121.go b/prometheus/go_collector_go121.go deleted file mode 100644 index 42500d04c..000000000 --- a/prometheus/go_collector_go121.go +++ /dev/null @@ -1,46 +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 - -func goRuntimeEnvVarsMetrics() runtimeEnvVarsMetrics { - return runtimeEnvVarsMetrics{ - { - desc: NewDesc( - "go_gogc_percent", - "Value of GOGC (percentage).", - nil, nil, - ), - origMetricName: "/gc/gogc:percent", - }, - { - desc: NewDesc( - "go_gomemlimit", - "Value of GOMEMLIMIT (bytes).", - nil, nil, - ), - origMetricName: "/gc/gomemlimit:bytes", - }, - { - desc: NewDesc( - "go_gomaxprocs", - "Value of GOMAXPROCS, i.e number of usable threads.", - nil, nil, - ), - origMetricName: "/sched/gomaxprocs:threads", - }, - } -} diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index ce4af331c..a3d38a40e 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -19,6 +19,7 @@ package prometheus import ( "fmt" "math" + "regexp" "runtime" "runtime/metrics" "strings" @@ -32,7 +33,6 @@ import ( const ( // constants for strings referenced more than once. - goGCGogcPercent = "/gc/gogc:percent" goGCHeapTinyAllocsObjects = "/gc/heap/tiny/allocs:objects" goGCHeapAllocsObjects = "/gc/heap/allocs:objects" goGCHeapFreesObjects = "/gc/heap/frees:objects" @@ -40,7 +40,6 @@ const ( goGCHeapAllocsBytes = "/gc/heap/allocs:bytes" goGCHeapObjects = "/gc/heap/objects:objects" goGCHeapGoalBytes = "/gc/heap/goal:bytes" - goGCMemLimit = "/gc/gomemlimit:bytes" goMemoryClassesTotalBytes = "/memory/classes/total:bytes" goMemoryClassesHeapObjectsBytes = "/memory/classes/heap/objects:bytes" goMemoryClassesHeapUnusedBytes = "/memory/classes/heap/unused:bytes" @@ -55,7 +54,6 @@ const ( goMemoryClassesProfilingBucketsBytes = "/memory/classes/profiling/buckets:bytes" goMemoryClassesMetadataOtherBytes = "/memory/classes/metadata/other:bytes" goMemoryClassesOtherBytes = "/memory/classes/other:bytes" - goSchedMaxProcs = "/sched/gomaxprocs:threads" ) // rmNamesForMemStatsMetrics represents runtime/metrics names required to populate goRuntimeMemStats from like logic. @@ -82,12 +80,6 @@ var rmNamesForMemStatsMetrics = []string{ goMemoryClassesOtherBytes, } -var rmNamesForEnvVarsMetrics = []string{ // how to name this var??? - goGCGogcPercent, - goGCMemLimit, - goSchedMaxProcs, -} - func bestEffortLookupRM(lookup []string) []metrics.Description { ret := make([]metrics.Description, 0, len(lookup)) for _, rm := range metrics.All() { @@ -126,9 +118,6 @@ type goCollector struct { // as well. msMetrics memStatsMetrics msMetricsEnabled bool - - rmEnvVarsMetrics runtimeEnvVarsMetrics // how to call them??? - rmEnvVarsMetricsEnabled bool } type rmMetricDesc struct { @@ -166,7 +155,9 @@ func defaultGoCollectorOptions() internal.GoCollectorOptions { "/gc/heap/frees-by-size:bytes": goGCHeapFreesBytes, }, RuntimeMetricRules: []internal.GoCollectorRule{ - //{Matcher: regexp.MustCompile("")}, + { + Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`), + }, }, } } @@ -206,7 +197,7 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { metricSet := make([]collectorMetric, 0, len(exposedDescriptions)) // SampleBuf is used for reading from runtime/metrics. // We are assuming the largest case to have stable pointers for sampleMap purposes. - sampleBuf := make([]metrics.Sample, 0, len(exposedDescriptions)+len(opt.RuntimeMetricSumForHist)+len(rmNamesForMemStatsMetrics)+len(rmNamesForEnvVarsMetrics)) + sampleBuf := make([]metrics.Sample, 0, len(exposedDescriptions)+len(opt.RuntimeMetricSumForHist)+len(rmNamesForMemStatsMetrics)) sampleMap := make(map[string]*metrics.Sample, len(exposedDescriptions)) for _, d := range exposedDescriptions { namespace, subsystem, name, ok := internal.RuntimeMetricsToProm(&d.Description) @@ -268,10 +259,8 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } var ( - msMetrics memStatsMetrics - msDescriptions []metrics.Description - rmEnvVarsMetrics runtimeEnvVarsMetrics - rmEnvVarsDescriptions []metrics.Description + msMetrics memStatsMetrics + msDescriptions []metrics.Description ) if !opt.DisableMemStatsLikeMetrics { @@ -288,29 +277,14 @@ func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector { } } - if !opt.DisableRuntimeEnvVarsMetrics { - rmEnvVarsMetrics = goRuntimeEnvVarsMetrics() - rmEnvVarsDescriptions = bestEffortLookupRM(rmNamesForEnvVarsMetrics) - - // Check if metric was not exposed before and if not, add to sampleBuf. - for _, rnevDesc := range rmEnvVarsDescriptions { - if _, ok := sampleMap[rnevDesc.Name]; ok { - continue - } - sampleBuf = append(sampleBuf, metrics.Sample{Name: rnevDesc.Name}) - sampleMap[rnevDesc.Name] = &sampleBuf[len(sampleBuf)-1] - } - } return &goCollector{ - base: newBaseGoCollector(), - sampleBuf: sampleBuf, - sampleMap: sampleMap, - rmExposedMetrics: metricSet, - rmExactSumMapForHist: opt.RuntimeMetricSumForHist, - msMetrics: msMetrics, - msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, - rmEnvVarsMetrics: rmEnvVarsMetrics, - rmEnvVarsMetricsEnabled: !opt.DisableRuntimeEnvVarsMetrics, + base: newBaseGoCollector(), + sampleBuf: sampleBuf, + sampleMap: sampleMap, + rmExposedMetrics: metricSet, + rmExactSumMapForHist: opt.RuntimeMetricSumForHist, + msMetrics: msMetrics, + msMetricsEnabled: !opt.DisableMemStatsLikeMetrics, } } @@ -390,17 +364,6 @@ func (c *goCollector) Collect(ch chan<- Metric) { ch <- MustNewConstMetric(i.desc, i.valType, i.eval(&ms)) } } - - if c.rmEnvVarsMetricsEnabled { - sampleBuf := make([]metrics.Sample, len(c.rmEnvVarsMetrics)) - for i, v := range c.rmEnvVarsMetrics { - sampleBuf[i].Name = v.origMetricName - } - metrics.Read(sampleBuf) - for i, v := range c.rmEnvVarsMetrics { - ch <- MustNewConstMetric(v.desc, GaugeValue, unwrapScalarRMValue(sampleBuf[i].Value)) - } - } } // unwrapScalarRMValue unwraps a runtime/metrics value that is assumed diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index 7eef31d55..b2ec5f00c 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -74,9 +74,14 @@ func addExpectedRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} return metrics } -func addExpectedEnvVarsMetrics(metrics map[string]struct{}) map[string]struct{} { - for _, m := range goRuntimeEnvVarsMetrics() { - metrics[m.desc.fqName] = struct{}{} +func addExpectedDefaultRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} { + 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", + } + for _, e := range expMetrics { + metrics[e] = struct{}{} } return metrics } @@ -88,27 +93,23 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { }{ { opts: internal.GoCollectorOptions{ - DisableMemStatsLikeMetrics: true, - DisableRuntimeEnvVarsMetrics: true, + DisableMemStatsLikeMetrics: true, }, expectedFQNameSet: expectedBaseMetrics(), }, { - // Default, only Memstats and RuntimeEnvVars. - expectedFQNameSet: addExpectedEnvVarsMetrics(addExpectedRuntimeMemStats(expectedBaseMetrics())), - }, - { - // Only MemStats. + // Default, only MemStats and default Runtime metrics. opts: internal.GoCollectorOptions{ - DisableRuntimeEnvVarsMetrics: true, + RuntimeMetricRules: []internal.GoCollectorRule{ + {Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`)}, + }, }, - expectedFQNameSet: addExpectedRuntimeMemStats(expectedBaseMetrics()), + expectedFQNameSet: addExpectedDefaultRuntimeMetrics(addExpectedRuntimeMemStats(expectedBaseMetrics())), }, { - // Get all runtime/metrics without MemStats nor RuntimeEnvVars. + // Get all runtime/metrics without MemStats. opts: internal.GoCollectorOptions{ - DisableMemStatsLikeMetrics: true, - DisableRuntimeEnvVarsMetrics: true, + DisableMemStatsLikeMetrics: true, RuntimeMetricRules: []internal.GoCollectorRule{ {Matcher: regexp.MustCompile("/.*")}, }, @@ -116,20 +117,13 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { expectedFQNameSet: addExpectedRuntimeMetrics(expectedBaseMetrics()), }, { - // Get all runtime/metrics, MemStats and RuntimeEnvVars. + // Get all runtime/metrics and MemStats. opts: internal.GoCollectorOptions{ RuntimeMetricRules: []internal.GoCollectorRule{ {Matcher: regexp.MustCompile("/.*")}, }, }, - expectedFQNameSet: addExpectedEnvVarsMetrics(addExpectedRuntimeMemStats(addExpectedRuntimeMetrics(expectedBaseMetrics()))), - }, - { - // Only RuntimeEnvVars. - opts: internal.GoCollectorOptions{ - DisableMemStatsLikeMetrics: true, - }, - expectedFQNameSet: addExpectedEnvVarsMetrics(expectedBaseMetrics()), + expectedFQNameSet: addExpectedRuntimeMemStats(addExpectedRuntimeMetrics(expectedBaseMetrics())), }, } { if ok := t.Run("", func(t *testing.T) { @@ -252,7 +246,6 @@ func collectGoMetrics(t *testing.T, opts internal.GoCollectorOptions) []Metric { o.DisableMemStatsLikeMetrics = opts.DisableMemStatsLikeMetrics o.RuntimeMetricSumForHist = opts.RuntimeMetricSumForHist o.RuntimeMetricRules = opts.RuntimeMetricRules - o.DisableRuntimeEnvVarsMetrics = opts.DisableRuntimeEnvVarsMetrics }).(*goCollector) // Collect all metrics. diff --git a/prometheus/internal/go_collector_options.go b/prometheus/internal/go_collector_options.go index c2ff96e2f..723b45d64 100644 --- a/prometheus/internal/go_collector_options.go +++ b/prometheus/internal/go_collector_options.go @@ -26,8 +26,7 @@ type GoCollectorRule struct { // // This is internal, so external users only can use it via `collector.WithGoCollector*` methods type GoCollectorOptions struct { - DisableMemStatsLikeMetrics bool - RuntimeMetricSumForHist map[string]string - RuntimeMetricRules []GoCollectorRule - DisableRuntimeEnvVarsMetrics bool + DisableMemStatsLikeMetrics bool + RuntimeMetricSumForHist map[string]string + RuntimeMetricRules []GoCollectorRule } From ed4053dc7be4c4e27e5260f98faaefcca2f16338 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Tue, 6 Aug 2024 17:36:28 +0200 Subject: [PATCH 10/13] Go version expected default runtime metrics map for tests Signed-off-by: Arianna Vespri --- prometheus/go_collector_latest_go120_test.go | 21 ++++++++++++++++++ prometheus/go_collector_latest_go121_test.go | 23 ++++++++++++++++++++ prometheus/go_collector_latest_test.go | 5 ----- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 prometheus/go_collector_latest_go120_test.go create mode 100644 prometheus/go_collector_latest_go121_test.go diff --git a/prometheus/go_collector_latest_go120_test.go b/prometheus/go_collector_latest_go120_test.go new file mode 100644 index 000000000..a6df675fd --- /dev/null +++ b/prometheus/go_collector_latest_go120_test.go @@ -0,0 +1,21 @@ +// 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", +} diff --git a/prometheus/go_collector_latest_go121_test.go b/prometheus/go_collector_latest_go121_test.go new file mode 100644 index 000000000..a6c3c18e9 --- /dev/null +++ b/prometheus/go_collector_latest_go121_test.go @@ -0,0 +1,23 @@ +// 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", +} diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index b2ec5f00c..cde7a2d77 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -75,11 +75,6 @@ func addExpectedRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} } func addExpectedDefaultRuntimeMetrics(metrics map[string]struct{}) map[string]struct{} { - 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", - } for _, e := range expMetrics { metrics[e] = struct{}{} } From b8a9eb7b75b4bdc7a5b041e8acb7072d7fad1827 Mon Sep 17 00:00:00 2001 From: bwplotka Date: Fri, 9 Aug 2024 11:01:18 +0100 Subject: [PATCH 11/13] 1.21 update. Signed-off-by: bwplotka --- prometheus/go_collector_metrics_go121_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prometheus/go_collector_metrics_go121_test.go b/prometheus/go_collector_metrics_go121_test.go index 58a8f10d9..90d05bd0e 100644 --- a/prometheus/go_collector_metrics_go121_test.go +++ b/prometheus/go_collector_metrics_go121_test.go @@ -52,7 +52,6 @@ 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", @@ -80,4 +79,4 @@ var expectedRuntimeMetrics = map[string]string{ "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", } -const expectedRuntimeMetricsCardinality = 115 +const expectedRuntimeMetricsCardinality = 114 From 23879d69c30460b71e386fcec3bfc6f2e4a21e77 Mon Sep 17 00:00:00 2001 From: bwplotka Date: Fri, 9 Aug 2024 11:14:57 +0100 Subject: [PATCH 12/13] Addressed comments on Arianna's PR. Signed-off-by: bwplotka --- prometheus/gen_go_collector_metrics_set.go | 42 ++++- prometheus/go_collector_latest.go | 6 +- prometheus/go_collector_latest_go120_test.go | 21 --- prometheus/go_collector_latest_go121_test.go | 23 --- prometheus/go_collector_metrics_go120_test.go | 100 +++++----- prometheus/go_collector_metrics_go121_test.go | 155 +++++++-------- prometheus/go_collector_metrics_go122_test.go | 176 +++++++++--------- prometheus/internal/go_collector_options.go | 2 + 8 files changed, 264 insertions(+), 261 deletions(-) delete mode 100644 prometheus/go_collector_latest_go120_test.go delete mode 100644 prometheus/go_collector_latest_go121_test.go diff --git a/prometheus/gen_go_collector_metrics_set.go b/prometheus/gen_go_collector_metrics_set.go index 2622b71e4..f1db3d8d1 100644 --- a/prometheus/gen_go_collector_metrics_set.go +++ b/prometheus/gen_go_collector_metrics_set.go @@ -63,16 +63,29 @@ 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 - GoVersion goVersion - Cardinality int + AllDescriptions []metrics.Description + DefaultDescriptions []metrics.Description + GoVersion goVersion + Cardinality int }{ - Descriptions: metrics.All(), - GoVersion: v, - Cardinality: rmCardinality(), + AllDescriptions: allDesc, + DefaultDescriptions: defaultDesc, + GoVersion: v, + Cardinality: rmCardinality(), }) if err != nil { log.Fatalf("executing template: %v", err) @@ -167,14 +180,25 @@ 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"}}, {{- end -}} {{end}} -} + } + + expMetrics = map[string]string{ +{{- range .DefaultDescriptions -}} + {{- $trans := rm2prom . -}} + {{- if ne $trans "" }} + {{.Name | printf "%q"}}: {{$trans | printf "%q"}}, + {{- end -}} +{{end}} + } +) const expectedRuntimeMetricsCardinality = {{.Cardinality}} `)) diff --git a/prometheus/go_collector_latest.go b/prometheus/go_collector_latest.go index a3d38a40e..127d0b1ec 100644 --- a/prometheus/go_collector_latest.go +++ b/prometheus/go_collector_latest.go @@ -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}, }, } } diff --git a/prometheus/go_collector_latest_go120_test.go b/prometheus/go_collector_latest_go120_test.go deleted file mode 100644 index a6df675fd..000000000 --- a/prometheus/go_collector_latest_go120_test.go +++ /dev/null @@ -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", -} diff --git a/prometheus/go_collector_latest_go121_test.go b/prometheus/go_collector_latest_go121_test.go deleted file mode 100644 index a6c3c18e9..000000000 --- a/prometheus/go_collector_latest_go121_test.go +++ /dev/null @@ -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", -} diff --git a/prometheus/go_collector_metrics_go120_test.go b/prometheus/go_collector_metrics_go120_test.go index 60517c4c2..4c1ca38d3 100644 --- a/prometheus/go_collector_metrics_go120_test.go +++ b/prometheus/go_collector_metrics_go120_test.go @@ -6,52 +6,58 @@ package prometheus -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", - "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", - "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", - "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", - "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", - "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", - "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", - "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", - "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", - "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", - "/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", - "/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", - "/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/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", - "/gc/pauses:seconds": "go_gc_pauses_seconds", - "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", - "/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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", - "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", - "/sched/latencies:seconds": "go_sched_latencies_seconds", - "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", -} +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", + "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", + "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", + "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", + "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", + "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", + "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", + "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", + "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", + "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", + "/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", + "/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", + "/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/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", + "/gc/pauses:seconds": "go_gc_pauses_seconds", + "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", + "/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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", + "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", + "/sched/latencies:seconds": "go_sched_latencies_seconds", + "/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 diff --git a/prometheus/go_collector_metrics_go121_test.go b/prometheus/go_collector_metrics_go121_test.go index 90d05bd0e..217b04fc7 100644 --- a/prometheus/go_collector_metrics_go121_test.go +++ b/prometheus/go_collector_metrics_go121_test.go @@ -6,77 +6,86 @@ package prometheus -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", - "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", - "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", - "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", - "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", - "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", - "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", - "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", - "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", - "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", - "/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/gogc:percent": "go_gc_gogc_percent", - "/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", - "/gc/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes", - "/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", - "/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/live:bytes": "go_gc_heap_live_bytes", - "/gc/heap/objects:objects": "go_gc_heap_objects_objects", - "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", - "/gc/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", - "/gc/pauses:seconds": "go_gc_pauses_seconds", - "/gc/scan/globals:bytes": "go_gc_scan_globals_bytes", - "/gc/scan/heap:bytes": "go_gc_scan_heap_bytes", - "/gc/scan/stack:bytes": "go_gc_scan_stack_bytes", - "/gc/scan/total:bytes": "go_gc_scan_total_bytes", - "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", - "/godebug/non-default-behavior/execerrdot:events": "go_godebug_non_default_behavior_execerrdot_events_total", - "/godebug/non-default-behavior/gocachehash:events": "go_godebug_non_default_behavior_gocachehash_events_total", - "/godebug/non-default-behavior/gocachetest:events": "go_godebug_non_default_behavior_gocachetest_events_total", - "/godebug/non-default-behavior/gocacheverify:events": "go_godebug_non_default_behavior_gocacheverify_events_total", - "/godebug/non-default-behavior/http2client:events": "go_godebug_non_default_behavior_http2client_events_total", - "/godebug/non-default-behavior/http2server:events": "go_godebug_non_default_behavior_http2server_events_total", - "/godebug/non-default-behavior/installgoroot:events": "go_godebug_non_default_behavior_installgoroot_events_total", - "/godebug/non-default-behavior/jstmpllitinterp:events": "go_godebug_non_default_behavior_jstmpllitinterp_events_total", - "/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/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", - "/godebug/non-default-behavior/tlsmaxrsasize:events": "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", - "/godebug/non-default-behavior/x509sha1:events": "go_godebug_non_default_behavior_x509sha1_events_total", - "/godebug/non-default-behavior/x509usefallbackroots:events": "go_godebug_non_default_behavior_x509usefallbackroots_events_total", - "/godebug/non-default-behavior/zipinsecurepath:events": "go_godebug_non_default_behavior_zipinsecurepath_events_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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", - "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", - "/sched/latencies:seconds": "go_sched_latencies_seconds", - "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", -} +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", + "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", + "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", + "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", + "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", + "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", + "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", + "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", + "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", + "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", + "/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/gogc:percent": "go_gc_gogc_percent", + "/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", + "/gc/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes", + "/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", + "/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/live:bytes": "go_gc_heap_live_bytes", + "/gc/heap/objects:objects": "go_gc_heap_objects_objects", + "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", + "/gc/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", + "/gc/pauses:seconds": "go_gc_pauses_seconds", + "/gc/scan/globals:bytes": "go_gc_scan_globals_bytes", + "/gc/scan/heap:bytes": "go_gc_scan_heap_bytes", + "/gc/scan/stack:bytes": "go_gc_scan_stack_bytes", + "/gc/scan/total:bytes": "go_gc_scan_total_bytes", + "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", + "/godebug/non-default-behavior/execerrdot:events": "go_godebug_non_default_behavior_execerrdot_events_total", + "/godebug/non-default-behavior/gocachehash:events": "go_godebug_non_default_behavior_gocachehash_events_total", + "/godebug/non-default-behavior/gocachetest:events": "go_godebug_non_default_behavior_gocachetest_events_total", + "/godebug/non-default-behavior/gocacheverify:events": "go_godebug_non_default_behavior_gocacheverify_events_total", + "/godebug/non-default-behavior/http2client:events": "go_godebug_non_default_behavior_http2client_events_total", + "/godebug/non-default-behavior/http2server:events": "go_godebug_non_default_behavior_http2server_events_total", + "/godebug/non-default-behavior/installgoroot:events": "go_godebug_non_default_behavior_installgoroot_events_total", + "/godebug/non-default-behavior/jstmpllitinterp:events": "go_godebug_non_default_behavior_jstmpllitinterp_events_total", + "/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", + "/godebug/non-default-behavior/tlsmaxrsasize:events": "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", + "/godebug/non-default-behavior/x509sha1:events": "go_godebug_non_default_behavior_x509sha1_events_total", + "/godebug/non-default-behavior/x509usefallbackroots:events": "go_godebug_non_default_behavior_x509usefallbackroots_events_total", + "/godebug/non-default-behavior/zipinsecurepath:events": "go_godebug_non_default_behavior_zipinsecurepath_events_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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", + "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", + "/sched/latencies:seconds": "go_sched_latencies_seconds", + "/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 diff --git a/prometheus/go_collector_metrics_go122_test.go b/prometheus/go_collector_metrics_go122_test.go index b40d93a60..6aa3a9f7e 100644 --- a/prometheus/go_collector_metrics_go122_test.go +++ b/prometheus/go_collector_metrics_go122_test.go @@ -6,89 +6,97 @@ package prometheus -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", - "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", - "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", - "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", - "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", - "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", - "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", - "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", - "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", - "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", - "/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/gogc:percent": "go_gc_gogc_percent", - "/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", - "/gc/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes", - "/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", - "/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/live:bytes": "go_gc_heap_live_bytes", - "/gc/heap/objects:objects": "go_gc_heap_objects_objects", - "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", - "/gc/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", - "/gc/pauses:seconds": "go_gc_pauses_seconds", - "/gc/scan/globals:bytes": "go_gc_scan_globals_bytes", - "/gc/scan/heap:bytes": "go_gc_scan_heap_bytes", - "/gc/scan/stack:bytes": "go_gc_scan_stack_bytes", - "/gc/scan/total:bytes": "go_gc_scan_total_bytes", - "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", - "/godebug/non-default-behavior/execerrdot:events": "go_godebug_non_default_behavior_execerrdot_events_total", - "/godebug/non-default-behavior/gocachehash:events": "go_godebug_non_default_behavior_gocachehash_events_total", - "/godebug/non-default-behavior/gocachetest:events": "go_godebug_non_default_behavior_gocachetest_events_total", - "/godebug/non-default-behavior/gocacheverify:events": "go_godebug_non_default_behavior_gocacheverify_events_total", - "/godebug/non-default-behavior/gotypesalias:events": "go_godebug_non_default_behavior_gotypesalias_events_total", - "/godebug/non-default-behavior/http2client:events": "go_godebug_non_default_behavior_http2client_events_total", - "/godebug/non-default-behavior/http2server:events": "go_godebug_non_default_behavior_http2server_events_total", - "/godebug/non-default-behavior/httplaxcontentlength:events": "go_godebug_non_default_behavior_httplaxcontentlength_events_total", - "/godebug/non-default-behavior/httpmuxgo121:events": "go_godebug_non_default_behavior_httpmuxgo121_events_total", - "/godebug/non-default-behavior/installgoroot:events": "go_godebug_non_default_behavior_installgoroot_events_total", - "/godebug/non-default-behavior/jstmpllitinterp:events": "go_godebug_non_default_behavior_jstmpllitinterp_events_total", - "/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", - "/godebug/non-default-behavior/tls10server:events": "go_godebug_non_default_behavior_tls10server_events_total", - "/godebug/non-default-behavior/tlsmaxrsasize:events": "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", - "/godebug/non-default-behavior/tlsrsakex:events": "go_godebug_non_default_behavior_tlsrsakex_events_total", - "/godebug/non-default-behavior/tlsunsafeekm:events": "go_godebug_non_default_behavior_tlsunsafeekm_events_total", - "/godebug/non-default-behavior/x509sha1:events": "go_godebug_non_default_behavior_x509sha1_events_total", - "/godebug/non-default-behavior/x509usefallbackroots:events": "go_godebug_non_default_behavior_x509usefallbackroots_events_total", - "/godebug/non-default-behavior/x509usepolicies:events": "go_godebug_non_default_behavior_x509usepolicies_events_total", - "/godebug/non-default-behavior/zipinsecurepath:events": "go_godebug_non_default_behavior_zipinsecurepath_events_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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", - "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", - "/sched/latencies:seconds": "go_sched_latencies_seconds", - "/sched/pauses/stopping/gc:seconds": "go_sched_pauses_stopping_gc_seconds", - "/sched/pauses/stopping/other:seconds": "go_sched_pauses_stopping_other_seconds", - "/sched/pauses/total/gc:seconds": "go_sched_pauses_total_gc_seconds", - "/sched/pauses/total/other:seconds": "go_sched_pauses_total_other_seconds", - "/sync/mutex/wait/total:seconds": "go_sync_mutex_wait_total_seconds_total", -} +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", + "/cpu/classes/gc/mark/idle:cpu-seconds": "go_cpu_classes_gc_mark_idle_cpu_seconds_total", + "/cpu/classes/gc/pause:cpu-seconds": "go_cpu_classes_gc_pause_cpu_seconds_total", + "/cpu/classes/gc/total:cpu-seconds": "go_cpu_classes_gc_total_cpu_seconds_total", + "/cpu/classes/idle:cpu-seconds": "go_cpu_classes_idle_cpu_seconds_total", + "/cpu/classes/scavenge/assist:cpu-seconds": "go_cpu_classes_scavenge_assist_cpu_seconds_total", + "/cpu/classes/scavenge/background:cpu-seconds": "go_cpu_classes_scavenge_background_cpu_seconds_total", + "/cpu/classes/scavenge/total:cpu-seconds": "go_cpu_classes_scavenge_total_cpu_seconds_total", + "/cpu/classes/total:cpu-seconds": "go_cpu_classes_total_cpu_seconds_total", + "/cpu/classes/user:cpu-seconds": "go_cpu_classes_user_cpu_seconds_total", + "/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/gogc:percent": "go_gc_gogc_percent", + "/gc/gomemlimit:bytes": "go_gc_gomemlimit_bytes", + "/gc/heap/allocs-by-size:bytes": "go_gc_heap_allocs_by_size_bytes", + "/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", + "/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/live:bytes": "go_gc_heap_live_bytes", + "/gc/heap/objects:objects": "go_gc_heap_objects_objects", + "/gc/heap/tiny/allocs:objects": "go_gc_heap_tiny_allocs_objects_total", + "/gc/limiter/last-enabled:gc-cycle": "go_gc_limiter_last_enabled_gc_cycle", + "/gc/pauses:seconds": "go_gc_pauses_seconds", + "/gc/scan/globals:bytes": "go_gc_scan_globals_bytes", + "/gc/scan/heap:bytes": "go_gc_scan_heap_bytes", + "/gc/scan/stack:bytes": "go_gc_scan_stack_bytes", + "/gc/scan/total:bytes": "go_gc_scan_total_bytes", + "/gc/stack/starting-size:bytes": "go_gc_stack_starting_size_bytes", + "/godebug/non-default-behavior/execerrdot:events": "go_godebug_non_default_behavior_execerrdot_events_total", + "/godebug/non-default-behavior/gocachehash:events": "go_godebug_non_default_behavior_gocachehash_events_total", + "/godebug/non-default-behavior/gocachetest:events": "go_godebug_non_default_behavior_gocachetest_events_total", + "/godebug/non-default-behavior/gocacheverify:events": "go_godebug_non_default_behavior_gocacheverify_events_total", + "/godebug/non-default-behavior/gotypesalias:events": "go_godebug_non_default_behavior_gotypesalias_events_total", + "/godebug/non-default-behavior/http2client:events": "go_godebug_non_default_behavior_http2client_events_total", + "/godebug/non-default-behavior/http2server:events": "go_godebug_non_default_behavior_http2server_events_total", + "/godebug/non-default-behavior/httplaxcontentlength:events": "go_godebug_non_default_behavior_httplaxcontentlength_events_total", + "/godebug/non-default-behavior/httpmuxgo121:events": "go_godebug_non_default_behavior_httpmuxgo121_events_total", + "/godebug/non-default-behavior/installgoroot:events": "go_godebug_non_default_behavior_installgoroot_events_total", + "/godebug/non-default-behavior/jstmpllitinterp:events": "go_godebug_non_default_behavior_jstmpllitinterp_events_total", + "/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", + "/godebug/non-default-behavior/tls10server:events": "go_godebug_non_default_behavior_tls10server_events_total", + "/godebug/non-default-behavior/tlsmaxrsasize:events": "go_godebug_non_default_behavior_tlsmaxrsasize_events_total", + "/godebug/non-default-behavior/tlsrsakex:events": "go_godebug_non_default_behavior_tlsrsakex_events_total", + "/godebug/non-default-behavior/tlsunsafeekm:events": "go_godebug_non_default_behavior_tlsunsafeekm_events_total", + "/godebug/non-default-behavior/x509sha1:events": "go_godebug_non_default_behavior_x509sha1_events_total", + "/godebug/non-default-behavior/x509usefallbackroots:events": "go_godebug_non_default_behavior_x509usefallbackroots_events_total", + "/godebug/non-default-behavior/x509usepolicies:events": "go_godebug_non_default_behavior_x509usepolicies_events_total", + "/godebug/non-default-behavior/zipinsecurepath:events": "go_godebug_non_default_behavior_zipinsecurepath_events_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/gomaxprocs:threads": "go_sched_gomaxprocs_threads", + "/sched/goroutines:goroutines": "go_sched_goroutines_goroutines", + "/sched/latencies:seconds": "go_sched_latencies_seconds", + "/sched/pauses/stopping/gc:seconds": "go_sched_pauses_stopping_gc_seconds", + "/sched/pauses/stopping/other:seconds": "go_sched_pauses_stopping_other_seconds", + "/sched/pauses/total/gc:seconds": "go_sched_pauses_total_gc_seconds", + "/sched/pauses/total/other:seconds": "go_sched_pauses_total_other_seconds", + "/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 diff --git a/prometheus/internal/go_collector_options.go b/prometheus/internal/go_collector_options.go index 723b45d64..a4fa6eabd 100644 --- a/prometheus/internal/go_collector_options.go +++ b/prometheus/internal/go_collector_options.go @@ -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`) From 4a2cb158382bcb2831ef1b7adb85aa53a0c207c8 Mon Sep 17 00:00:00 2001 From: Arianna Vespri Date: Fri, 9 Aug 2024 14:28:17 +0200 Subject: [PATCH 13/13] Use default GoCollector func in test Signed-off-by: Arianna Vespri --- prometheus/go_collector_latest_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/prometheus/go_collector_latest_test.go b/prometheus/go_collector_latest_test.go index cde7a2d77..2fbe01bae 100644 --- a/prometheus/go_collector_latest_test.go +++ b/prometheus/go_collector_latest_test.go @@ -94,11 +94,7 @@ func TestGoCollector_ExposedMetrics(t *testing.T) { }, { // Default, only MemStats and default Runtime metrics. - opts: internal.GoCollectorOptions{ - RuntimeMetricRules: []internal.GoCollectorRule{ - {Matcher: regexp.MustCompile(`\/gc\/gogc:percent|\/gc\/gomemlimit:bytes|\/sched\/gomaxprocs:threads`)}, - }, - }, + opts: defaultGoCollectorOptions(), expectedFQNameSet: addExpectedDefaultRuntimeMetrics(addExpectedRuntimeMemStats(expectedBaseMetrics())), }, {