-
Notifications
You must be signed in to change notification settings - Fork 139
/
function.go
62 lines (54 loc) · 1.84 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
package aliasByMetric
import (
"context"
"github.com/go-graphite/carbonapi/expr/helper"
"github.com/go-graphite/carbonapi/expr/interfaces"
"github.com/go-graphite/carbonapi/expr/types"
"github.com/go-graphite/carbonapi/pkg/parser"
"strings"
)
type aliasByMetric struct {
interfaces.FunctionBase
}
func GetOrder() interfaces.Order {
return interfaces.Any
}
func New(configFile string) []interfaces.FunctionMetadata {
res := make([]interfaces.FunctionMetadata, 0)
f := &aliasByMetric{}
for _, n := range []string{"aliasByMetric"} {
res = append(res, interfaces.FunctionMetadata{Name: n, F: f})
}
return res
}
func (f *aliasByMetric) Do(ctx context.Context, e parser.Expr, from, until int64, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
return helper.ForEachSeriesDo1(ctx, e, from, until, values, func(a *types.MetricData) *types.MetricData {
metric := types.ExtractNameTag(a.Name)
part := strings.Split(metric, ".")
name := part[len(part)-1]
ret := a.CopyName(name)
ret.PathExpression = name
return ret
})
}
// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web
func (f *aliasByMetric) Description() map[string]types.FunctionDescription {
return map[string]types.FunctionDescription{
"aliasByMetric": {
Description: "Takes a seriesList and applies an alias derived from the base metric name.\n\n.. code-block:: none\n\n &target=aliasByMetric(carbon.agents.graphite.creates)",
Function: "aliasByMetric(seriesList)",
Group: "Alias",
Module: "graphite.render.functions",
Name: "aliasByMetric",
Params: []types.FunctionParam{
{
Name: "seriesList",
Required: true,
Type: types.SeriesList,
},
},
NameChange: true, // name changed
TagsChange: true, // name tag changed
},
}
}