mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Merge pull request #13059 from zenador/add-mad-function
Add mad_over_time function
This commit is contained in:
commit
91a383f52c
|
@ -640,6 +640,7 @@ over time and return an instant vector with per-series aggregation results:
|
||||||
* `quantile_over_time(scalar, range-vector)`: the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.
|
* `quantile_over_time(scalar, range-vector)`: the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.
|
||||||
* `stddev_over_time(range-vector)`: the population standard deviation of the values in the specified interval.
|
* `stddev_over_time(range-vector)`: the population standard deviation of the values in the specified interval.
|
||||||
* `stdvar_over_time(range-vector)`: the population standard variance of the values in the specified interval.
|
* `stdvar_over_time(range-vector)`: the population standard variance of the values in the specified interval.
|
||||||
|
* `mad_over_time(range-vector)`: the median absolute deviation of all points in the specified interval.
|
||||||
* `last_over_time(range-vector)`: the most recent point value in the specified interval.
|
* `last_over_time(range-vector)`: the most recent point value in the specified interval.
|
||||||
* `present_over_time(range-vector)`: the value 1 for any series in the specified interval.
|
* `present_over_time(range-vector)`: the value 1 for any series in the specified interval.
|
||||||
|
|
||||||
|
|
|
@ -609,6 +609,25 @@ func funcLastOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNod
|
||||||
}), nil
|
}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === mad_over_time(Matrix parser.ValueTypeMatrix) (Vector, Annotations) ===
|
||||||
|
func funcMadOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
||||||
|
if len(vals[0].(Matrix)[0].Floats) == 0 {
|
||||||
|
return enh.Out, nil
|
||||||
|
}
|
||||||
|
return aggrOverTime(vals, enh, func(s Series) float64 {
|
||||||
|
values := make(vectorByValueHeap, 0, len(s.Floats))
|
||||||
|
for _, f := range s.Floats {
|
||||||
|
values = append(values, Sample{F: f.F})
|
||||||
|
}
|
||||||
|
median := quantile(0.5, values)
|
||||||
|
values = make(vectorByValueHeap, 0, len(s.Floats))
|
||||||
|
for _, f := range s.Floats {
|
||||||
|
values = append(values, Sample{F: math.Abs(f.F - median)})
|
||||||
|
}
|
||||||
|
return quantile(0.5, values)
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
// === max_over_time(Matrix parser.ValueTypeMatrix) (Vector, Annotations) ===
|
// === max_over_time(Matrix parser.ValueTypeMatrix) (Vector, Annotations) ===
|
||||||
func funcMaxOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
func funcMaxOverTime(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
||||||
if len(vals[0].(Matrix)[0].Floats) == 0 {
|
if len(vals[0].(Matrix)[0].Floats) == 0 {
|
||||||
|
@ -1538,6 +1557,7 @@ var FunctionCalls = map[string]FunctionCall{
|
||||||
"log10": funcLog10,
|
"log10": funcLog10,
|
||||||
"log2": funcLog2,
|
"log2": funcLog2,
|
||||||
"last_over_time": funcLastOverTime,
|
"last_over_time": funcLastOverTime,
|
||||||
|
"mad_over_time": funcMadOverTime,
|
||||||
"max_over_time": funcMaxOverTime,
|
"max_over_time": funcMaxOverTime,
|
||||||
"min_over_time": funcMinOverTime,
|
"min_over_time": funcMinOverTime,
|
||||||
"minute": funcMinute,
|
"minute": funcMinute,
|
||||||
|
|
|
@ -254,6 +254,12 @@ var Functions = map[string]*Function{
|
||||||
ArgTypes: []ValueType{ValueTypeVector},
|
ArgTypes: []ValueType{ValueTypeVector},
|
||||||
ReturnType: ValueTypeVector,
|
ReturnType: ValueTypeVector,
|
||||||
},
|
},
|
||||||
|
"mad_over_time": {
|
||||||
|
Name: "mad_over_time",
|
||||||
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
ReturnType: ValueTypeVector,
|
||||||
|
Experimental: true,
|
||||||
|
},
|
||||||
"max_over_time": {
|
"max_over_time": {
|
||||||
Name: "max_over_time",
|
Name: "max_over_time",
|
||||||
ArgTypes: []ValueType{ValueTypeMatrix},
|
ArgTypes: []ValueType{ValueTypeMatrix},
|
||||||
|
|
8
promql/testdata/functions.test
vendored
8
promql/testdata/functions.test
vendored
|
@ -739,6 +739,14 @@ eval instant at 1m stdvar_over_time(metric[1m])
|
||||||
eval instant at 1m stddev_over_time(metric[1m])
|
eval instant at 1m stddev_over_time(metric[1m])
|
||||||
{} 0
|
{} 0
|
||||||
|
|
||||||
|
# Tests for mad_over_time.
|
||||||
|
clear
|
||||||
|
load 10s
|
||||||
|
metric 4 6 2 1 999 1 2
|
||||||
|
|
||||||
|
eval instant at 70s mad_over_time(metric[70s])
|
||||||
|
{} 1
|
||||||
|
|
||||||
# Tests for quantile_over_time
|
# Tests for quantile_over_time
|
||||||
clear
|
clear
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,12 @@ export const functionIdentifierTerms = [
|
||||||
info: 'Calculate base-2 logarithm of input series',
|
info: 'Calculate base-2 logarithm of input series',
|
||||||
type: 'function',
|
type: 'function',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'mad_over_time',
|
||||||
|
detail: 'function',
|
||||||
|
info: 'Return the median absolute deviation over time for input series',
|
||||||
|
type: 'function',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'max_over_time',
|
label: 'max_over_time',
|
||||||
detail: 'function',
|
detail: 'function',
|
||||||
|
|
|
@ -95,6 +95,11 @@ describe('promql operations', () => {
|
||||||
expectedValueType: ValueType.vector,
|
expectedValueType: ValueType.vector,
|
||||||
expectedDiag: [] as Diagnostic[],
|
expectedDiag: [] as Diagnostic[],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
expr: 'mad_over_time(rate(metric_name[5m])[1h:] offset 1m)',
|
||||||
|
expectedValueType: ValueType.vector,
|
||||||
|
expectedDiag: [] as Diagnostic[],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
expr: 'max_over_time(rate(metric_name[5m])[1h:] offset 1m)',
|
expr: 'max_over_time(rate(metric_name[5m])[1h:] offset 1m)',
|
||||||
expectedValueType: ValueType.vector,
|
expectedValueType: ValueType.vector,
|
||||||
|
|
|
@ -56,6 +56,7 @@ import {
|
||||||
Ln,
|
Ln,
|
||||||
Log10,
|
Log10,
|
||||||
Log2,
|
Log2,
|
||||||
|
MadOverTime,
|
||||||
MaxOverTime,
|
MaxOverTime,
|
||||||
MinOverTime,
|
MinOverTime,
|
||||||
Minute,
|
Minute,
|
||||||
|
@ -370,6 +371,12 @@ const promqlFunctions: { [key: number]: PromQLFunction } = {
|
||||||
variadic: 0,
|
variadic: 0,
|
||||||
returnType: ValueType.vector,
|
returnType: ValueType.vector,
|
||||||
},
|
},
|
||||||
|
[MadOverTime]: {
|
||||||
|
name: 'mad_over_time',
|
||||||
|
argTypes: [ValueType.matrix],
|
||||||
|
variadic: 0,
|
||||||
|
returnType: ValueType.vector,
|
||||||
|
},
|
||||||
[MaxOverTime]: {
|
[MaxOverTime]: {
|
||||||
name: 'max_over_time',
|
name: 'max_over_time',
|
||||||
argTypes: [ValueType.matrix],
|
argTypes: [ValueType.matrix],
|
||||||
|
|
|
@ -149,6 +149,7 @@ FunctionIdentifier {
|
||||||
Ln |
|
Ln |
|
||||||
Log10 |
|
Log10 |
|
||||||
Log2 |
|
Log2 |
|
||||||
|
MadOverTime |
|
||||||
MaxOverTime |
|
MaxOverTime |
|
||||||
MinOverTime |
|
MinOverTime |
|
||||||
Minute |
|
Minute |
|
||||||
|
@ -380,6 +381,7 @@ NumberLiteral {
|
||||||
Ln { condFn<"ln"> }
|
Ln { condFn<"ln"> }
|
||||||
Log10 { condFn<"log10"> }
|
Log10 { condFn<"log10"> }
|
||||||
Log2 { condFn<"log2"> }
|
Log2 { condFn<"log2"> }
|
||||||
|
MadOverTime { condFn<"mad_over_time"> }
|
||||||
MaxOverTime { condFn<"max_over_time"> }
|
MaxOverTime { condFn<"max_over_time"> }
|
||||||
MinOverTime { condFn<"min_over_time"> }
|
MinOverTime { condFn<"min_over_time"> }
|
||||||
Minute { condFn<"minute"> }
|
Minute { condFn<"minute"> }
|
||||||
|
|
Loading…
Reference in a new issue