forked from bookingcom/carbonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.go
68 lines (59 loc) · 1.93 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
package countSeries
import (
"fmt"
"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 countSeries struct {
interfaces.FunctionBase
}
func GetOrder() interfaces.Order {
return interfaces.Any
}
func New(configFile string) []interfaces.FunctionMetadata {
res := make([]interfaces.FunctionMetadata, 0)
f := &countSeries{}
functions := []string{"countSeries"}
for _, n := range functions {
res = append(res, interfaces.FunctionMetadata{Name: n, F: f})
}
return res
}
// countSeries(seriesList)
func (f *countSeries) Do(e parser.Expr, from, until int32, values map[parser.MetricRequest][]*types.MetricData) ([]*types.MetricData, error) {
// TODO(civil): Check that series have equal length
args, err := helper.GetSeriesArgsAndRemoveNonExisting(e, from, until, values)
if err != nil {
return nil, err
}
r := *args[0]
r.Name = fmt.Sprintf("countSeries(%s)", e.RawArgs())
r.Values = make([]float64, len(args[0].Values))
r.IsAbsent = make([]bool, len(args[0].Values))
count := float64(len(args))
for i := range args[0].Values {
r.Values[i] = count
}
return []*types.MetricData{&r}, nil
}
// Description is auto-generated description, based on output of https://github.com/graphite-project/graphite-web
func (f *countSeries) Description() map[string]types.FunctionDescription {
return map[string]types.FunctionDescription{
"countSeries": {
Description: "Draws a horizontal line representing the number of nodes found in the seriesList.\n\n.. code-block:: none\n\n &target=countSeries(carbon.agents.*.*)",
Function: "countSeries(*seriesLists)",
Group: "Combine",
Module: "graphite.render.functions",
Name: "countSeries",
Params: []types.FunctionParam{
{
Multiple: true,
Name: "seriesLists",
Type: types.SeriesList,
},
},
},
}
}