mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
Add increase() function, to replace delta(..., 1).
This calculates how much a counter increases over a given period of time, which is the area under the curve of it's rate. increase(x[5m]) is equivilent to rate(x[5m]) * 300.
This commit is contained in:
parent
7b5304850d
commit
f34de493d5
|
@ -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},
|
||||
|
|
|
@ -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 {
|
||||
|
|
13
promql/testdata/functions.test
vendored
13
promql/testdata/functions.test
vendored
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
},
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue