Expose rules.NewGroupMetrics and rules.Metrics. (#5059)

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
Tom Wilkie 2019-01-03 12:07:06 +00:00 committed by GitHub
parent 6e08029b56
commit 121603c417
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
}