diff --git a/rules/manager.go b/rules/manager.go index e6cf35f90..99477b4a2 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -61,7 +61,8 @@ var ( ) ) -type metrics struct { +// Metrics for rule evaluation. +type Metrics struct { evalDuration prometheus.Summary evalFailures prometheus.Counter evalTotal prometheus.Counter @@ -72,8 +73,10 @@ type metrics struct { groupLastDuration *prometheus.GaugeVec } -func newGroupMetrics(reg prometheus.Registerer) *metrics { - m := &metrics{ +// NewGroupMetrics makes a new Metrics and registers them with then provided registerer, +// if not nil. +func NewGroupMetrics(reg prometheus.Registerer) *Metrics { + m := &Metrics{ evalDuration: prometheus.NewSummary( prometheus.SummaryOpts{ Namespace: namespace, @@ -220,14 +223,14 @@ type Group struct { logger log.Logger - metrics *metrics + metrics *Metrics } // NewGroup makes a new Group with the given name, options, and rules. func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRestore bool, opts *ManagerOptions) *Group { - metrics := opts.metrics + metrics := opts.Metrics if metrics == nil { - metrics = newGroupMetrics(opts.Registerer) + metrics = NewGroupMetrics(opts.Registerer) } metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name)) @@ -684,14 +687,14 @@ type ManagerOptions struct { ForGracePeriod time.Duration ResendDelay time.Duration - metrics *metrics + Metrics *Metrics } // NewManager returns an implementation of Manager, ready to be started // by calling the Run method. func NewManager(o *ManagerOptions) *Manager { - if o.metrics == nil { - o.metrics = newGroupMetrics(o.Registerer) + if o.Metrics == nil { + o.Metrics = NewGroupMetrics(o.Registerer) } m := &Manager{ @@ -705,7 +708,7 @@ func NewManager(o *ManagerOptions) *Manager { o.Registerer.MustRegister(m) } - o.metrics.iterationsMissed.Inc() + o.Metrics.iterationsMissed.Inc() return m }