Skip to content

Commit

Permalink
gocollector: Added options to Go Collector for changing the
Browse files Browse the repository at this point in the history
Fixes #983

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Apr 12, 2022
1 parent 130da3b commit 1495848
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 10 additions & 2 deletions prometheus/collectors/go_collector.go
Expand Up @@ -15,6 +15,14 @@ package collectors

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

type goCollectorOption func(o *prometheus.GoCollectorOptions)

func WithTBD() goCollectorOption {
return func(o *prometheus.GoCollectorOptions) {
o.TBD = true
}
}

// NewGoCollector returns a collector that exports metrics about the current Go
// process. This includes memory stats. To collect those, runtime.ReadMemStats
// is called. This requires to “stop the world”, which usually only happens for
Expand All @@ -41,9 +49,9 @@ import "github.com/prometheus/client_golang/prometheus"
//
// NOTE: The problem is solved in Go 1.15, see
// https://github.com/golang/go/issues/19812 for the related Go issue.
func NewGoCollector() prometheus.Collector {
func NewGoCollector(opts ...prometheus.GoCollectorOption) prometheus.Collector {
//nolint:staticcheck // Ignore SA1019 until v2.
return prometheus.NewGoCollector()
return prometheus.NewGoCollector(opts...)
}

// NewBuildInfoCollector returns a collector collecting a single metric
Expand Down
Expand Up @@ -51,11 +51,22 @@ type goCollector struct {
msMetrics memStatsMetrics
}

type GoCollectorOption func(o *GoCollectorOptions)

// GoCollectorOptions should not used be directly by anyone, except `collectors` package.
// Use it via collectors package instead. See issue why it exists in this package
// https://github.com/prometheus/client_golang/issues/1030.
//
// Deprecated: Use collectors.With
type GoCollectorOptions struct {
TBD bool
}

// NewGoCollector is the obsolete version of collectors.NewGoCollector.
// See there for documentation.
//
// Deprecated: Use collectors.NewGoCollector instead.
func NewGoCollector() Collector {
func NewGoCollector(opts ...GoCollectorOption) Collector {
descriptions := metrics.All()

// Collect all histogram samples so that we can get their buckets.
Expand Down
File renamed without changes.

0 comments on commit 1495848

Please sign in to comment.