rules: Minor naming/comment cleanups (#4328)

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2018-07-18 05:54:33 +02:00 committed by Brian Brazil
parent 3ee7a6a6c2
commit 9e3171f6e3
4 changed files with 34 additions and 35 deletions

View file

@ -102,7 +102,7 @@ type AlertingRule struct {
// Non-identifying key/value pairs. // Non-identifying key/value pairs.
annotations labels.Labels annotations labels.Labels
// Time in seconds taken to evaluate rule. // Time in seconds taken to evaluate rule.
evaluationTime time.Duration evaluationDuration time.Duration
// Protects the below. // Protects the below.
mtx sync.Mutex mtx sync.Mutex
@ -153,18 +153,18 @@ func (r *AlertingRule) sample(alert *Alert, ts time.Time) promql.Sample {
return s return s
} }
// SetEvaluationTime updates evaluationTime to the duration it took to evaluate the rule on its last evaluation. // SetEvaluationDuration updates evaluationDuration to the duration it took to evaluate the rule on its last evaluation.
func (r *AlertingRule) SetEvaluationTime(dur time.Duration) { func (r *AlertingRule) SetEvaluationDuration(dur time.Duration) {
r.mtx.Lock() r.mtx.Lock()
defer r.mtx.Unlock() defer r.mtx.Unlock()
r.evaluationTime = dur r.evaluationDuration = dur
} }
// GetEvaluationTime returns the time in seconds it took to evaluate the alerting rule. // GetEvaluationDuration returns the time in seconds it took to evaluate the alerting rule.
func (r *AlertingRule) GetEvaluationTime() time.Duration { func (r *AlertingRule) GetEvaluationDuration() time.Duration {
r.mtx.Lock() r.mtx.Lock()
defer r.mtx.Unlock() defer r.mtx.Unlock()
return r.evaluationTime return r.evaluationDuration
} }
// resolvedRetention is the duration for which a resolved alert instance // resolvedRetention is the duration for which a resolved alert instance

View file

@ -106,7 +106,7 @@ type QueryFunc func(ctx context.Context, q string, t time.Time) (promql.Vector,
// EngineQueryFunc returns a new query function that executes instant queries against // EngineQueryFunc returns a new query function that executes instant queries against
// the given engine. // the given engine.
// It converts scaler into vector results. // It converts scalar into vector results.
func EngineQueryFunc(engine *promql.Engine, q storage.Queryable) QueryFunc { func EngineQueryFunc(engine *promql.Engine, q storage.Queryable) QueryFunc {
return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) { return func(ctx context.Context, qs string, t time.Time) (promql.Vector, error) {
q, err := engine.NewInstantQuery(q, qs, t) q, err := engine.NewInstantQuery(q, qs, t)
@ -140,8 +140,8 @@ type Rule interface {
// String returns a human-readable string representation of the rule. // String returns a human-readable string representation of the rule.
String() string String() string
SetEvaluationTime(time.Duration) SetEvaluationDuration(time.Duration)
GetEvaluationTime() time.Duration GetEvaluationDuration() time.Duration
// HTMLSnippet returns a human-readable string representation of the rule, // HTMLSnippet returns a human-readable string representation of the rule,
// decorated with HTML elements for use the web frontend. // decorated with HTML elements for use the web frontend.
HTMLSnippet(pathPrefix string) html_template.HTML HTMLSnippet(pathPrefix string) html_template.HTML
@ -155,7 +155,7 @@ type Group struct {
rules []Rule rules []Rule
seriesInPreviousEval []map[string]labels.Labels // One per Rule. seriesInPreviousEval []map[string]labels.Labels // One per Rule.
opts *ManagerOptions opts *ManagerOptions
evaluationTime time.Duration evaluationDuration time.Duration
mtx sync.Mutex mtx sync.Mutex
done chan struct{} done chan struct{}
@ -207,7 +207,7 @@ func (g *Group) run(ctx context.Context) {
timeSinceStart := time.Since(start) timeSinceStart := time.Since(start)
iterationDuration.Observe(timeSinceStart.Seconds()) iterationDuration.Observe(timeSinceStart.Seconds())
g.SetEvaluationTime(timeSinceStart) g.SetEvaluationDuration(timeSinceStart)
} }
// The assumption here is that since the ticker was started after having // The assumption here is that since the ticker was started after having
@ -251,18 +251,18 @@ func (g *Group) hash() uint64 {
return l.Hash() return l.Hash()
} }
// GetEvaluationTime returns the time in seconds it took to evaluate the rule group. // GetEvaluationDuration returns the time in seconds it took to evaluate the rule group.
func (g *Group) GetEvaluationTime() time.Duration { func (g *Group) GetEvaluationDuration() time.Duration {
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
return g.evaluationTime return g.evaluationDuration
} }
// SetEvaluationTime sets the time in seconds the last evaluation took. // SetEvaluationDuration sets the time in seconds the last evaluation took.
func (g *Group) SetEvaluationTime(dur time.Duration) { func (g *Group) SetEvaluationDuration(dur time.Duration) {
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
g.evaluationTime = dur g.evaluationDuration = dur
} }
// evalTimestamp returns the immediately preceding consistently slotted evaluation time. // evalTimestamp returns the immediately preceding consistently slotted evaluation time.
@ -282,7 +282,7 @@ func (g *Group) evalTimestamp() time.Time {
// Rules are matched based on their name. If there are duplicates, the // Rules are matched based on their name. If there are duplicates, the
// first is matched with the first, second with the second etc. // first is matched with the first, second with the second etc.
func (g *Group) copyState(from *Group) { func (g *Group) copyState(from *Group) {
g.evaluationTime = from.evaluationTime g.evaluationDuration = from.evaluationDuration
ruleMap := make(map[string][]int, len(from.rules)) ruleMap := make(map[string][]int, len(from.rules))
@ -330,7 +330,7 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) {
defer func(t time.Time) { defer func(t time.Time) {
sp.Finish() sp.Finish()
evalDuration.Observe(time.Since(t).Seconds()) evalDuration.Observe(time.Since(t).Seconds())
rule.SetEvaluationTime(time.Since(t)) rule.SetEvaluationDuration(time.Since(t))
}(time.Now()) }(time.Now())
evalTotal.Inc() evalTotal.Inc()
@ -476,7 +476,6 @@ func (m *Manager) Update(interval time.Duration, files []string) error {
m.mtx.Lock() m.mtx.Lock()
defer m.mtx.Unlock() defer m.mtx.Unlock()
// To be replaced with a configurable per-group interval.
groups, errs := m.loadGroups(interval, files...) groups, errs := m.loadGroups(interval, files...)
if errs != nil { if errs != nil {
for _, e := range errs { for _, e := range errs {
@ -633,7 +632,7 @@ func (m *Manager) Collect(ch chan<- prometheus.Metric) {
for _, g := range m.RuleGroups() { for _, g := range m.RuleGroups() {
ch <- prometheus.MustNewConstMetric(lastDuration, ch <- prometheus.MustNewConstMetric(lastDuration,
prometheus.GaugeValue, prometheus.GaugeValue,
g.GetEvaluationTime().Seconds(), g.GetEvaluationDuration().Seconds(),
groupKey(g.file, g.name)) groupKey(g.file, g.name))
} }
for _, g := range m.RuleGroups() { for _, g := range m.RuleGroups() {

View file

@ -257,7 +257,7 @@ func TestCopyState(t *testing.T) {
map[string]labels.Labels{"r3a": nil}, map[string]labels.Labels{"r3a": nil},
map[string]labels.Labels{"r3b": nil}, map[string]labels.Labels{"r3b": nil},
}, },
evaluationTime: time.Second, evaluationDuration: time.Second,
} }
oldGroup.rules[0].(*AlertingRule).active[42] = nil oldGroup.rules[0].(*AlertingRule).active[42] = nil
newGroup := &Group{ newGroup := &Group{
@ -283,7 +283,7 @@ func TestCopyState(t *testing.T) {
} }
testutil.Equals(t, want, newGroup.seriesInPreviousEval) testutil.Equals(t, want, newGroup.seriesInPreviousEval)
testutil.Equals(t, oldGroup.rules[0], newGroup.rules[3]) testutil.Equals(t, oldGroup.rules[0], newGroup.rules[3])
testutil.Equals(t, oldGroup.evaluationTime, newGroup.evaluationTime) testutil.Equals(t, oldGroup.evaluationDuration, newGroup.evaluationDuration)
} }
func TestUpdate(t *testing.T) { func TestUpdate(t *testing.T) {

View file

@ -35,7 +35,7 @@ type RecordingRule struct {
vector promql.Expr vector promql.Expr
labels labels.Labels labels labels.Labels
mtx sync.Mutex mtx sync.Mutex
evaluationTime time.Duration evaluationDuration time.Duration
} }
// NewRecordingRule returns a new recording rule. // NewRecordingRule returns a new recording rule.
@ -95,18 +95,18 @@ func (rule *RecordingRule) String() string {
return string(byt) return string(byt)
} }
// SetEvaluationTime updates evaluationTimeSeconds to the time in seconds it took to evaluate the rule on its last evaluation. // SetEvaluationDuration updates evaluationDuration to the time in seconds it took to evaluate the rule on its last evaluation.
func (rule *RecordingRule) SetEvaluationTime(dur time.Duration) { func (rule *RecordingRule) SetEvaluationDuration(dur time.Duration) {
rule.mtx.Lock() rule.mtx.Lock()
defer rule.mtx.Unlock() defer rule.mtx.Unlock()
rule.evaluationTime = dur rule.evaluationDuration = dur
} }
// GetEvaluationTime returns the time in seconds it took to evaluate the recording rule. // GetEvaluationDuration returns the time in seconds it took to evaluate the recording rule.
func (rule *RecordingRule) GetEvaluationTime() time.Duration { func (rule *RecordingRule) GetEvaluationDuration() time.Duration {
rule.mtx.Lock() rule.mtx.Lock()
defer rule.mtx.Unlock() defer rule.mtx.Unlock()
return rule.evaluationTime return rule.evaluationDuration
} }
// HTMLSnippet returns an HTML snippet representing this rule. // HTMLSnippet returns an HTML snippet representing this rule.