diff --git a/promql/functions.go b/promql/functions.go index 68d30ec43..9252cb71f 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -118,6 +118,13 @@ func funcRate(ev *evaluator, args Expressions) Value { return vector } +// === increase(node ExprMatrix) Vector === +func funcIncrease(ev *evaluator, args Expressions) Value { + args = append(args, &NumberLiteral{1}) + vector := funcDelta(ev, args).(Vector) + return vector +} + // === sort(node ExprVector) Vector === func funcSort(ev *evaluator, args Expressions) Value { byValueSorter := vectorByValueHeap(ev.evalVector(args[0])) @@ -572,6 +579,12 @@ var functions = map[string]*Function{ ReturnType: ExprVector, Call: funcAbsent, }, + "increase": { + Name: "increase", + ArgTypes: []ExprType{ExprMatrix}, + ReturnType: ExprVector, + Call: funcIncrease, + }, "avg_over_time": { Name: "avg_over_time", ArgTypes: []ExprType{ExprMatrix}, diff --git a/promql/quantile.go b/promql/quantile.go index 11edad85f..e074df433 100644 --- a/promql/quantile.go +++ b/promql/quantile.go @@ -25,8 +25,8 @@ import ( // excludedLabels are the labels to exclude from signature calculation for // quantiles. var excludedLabels = map[clientmodel.LabelName]struct{}{ - clientmodel.MetricNameLabel: struct{}{}, - clientmodel.BucketLabel: struct{}{}, + clientmodel.MetricNameLabel: {}, + clientmodel.BucketLabel: {}, } type bucket struct { diff --git a/promql/testdata/functions.test b/promql/testdata/functions.test index 143f8deb5..6d246e2b0 100644 --- a/promql/testdata/functions.test +++ b/promql/testdata/functions.test @@ -49,3 +49,16 @@ eval instant at 50m changes(http_requests[50m]) {path="/biz"} 1 eval instant at 50m changes(nonexistent_metric[50m]) + + +clear + +# Tests for increase(). +load 5m + http_requests{path="/foo"} 0+10x10 + http_requests{path="/bar"} 0+10x5 0+10x5 + +# Tests for increase(). +eval instant at 50m increase(http_requests[50m]) + {path="/foo"} 100 + {path="/bar"} 90 diff --git a/retrieval/targetmanager.go b/retrieval/targetmanager.go index f1b2e0677..7e0ecd918 100644 --- a/retrieval/targetmanager.go +++ b/retrieval/targetmanager.go @@ -310,7 +310,7 @@ func (tm *TargetManager) targetsFromGroup(tg *config.TargetGroup, cfg *config.Sc // set already. Apply the labelsets in order of decreasing precedence. labelsets := []clientmodel.LabelSet{ tg.Labels, - clientmodel.LabelSet{ + { clientmodel.MetricsPathLabel: clientmodel.LabelValue(cfg.MetricsPath), clientmodel.JobLabel: clientmodel.LabelValue(cfg.JobName), }, diff --git a/retrieval/targetmanager_test.go b/retrieval/targetmanager_test.go index aaa251539..9cb30783d 100644 --- a/retrieval/targetmanager_test.go +++ b/retrieval/targetmanager_test.go @@ -43,7 +43,7 @@ func TestTargetManagerChan(t *testing.T) { targetManager := &TargetManager{ sampleAppender: nopAppender{}, providers: map[*config.ScrapeConfig][]TargetProvider{ - testJob1: []TargetProvider{prov1}, + testJob1: {prov1}, }, targets: make(map[string][]*Target), }