Skip to content

Commit 072c479

Browse files
Add consolidation function aliases to function mapping (#91)
* Add aliases of consolidation functions to consolidation function mapping * Add tests to verify aliases are accepted
1 parent c627d84 commit 072c479

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

expr/consolidations/consolidations.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ var ConsolidationToFunc = map[string]func([]float64) float64{
2424
"minimum": AggMin,
2525
"multiply": summarizeToAggregate("multiply"),
2626
"range": summarizeToAggregate("range"),
27+
"rangeOf": summarizeToAggregate("rangeOf"),
2728
"sum": AggSum,
29+
"total": AggSum,
2830
"stddev": summarizeToAggregate("stddev"),
2931
"first": AggFirst,
3032
"last": AggLast,
33+
"current": AggLast,
3134
}
3235

33-
var AvailableSummarizers = []string{"sum", "total", "avg", "average", "avg_zero", "max", "min", "last", "range", "median", "multiply", "diff", "count", "stddev"}
36+
var AvailableSummarizers = []string{"sum", "total", "avg", "average", "avg_zero", "max", "min", "last", "current", "range", "rangeOf", "median", "multiply", "diff", "count", "stddev"}
3437

3538
// AvgValue returns average of list of values
3639
func AvgValue(f64s []float64) float64 {
@@ -167,10 +170,10 @@ func SummarizeValues(f string, values []float64, XFilesFactor float32) float64 {
167170
}
168171
}
169172
}
170-
case "last":
173+
case "last", "current":
171174
rv = values[len(values)-1]
172175
total = notNans(values)
173-
case "range":
176+
case "range", "rangeOf":
174177
vMax := math.Inf(-1)
175178
vMin := math.Inf(1)
176179
isNaN := true

expr/functions/aggregate/function_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ func TestAverageSeries(t *testing.T) {
100100
[]*types.MetricData{types.MakeMetricData("lastSeries(metric[123])",
101101
[]float64{3, math.NaN(), 4, 5, 6, 6}, 1, now32)},
102102
},
103+
{
104+
`aggregate(metric[123], "current")`,
105+
map[parser.MetricRequest][]*types.MetricData{
106+
{"metric[123]", 0, 1}: {
107+
types.MakeMetricData("metric1", []float64{1, math.NaN(), 2, 3, 4, 5}, 1, now32),
108+
types.MakeMetricData("metric2", []float64{2, math.NaN(), 3, math.NaN(), 5, 6}, 1, now32),
109+
types.MakeMetricData("metric3", []float64{3, math.NaN(), 4, 5, 6, math.NaN()}, 1, now32),
110+
},
111+
},
112+
[]*types.MetricData{types.MakeMetricData("currentSeries(metric[123])",
113+
[]float64{3, math.NaN(), 4, 5, 6, 6}, 1, now32)},
114+
},
103115
{
104116
`aggregate(metric[123], "max")`,
105117
map[parser.MetricRequest][]*types.MetricData{
@@ -160,6 +172,18 @@ func TestAverageSeries(t *testing.T) {
160172
[]*types.MetricData{types.MakeMetricData("rangeSeries(metric[123])",
161173
[]float64{2, math.NaN(), 2, 2, 2, 1}, 1, now32)},
162174
},
175+
{
176+
`aggregate(metric[123], "rangeOf")`,
177+
map[parser.MetricRequest][]*types.MetricData{
178+
{"metric[123]", 0, 1}: {
179+
types.MakeMetricData("metric1", []float64{1, math.NaN(), 2, 3, 4, 6}, 1, now32),
180+
types.MakeMetricData("metric2", []float64{2, math.NaN(), 3, math.NaN(), 5, 5}, 1, now32),
181+
types.MakeMetricData("metric3", []float64{3, math.NaN(), 4, 5, 6, math.NaN()}, 1, now32),
182+
},
183+
},
184+
[]*types.MetricData{types.MakeMetricData("rangeOfSeries(metric[123])",
185+
[]float64{2, math.NaN(), 2, 2, 2, 1}, 1, now32)},
186+
},
163187
{
164188
`aggregate(metric[123], "sum")`,
165189
map[parser.MetricRequest][]*types.MetricData{
@@ -172,6 +196,18 @@ func TestAverageSeries(t *testing.T) {
172196
[]*types.MetricData{types.MakeMetricData("sumSeries(metric[123])",
173197
[]float64{6, math.NaN(), 9, 8, 15, 11}, 1, now32)},
174198
},
199+
{
200+
`aggregate(metric[123], "total")`,
201+
map[parser.MetricRequest][]*types.MetricData{
202+
{"metric[123]", 0, 1}: {
203+
types.MakeMetricData("metric1", []float64{1, math.NaN(), 2, 3, 4, 6}, 1, now32),
204+
types.MakeMetricData("metric2", []float64{2, math.NaN(), 3, math.NaN(), 5, 5}, 1, now32),
205+
types.MakeMetricData("metric3", []float64{3, math.NaN(), 4, 5, 6, math.NaN()}, 1, now32),
206+
},
207+
},
208+
[]*types.MetricData{types.MakeMetricData("totalSeries(metric[123])",
209+
[]float64{6, math.NaN(), 9, 8, 15, 11}, 1, now32)},
210+
},
175211
{
176212
`stddevSeries(metric[123])`,
177213
map[parser.MetricRequest][]*types.MetricData{

0 commit comments

Comments
 (0)