Skip to content

Commit 1495848

Browse files
committed
gocollector: Added options to Go Collector for changing the
Fixes #983 Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
1 parent 130da3b commit 1495848

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

prometheus/collectors/go_collector.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ package collectors
1515

1616
import "github.com/prometheus/client_golang/prometheus"
1717

18+
type goCollectorOption func(o *prometheus.GoCollectorOptions)
19+
20+
func WithTBD() goCollectorOption {
21+
return func(o *prometheus.GoCollectorOptions) {
22+
o.TBD = true
23+
}
24+
}
25+
1826
// NewGoCollector returns a collector that exports metrics about the current Go
1927
// process. This includes memory stats. To collect those, runtime.ReadMemStats
2028
// is called. This requires to “stop the world”, which usually only happens for
@@ -41,9 +49,9 @@ import "github.com/prometheus/client_golang/prometheus"
4149
//
4250
// NOTE: The problem is solved in Go 1.15, see
4351
// https://github.com/golang/go/issues/19812 for the related Go issue.
44-
func NewGoCollector() prometheus.Collector {
52+
func NewGoCollector(opts ...prometheus.GoCollectorOption) prometheus.Collector {
4553
//nolint:staticcheck // Ignore SA1019 until v2.
46-
return prometheus.NewGoCollector()
54+
return prometheus.NewGoCollector(opts...)
4755
}
4856

4957
// NewBuildInfoCollector returns a collector collecting a single metric

prometheus/go_collector_go117.go renamed to prometheus/go_collector_latest.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,22 @@ type goCollector struct {
5151
msMetrics memStatsMetrics
5252
}
5353

54+
type GoCollectorOption func(o *GoCollectorOptions)
55+
56+
// GoCollectorOptions should not used be directly by anyone, except `collectors` package.
57+
// Use it via collectors package instead. See issue why it exists in this package
58+
// https://github.com/prometheus/client_golang/issues/1030.
59+
//
60+
// Deprecated: Use collectors.With
61+
type GoCollectorOptions struct {
62+
TBD bool
63+
}
64+
5465
// NewGoCollector is the obsolete version of collectors.NewGoCollector.
5566
// See there for documentation.
5667
//
5768
// Deprecated: Use collectors.NewGoCollector instead.
58-
func NewGoCollector() Collector {
69+
func NewGoCollector(opts ...GoCollectorOption) Collector {
5970
descriptions := metrics.All()
6071

6172
// Collect all histogram samples so that we can get their buckets.

0 commit comments

Comments
 (0)