-
Notifications
You must be signed in to change notification settings - Fork 23
/
function.go
69 lines (62 loc) · 2.2 KB
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package fallbackSeries
import (
"github.com/bookingcom/carbonapi/expr/helper"
"github.com/bookingcom/carbonapi/expr/interfaces"
"github.com/bookingcom/carbonapi/expr/types"
"github.com/bookingcom/carbonapi/pkg/parser"
)
type fallbackSeries struct {
interfaces.FunctionBase
}
func GetOrder() interfaces.Order {
return interfaces.Any
}
func New(configFile string) []interfaces.FunctionMetadata {
res := make([]interfaces.FunctionMetadata, 0)
f := &fallbackSeries{}
functions := []string{"fallbackSeries"}
for _, n := range functions {
res = append(res, interfaces.FunctionMetadata{Name: n, F: f})
}
return res
}
// fallbackSeries( seriesList, fallback )
func (f *fallbackSeries) Do(e parser.Expr, from, until int32, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
/*
Takes a wildcard seriesList, and a second fallback metric.
If the wildcard does not match any series, draws the fallback metric.
*/
seriesList, err := helper.GetSeriesArg(e.Args()[0], from, until, values)
fallback, errFallback := helper.GetSeriesArg(e.Args()[1], from, until, values)
if errFallback != nil && err != nil {
return nil, errFallback
}
if seriesList != nil && len(seriesList) > 0 {
return seriesList, nil
}
return fallback, nil
}
// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web
func (f *fallbackSeries) Description() map[string]types.FunctionDescription {
return map[string]types.FunctionDescription{
"fallbackSeries": {
Description: "Takes a wildcard seriesList, and a second fallback metric.\nIf the wildcard does not match any series, draws the fallback metric.\n\nExample:\n\n.. code-block:: none\n\n &target=fallbackSeries(server*.requests_per_second, constantLine(0))\n\nDraws a 0 line when server metric does not exist.",
Function: "fallbackSeries(seriesList, fallback)",
Group: "Special",
Module: "graphite.render.functions",
Name: "fallbackSeries",
Params: []types.FunctionParam{
{
Name: "seriesList",
Required: true,
Type: types.SeriesList,
},
{
Name: "fallback",
Required: true,
Type: types.SeriesList,
},
},
},
}
}