Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Added 8 functions related to filterSeries #1308

Merged
merged 2 commits into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/graphite.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ See also:
| applyByNode | | No |
| areaBetween | | No |
| asPercent(seriesList, seriesList, nodeList) seriesList | | Stable |
| averageAbove | | No |
| averageBelow | | No |
| averageAbove | | Stable |
| averageBelow | | Stable |
| averageOutsidePercentile | | No |
| averageSeries(seriesLists) series | avg | Stable |
| averageSeriesWithWildcards | | No |
Expand All @@ -62,8 +62,8 @@ See also:
| constantLine | | No |
| countSeries(seriesLists) series | | Stable |
| cumulative | | Stable |
| currentAbove | | No |
| currentBelow | | No |
| currentAbove | | Stable |
| currentBelow | | Stable |
| dashed | | No |
| delay | | No |
| derivative(seriesLists) series | | Stable |
Expand Down Expand Up @@ -106,11 +106,11 @@ See also:
| lowestAverage(seriesList, n, func) seriesList | | Stable |
| lowestCurrent(seriesList, n, func) seriesList | | Stable |
| mapSeries | map | No |
| maximumAbove | | No |
| maximumBelow | | No |
| maximumAbove | | Stable |
| maximumBelow | | Stable |
| maxSeries(seriesList) series | max | Stable |
| minimumAbove | | No |
| minimumBelow | | No |
| minimumAbove | | Stable |
| minimumBelow | | Stable |
| minMax | | No |
| minSeries(seriesList) series | min | Stable |
| mostDeviant | | No |
Expand Down
13 changes: 13 additions & 0 deletions expr/func_filterseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@ func NewFilterSeries() GraphiteFunc {
return &FuncFilterSeries{}
}

func NewFilterSeriesConstructor(fn string, operator string) func() GraphiteFunc {
return func() GraphiteFunc {
return &FuncFilterSeries{fn: fn, operator: operator}
}
}

func (s *FuncFilterSeries) Signature() ([]Arg, []Arg) {
if s.fn != "" && s.operator != "" {
return []Arg{
ArgSeriesList{val: &s.in},
ArgFloat{key: "threshold", val: &s.threshold},
}, []Arg{ArgSeriesList{}}
}
return []Arg{
ArgSeriesList{val: &s.in},
ArgString{key: "func", val: &s.fn, validator: []Validator{IsConsolFunc}},
ArgString{key: "operator", val: &s.operator, validator: []Validator{IsOperator}},
ArgFloat{key: "threshold", val: &s.threshold},
}, []Arg{ArgSeriesList{}}

}

func (s *FuncFilterSeries) Context(context Context) Context {
Expand Down
8 changes: 8 additions & 0 deletions expr/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ func init() {
"aliasSub": {NewAliasSub, true},
"asPercent": {NewAsPercent, true},
"avg": {NewAggregateConstructor("average", crossSeriesAvg), true},
"averageAbove": {NewFilterSeriesConstructor("average", ">"), true},
"averageBelow": {NewFilterSeriesConstructor("average", "<="), true},
"averageSeries": {NewAggregateConstructor("average", crossSeriesAvg), true},
"consolidateBy": {NewConsolidateBy, true},
"countSeries": {NewCountSeries, true},
"cumulative": {NewConsolidateByConstructor("sum"), true},
"currentAbove": {NewFilterSeriesConstructor("last", ">"), true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces

"currentBelow": {NewFilterSeriesConstructor("last", "<="), true},
"derivative": {NewDerivative, true},
"diffSeries": {NewAggregateConstructor("diff", crossSeriesDiff), true},
"divideSeries": {NewDivideSeries, true},
Expand All @@ -77,8 +81,12 @@ func init() {
"lowestAverage": {NewHighestLowestConstructor("average", false), true},
"lowestCurrent": {NewHighestLowestConstructor("current", false), true},
"max": {NewAggregateConstructor("max", crossSeriesMax), true},
"maximumAbove": {NewFilterSeriesConstructor("max", ">"), true},
"maximumBelow": {NewFilterSeriesConstructor("max", "<="), true},
"maxSeries": {NewAggregateConstructor("max", crossSeriesMax), true},
"min": {NewAggregateConstructor("min", crossSeriesMin), true},
"minimumAbove": {NewFilterSeriesConstructor("min", ">"), true},
"minimumBelow": {NewFilterSeriesConstructor("min", "<="), true},
"minSeries": {NewAggregateConstructor("min", crossSeriesMin), true},
"multiplySeries": {NewAggregateConstructor("multiply", crossSeriesMultiply), true},
"movingAverage": {NewMovingAverage, false},
Expand Down