From 2f2a51a43a011c4a12b0c2c0b31b1a742ce76c7a Mon Sep 17 00:00:00 2001 From: johncming Date: Tue, 25 Aug 2020 18:38:06 +0800 Subject: [PATCH] web/api/v1: make names consistent. (#7841) Signed-off-by: johncming --- rules/manager.go | 36 ++++++++++++++++++------------------ rules/manager_test.go | 6 +++--- web/api/v1/api.go | 4 ++-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/rules/manager.go b/rules/manager.go index 8c24485ca..b3a60c828 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -237,8 +237,8 @@ type Group struct { staleSeries []labels.Labels opts *ManagerOptions mtx sync.Mutex - evaluationDuration time.Duration - evaluationTimestamp time.Time + evaluationTime time.Duration + lastEvaluation time.Time shouldRestore bool @@ -332,8 +332,8 @@ func (g *Group) run(ctx context.Context) { timeSinceStart := time.Since(start) g.metrics.iterationDuration.Observe(timeSinceStart.Seconds()) - g.setEvaluationDuration(timeSinceStart) - g.setEvaluationTimestamp(start) + g.setEvaluationTime(timeSinceStart) + g.setLastEvaluation(start) } // The assumption here is that since the ticker was started after having @@ -454,36 +454,36 @@ func (g *Group) HasAlertingRules() bool { return false } -// GetEvaluationDuration returns the time in seconds it took to evaluate the rule group. -func (g *Group) GetEvaluationDuration() time.Duration { +// GetEvaluationTime returns the time in seconds it took to evaluate the rule group. +func (g *Group) GetEvaluationTime() time.Duration { g.mtx.Lock() defer g.mtx.Unlock() - return g.evaluationDuration + return g.evaluationTime } -// setEvaluationDuration sets the time in seconds the last evaluation took. -func (g *Group) setEvaluationDuration(dur time.Duration) { +// setEvaluationTime sets the time in seconds the last evaluation took. +func (g *Group) setEvaluationTime(dur time.Duration) { g.metrics.groupLastDuration.WithLabelValues(groupKey(g.file, g.name)).Set(dur.Seconds()) g.mtx.Lock() defer g.mtx.Unlock() - g.evaluationDuration = dur + g.evaluationTime = dur } -// GetEvaluationTimestamp returns the time the last evaluation of the rule group took place. -func (g *Group) GetEvaluationTimestamp() time.Time { +// GetLastEvaluation returns the time the last evaluation of the rule group took place. +func (g *Group) GetLastEvaluation() time.Time { g.mtx.Lock() defer g.mtx.Unlock() - return g.evaluationTimestamp + return g.lastEvaluation } -// setEvaluationTimestamp updates evaluationTimestamp to the timestamp of when the rule group was last evaluated. -func (g *Group) setEvaluationTimestamp(ts time.Time) { +// setLastEvaluation updates lastEvaluation to the timestamp of when the rule group was last evaluated. +func (g *Group) setLastEvaluation(ts time.Time) { g.metrics.groupLastEvalTime.WithLabelValues(groupKey(g.file, g.name)).Set(float64(ts.UnixNano()) / 1e9) g.mtx.Lock() defer g.mtx.Unlock() - g.evaluationTimestamp = ts + g.lastEvaluation = ts } // evalTimestamp returns the immediately preceding consistently slotted evaluation time. @@ -507,8 +507,8 @@ func nameAndLabels(rule Rule) string { // Rules are matched based on their name and labels. If there are duplicates, the // first is matched with the first, second with the second etc. func (g *Group) CopyState(from *Group) { - g.evaluationDuration = from.evaluationDuration - g.evaluationTimestamp = from.evaluationTimestamp + g.evaluationTime = from.evaluationTime + g.lastEvaluation = from.lastEvaluation ruleMap := make(map[string][]int, len(from.rules)) diff --git a/rules/manager_test.go b/rules/manager_test.go index e9deb70ad..93e9cc8ba 100644 --- a/rules/manager_test.go +++ b/rules/manager_test.go @@ -626,7 +626,7 @@ func TestCopyState(t *testing.T) { {"r3c": labels.Labels{{Name: "l1", Value: "v3"}}}, {"a2": labels.Labels{{Name: "l2", Value: "v1"}}}, }, - evaluationDuration: time.Second, + evaluationTime: time.Second, } oldGroup.rules[0].(*AlertingRule).active[42] = nil newGroup := &Group{ @@ -656,8 +656,8 @@ func TestCopyState(t *testing.T) { } testutil.Equals(t, want, newGroup.seriesInPreviousEval) testutil.Equals(t, oldGroup.rules[0], newGroup.rules[3]) - testutil.Equals(t, oldGroup.evaluationDuration, newGroup.evaluationDuration) - testutil.Equals(t, oldGroup.evaluationTimestamp, newGroup.evaluationTimestamp) + testutil.Equals(t, oldGroup.evaluationTime, newGroup.evaluationTime) + testutil.Equals(t, oldGroup.lastEvaluation, newGroup.lastEvaluation) testutil.Equals(t, []labels.Labels{{{Name: "l1", Value: "v3"}}}, newGroup.staleSeries) } diff --git a/web/api/v1/api.go b/web/api/v1/api.go index cc64ab498..4bd00c176 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -1063,8 +1063,8 @@ func (api *API) rules(r *http.Request) apiFuncResult { File: grp.File(), Interval: grp.Interval().Seconds(), Rules: []rule{}, - EvaluationTime: grp.GetEvaluationDuration().Seconds(), - LastEvaluation: grp.GetEvaluationTimestamp(), + EvaluationTime: grp.GetEvaluationTime().Seconds(), + LastEvaluation: grp.GetLastEvaluation(), } for _, r := range grp.Rules() { var enrichedRule rule