github.com/rudderlabs/rudder-go-kit@v0.30.0/stats/options.go (about)

     1  package stats
     2  
     3  import (
     4  	"sync/atomic"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  )
     8  
     9  type statsConfig struct {
    10  	enabled             *atomic.Bool
    11  	serviceName         string
    12  	serviceVersion      string
    13  	instanceName        string
    14  	namespaceIdentifier string
    15  	excludedTags        map[string]struct{}
    16  
    17  	periodicStatsConfig     periodicStatsConfig
    18  	defaultHistogramBuckets []float64
    19  	histogramBuckets        map[string][]float64
    20  	prometheusRegisterer    prometheus.Registerer
    21  	prometheusGatherer      prometheus.Gatherer
    22  }
    23  
    24  // Option is a function used to configure the stats service.
    25  type Option func(*statsConfig)
    26  
    27  // WithServiceName sets the service name for the stats service.
    28  func WithServiceName(name string) Option {
    29  	return func(c *statsConfig) {
    30  		c.serviceName = name
    31  	}
    32  }
    33  
    34  // WithServiceVersion sets the service version for the stats service.
    35  func WithServiceVersion(version string) Option {
    36  	return func(c *statsConfig) {
    37  		c.serviceVersion = version
    38  	}
    39  }
    40  
    41  // WithDefaultHistogramBuckets sets the histogram buckets for the stats service.
    42  func WithDefaultHistogramBuckets(buckets []float64) Option {
    43  	return func(c *statsConfig) {
    44  		c.defaultHistogramBuckets = buckets
    45  	}
    46  }
    47  
    48  // WithHistogramBuckets sets the histogram buckets for a measurement.
    49  func WithHistogramBuckets(histogramName string, buckets []float64) Option {
    50  	return func(c *statsConfig) {
    51  		if c.histogramBuckets == nil {
    52  			c.histogramBuckets = make(map[string][]float64)
    53  		}
    54  		c.histogramBuckets[histogramName] = buckets
    55  	}
    56  }
    57  
    58  // WithPrometheusRegistry sets the prometheus registerer and gatherer for the stats service.
    59  // If nil is passed the default ones will be used.
    60  func WithPrometheusRegistry(registerer prometheus.Registerer, gatherer prometheus.Gatherer) Option {
    61  	return func(c *statsConfig) {
    62  		c.prometheusRegisterer = registerer
    63  		c.prometheusGatherer = gatherer
    64  	}
    65  }