web/api/v1: make names consistent. (#7841)

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2020-08-25 18:38:06 +08:00 committed by GitHub
parent 442b3364d7
commit 2f2a51a43a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 23 deletions

View file

@ -237,8 +237,8 @@ type Group struct {
staleSeries []labels.Labels staleSeries []labels.Labels
opts *ManagerOptions opts *ManagerOptions
mtx sync.Mutex mtx sync.Mutex
evaluationDuration time.Duration evaluationTime time.Duration
evaluationTimestamp time.Time lastEvaluation time.Time
shouldRestore bool shouldRestore bool
@ -332,8 +332,8 @@ func (g *Group) run(ctx context.Context) {
timeSinceStart := time.Since(start) timeSinceStart := time.Since(start)
g.metrics.iterationDuration.Observe(timeSinceStart.Seconds()) g.metrics.iterationDuration.Observe(timeSinceStart.Seconds())
g.setEvaluationDuration(timeSinceStart) g.setEvaluationTime(timeSinceStart)
g.setEvaluationTimestamp(start) g.setLastEvaluation(start)
} }
// The assumption here is that since the ticker was started after having // The assumption here is that since the ticker was started after having
@ -454,36 +454,36 @@ func (g *Group) HasAlertingRules() bool {
return false return false
} }
// GetEvaluationDuration returns the time in seconds it took to evaluate the rule group. // GetEvaluationTime returns the time in seconds it took to evaluate the rule group.
func (g *Group) GetEvaluationDuration() time.Duration { func (g *Group) GetEvaluationTime() time.Duration {
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
return g.evaluationDuration return g.evaluationTime
} }
// setEvaluationDuration sets the time in seconds the last evaluation took. // setEvaluationTime sets the time in seconds the last evaluation took.
func (g *Group) setEvaluationDuration(dur time.Duration) { func (g *Group) setEvaluationTime(dur time.Duration) {
g.metrics.groupLastDuration.WithLabelValues(groupKey(g.file, g.name)).Set(dur.Seconds()) g.metrics.groupLastDuration.WithLabelValues(groupKey(g.file, g.name)).Set(dur.Seconds())
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
g.evaluationDuration = dur g.evaluationTime = dur
} }
// GetEvaluationTimestamp returns the time the last evaluation of the rule group took place. // GetLastEvaluation returns the time the last evaluation of the rule group took place.
func (g *Group) GetEvaluationTimestamp() time.Time { func (g *Group) GetLastEvaluation() time.Time {
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
return g.evaluationTimestamp return g.lastEvaluation
} }
// setEvaluationTimestamp updates evaluationTimestamp to the timestamp of when the rule group was last evaluated. // setLastEvaluation updates lastEvaluation to the timestamp of when the rule group was last evaluated.
func (g *Group) setEvaluationTimestamp(ts time.Time) { func (g *Group) setLastEvaluation(ts time.Time) {
g.metrics.groupLastEvalTime.WithLabelValues(groupKey(g.file, g.name)).Set(float64(ts.UnixNano()) / 1e9) g.metrics.groupLastEvalTime.WithLabelValues(groupKey(g.file, g.name)).Set(float64(ts.UnixNano()) / 1e9)
g.mtx.Lock() g.mtx.Lock()
defer g.mtx.Unlock() defer g.mtx.Unlock()
g.evaluationTimestamp = ts g.lastEvaluation = ts
} }
// evalTimestamp returns the immediately preceding consistently slotted evaluation time. // 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 // 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. // first is matched with the first, second with the second etc.
func (g *Group) CopyState(from *Group) { func (g *Group) CopyState(from *Group) {
g.evaluationDuration = from.evaluationDuration g.evaluationTime = from.evaluationTime
g.evaluationTimestamp = from.evaluationTimestamp g.lastEvaluation = from.lastEvaluation
ruleMap := make(map[string][]int, len(from.rules)) ruleMap := make(map[string][]int, len(from.rules))

View file

@ -626,7 +626,7 @@ func TestCopyState(t *testing.T) {
{"r3c": labels.Labels{{Name: "l1", Value: "v3"}}}, {"r3c": labels.Labels{{Name: "l1", Value: "v3"}}},
{"a2": labels.Labels{{Name: "l2", Value: "v1"}}}, {"a2": labels.Labels{{Name: "l2", Value: "v1"}}},
}, },
evaluationDuration: time.Second, evaluationTime: time.Second,
} }
oldGroup.rules[0].(*AlertingRule).active[42] = nil oldGroup.rules[0].(*AlertingRule).active[42] = nil
newGroup := &Group{ newGroup := &Group{
@ -656,8 +656,8 @@ 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.evaluationDuration, newGroup.evaluationDuration) testutil.Equals(t, oldGroup.evaluationTime, newGroup.evaluationTime)
testutil.Equals(t, oldGroup.evaluationTimestamp, newGroup.evaluationTimestamp) testutil.Equals(t, oldGroup.lastEvaluation, newGroup.lastEvaluation)
testutil.Equals(t, []labels.Labels{{{Name: "l1", Value: "v3"}}}, newGroup.staleSeries) testutil.Equals(t, []labels.Labels{{{Name: "l1", Value: "v3"}}}, newGroup.staleSeries)
} }

View file

@ -1063,8 +1063,8 @@ func (api *API) rules(r *http.Request) apiFuncResult {
File: grp.File(), File: grp.File(),
Interval: grp.Interval().Seconds(), Interval: grp.Interval().Seconds(),
Rules: []rule{}, Rules: []rule{},
EvaluationTime: grp.GetEvaluationDuration().Seconds(), EvaluationTime: grp.GetEvaluationTime().Seconds(),
LastEvaluation: grp.GetEvaluationTimestamp(), LastEvaluation: grp.GetLastEvaluation(),
} }
for _, r := range grp.Rules() { for _, r := range grp.Rules() {
var enrichedRule rule var enrichedRule rule