...

Source file src/edge-infra.dev/pkg/k8s/runtime/controller/metrics/options.go

Documentation: edge-infra.dev/pkg/k8s/runtime/controller/metrics

     1  package metrics
     2  
     3  import "github.com/prometheus/client_golang/prometheus"
     4  
     5  // Option is the functional interface that is used to provide public options for
     6  // creating metrics structs.
     7  type Option func(*options)
     8  
     9  // WithCollectors adds custom collectors in addition to the built in controller
    10  // metrics.
    11  func WithCollectors(c ...prometheus.Collector) Option {
    12  	return func(o *options) {
    13  		o.customCollectors = c
    14  	}
    15  }
    16  
    17  // WithSuspend adds a collector for recording an objects suspension status via
    18  // Metrics.RecordSuspend()
    19  func WithSuspend() Option {
    20  	return func(o *options) {
    21  		o.suspend = true
    22  	}
    23  }
    24  
    25  // WithReason adds the `reason` label to the reconcile_condition_status gauge
    26  func WithReason() Option {
    27  	return func(o *options) {
    28  		o.reason = true
    29  	}
    30  }
    31  
    32  type options struct {
    33  	// whether or not to add the gauge for recording object suspension
    34  	suspend bool
    35  	// whether or not to use the `reason` label in reconcile_condition_status
    36  	reason           bool
    37  	customCollectors []prometheus.Collector
    38  }
    39  
    40  func makeOptions(opts ...Option) *options {
    41  	o := &options{customCollectors: []prometheus.Collector{}}
    42  	for _, opt := range opts {
    43  		opt(o)
    44  	}
    45  
    46  	return o
    47  }
    48  

View as plain text