/
function.go
80 lines (69 loc) · 2.04 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
70
71
72
73
74
75
76
77
78
79
80
package exclude
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"
"regexp"
)
type exclude struct {
interfaces.FunctionBase
}
func GetOrder() interfaces.Order {
return interfaces.Any
}
func New(configFile string) []interfaces.FunctionMetadata {
res := make([]interfaces.FunctionMetadata, 0)
f := &exclude{}
functions := []string{"exclude"}
for _, n := range functions {
res = append(res, interfaces.FunctionMetadata{Name: n, F: f})
}
return res
}
// exclude(seriesList, pattern)
func (f *exclude) Do(e parser.Expr, from, until int32, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
arg, err := helper.GetSeriesArg(e.Args()[0], from, until, values)
if err != nil {
return nil, err
}
pat, err := e.GetStringArg(1)
if err != nil {
return nil, err
}
patre, err := regexp.Compile(pat)
if err != nil {
return nil, err
}
var results []*types.MetricData
for _, a := range arg {
if !patre.MatchString(a.Name) {
results = append(results, a)
}
}
return results, nil
}
// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web
func (f *exclude) Description() map[string]types.FunctionDescription {
return map[string]types.FunctionDescription{
"exclude": {
Description: "Takes a metric or a wildcard seriesList, followed by a regular expression\nin double quotes. Excludes metrics that match the regular expression.\n\nExample:\n\n.. code-block:: none\n\n &target=exclude(servers*.instance*.threads.busy,\"server02\")",
Function: "exclude(seriesList, pattern)",
Group: "Filter Series",
Module: "graphite.render.functions",
Name: "exclude",
Params: []types.FunctionParam{
{
Name: "seriesList",
Required: true,
Type: types.SeriesList,
},
{
Name: "pattern",
Required: true,
Type: types.String,
},
},
},
}
}