Skip to content

Commit 881c608

Browse files
authored
Added compatibility mode with old options. (#1107)
* Added compatibility mode with old options. Signed-off-by: bwplotka <[email protected]> * Copyright header. Signed-off-by: bwplotka <[email protected]>
1 parent b94d7e2 commit 881c608

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

prometheus/collectors/go_collector_latest.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,36 @@ func WithoutGoCollectorRuntimeMetrics(matchers ...*regexp.Regexp) func(options *
109109
}
110110
}
111111

112+
// GoCollectionOption represents Go collection option flag.
113+
// Deprecated.
114+
type GoCollectionOption uint32
115+
116+
const (
117+
// GoRuntimeMemStatsCollection represents the metrics represented by runtime.MemStats structure.
118+
// Deprecated. Use WithGoCollectorMemStatsMetricsDisabled() function to disable those metrics in the collector.
119+
GoRuntimeMemStatsCollection GoCollectionOption = 1 << iota
120+
// GoRuntimeMetricsCollection is the new set of metrics represented by runtime/metrics package.
121+
// Deprecated. Use WithGoCollectorRuntimeMetrics(GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")})
122+
// function to enable those metrics in the collector.
123+
GoRuntimeMetricsCollection
124+
)
125+
126+
// WithGoCollections allows enabling different collections for Go collector on top of base metrics.
127+
// Deprecated. Use WithGoCollectorRuntimeMetrics() and WithGoCollectorMemStatsMetricsDisabled() instead to control metrics.
128+
func WithGoCollections(flags GoCollectionOption) func(options *internal.GoCollectorOptions) {
129+
return func(options *internal.GoCollectorOptions) {
130+
if flags&GoRuntimeMemStatsCollection == 0 {
131+
WithGoCollectorMemStatsMetricsDisabled()(options)
132+
}
133+
134+
if flags&GoRuntimeMetricsCollection != 0 {
135+
WithGoCollectorRuntimeMetrics(GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")})(options)
136+
}
137+
}
138+
}
139+
112140
// NewGoCollector returns a collector that exports metrics about the current Go
113-
// process using debug.GCStats and runtime/metrics.
141+
// process using debug.GCStats (base metrics) and runtime/metrics (both in MemStats style and new ones).
114142
func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) prometheus.Collector {
115143
//nolint:staticcheck // Ignore SA1019 until v2.
116144
return prometheus.NewGoCollector(opts...)

prometheus/internal/go_collector_options.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
// Copyright 2021 The Prometheus Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
114
package internal
215

316
import "regexp"

0 commit comments

Comments
 (0)