Expose rules.NewGroupMetrics and rules.Metrics. (#5059)
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
parent
6e08029b56
commit
121603c417
|
@ -61,7 +61,8 @@ var (
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
type metrics struct {
|
// Metrics for rule evaluation.
|
||||||
|
type Metrics struct {
|
||||||
evalDuration prometheus.Summary
|
evalDuration prometheus.Summary
|
||||||
evalFailures prometheus.Counter
|
evalFailures prometheus.Counter
|
||||||
evalTotal prometheus.Counter
|
evalTotal prometheus.Counter
|
||||||
|
@ -72,8 +73,10 @@ type metrics struct {
|
||||||
groupLastDuration *prometheus.GaugeVec
|
groupLastDuration *prometheus.GaugeVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGroupMetrics(reg prometheus.Registerer) *metrics {
|
// NewGroupMetrics makes a new Metrics and registers them with then provided registerer,
|
||||||
m := &metrics{
|
// if not nil.
|
||||||
|
func NewGroupMetrics(reg prometheus.Registerer) *Metrics {
|
||||||
|
m := &Metrics{
|
||||||
evalDuration: prometheus.NewSummary(
|
evalDuration: prometheus.NewSummary(
|
||||||
prometheus.SummaryOpts{
|
prometheus.SummaryOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@ -220,14 +223,14 @@ type Group struct {
|
||||||
|
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
metrics *metrics
|
metrics *Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGroup makes a new Group with the given name, options, and rules.
|
// 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 {
|
func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRestore bool, opts *ManagerOptions) *Group {
|
||||||
metrics := opts.metrics
|
metrics := opts.Metrics
|
||||||
if metrics == nil {
|
if metrics == nil {
|
||||||
metrics = newGroupMetrics(opts.Registerer)
|
metrics = NewGroupMetrics(opts.Registerer)
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name))
|
metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name))
|
||||||
|
@ -684,14 +687,14 @@ type ManagerOptions struct {
|
||||||
ForGracePeriod time.Duration
|
ForGracePeriod time.Duration
|
||||||
ResendDelay time.Duration
|
ResendDelay time.Duration
|
||||||
|
|
||||||
metrics *metrics
|
Metrics *Metrics
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns an implementation of Manager, ready to be started
|
// NewManager returns an implementation of Manager, ready to be started
|
||||||
// by calling the Run method.
|
// by calling the Run method.
|
||||||
func NewManager(o *ManagerOptions) *Manager {
|
func NewManager(o *ManagerOptions) *Manager {
|
||||||
if o.metrics == nil {
|
if o.Metrics == nil {
|
||||||
o.metrics = newGroupMetrics(o.Registerer)
|
o.Metrics = NewGroupMetrics(o.Registerer)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := &Manager{
|
m := &Manager{
|
||||||
|
@ -705,7 +708,7 @@ func NewManager(o *ManagerOptions) *Manager {
|
||||||
o.Registerer.MustRegister(m)
|
o.Registerer.MustRegister(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
o.metrics.iterationsMissed.Inc()
|
o.Metrics.iterationsMissed.Inc()
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue