Skip to content

Commit

Permalink
Added compatibility mode with old options.
Browse files Browse the repository at this point in the history
Signed-off-by: bwplotka <[email protected]>
  • Loading branch information
bwplotka committed Aug 5, 2022
1 parent b94d7e2 commit 923b9e7
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion prometheus/collectors/go_collector_latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,38 @@ func WithoutGoCollectorRuntimeMetrics(matchers ...*regexp.Regexp) func(options *
}
}

// GoCollectionOption represents Go collection option flag.
// Deprecated.
type GoCollectionOption uint32

const (
// GoRuntimeMemStatsCollection represents the metrics represented by runtime.MemStats structure.
// Deprecated. Use WithGoCollectorMemStatsMetricsDisabled() function to disable those metrics in the collector.
GoRuntimeMemStatsCollection GoCollectionOption = 1 << iota
// GoRuntimeMetricsCollection is the new set of metrics represented by runtime/metrics package.
// Deprecated. Use WithGoCollectorRuntimeMetrics(GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")})
// function to enable those metrics in the collector.
GoRuntimeMetricsCollection
)

// WithGoCollections allows enabling different collections for Go collector on top of base metrics.
// Deprecated. Use WithGoCollectorRuntimeMetrics() and WithGoCollectorMemStatsMetricsDisabled() instead to control metrics.
func WithGoCollections(flags GoCollectionOption) func(options *internal.GoCollectorOptions) {
return func(options *internal.GoCollectorOptions) {
//nolint:staticcheck // Ignore SA1019 until v2.
if flags&GoRuntimeMemStatsCollection == 0 {
WithGoCollectorMemStatsMetricsDisabled()(options)
}

//nolint:staticcheck // Ignore SA1019 until v2.
if flags&GoRuntimeMetricsCollection != 0 {
WithGoCollectorRuntimeMetrics(GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")})(options)
}
}
}

// NewGoCollector returns a collector that exports metrics about the current Go
// process using debug.GCStats and runtime/metrics.
// process using debug.GCStats (base metrics) and runtime/metrics (both in MemStats style and new ones).
func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) prometheus.Collector {
//nolint:staticcheck // Ignore SA1019 until v2.
return prometheus.NewGoCollector(opts...)
Expand Down

0 comments on commit 923b9e7

Please sign in to comment.