Skip to content

Commit

Permalink
update BatchNode to allow double GroupBy
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielc committed Apr 4, 2016
1 parent b53d3c2 commit e8fa639
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ format a TICKscript file according to a common standard.
- [#387](https://github.com/influxdata/kapacitor/issues/387): Add `.quiet()` option to EvalNode so errors can be suppressed if expected.
- [#400](https://github.com/influxdata/kapacitor/issues/400): All query/connection errors are counted and reported in BatchNode stats.
- [#412](https://github.com/influxdata/kapacitor/pull/412): Fix issues with batch queries dropping points because of nil fields.
- [#413](https://github.com/influxdata/kapacitor/pull/413): Allow disambiguation between ".groupBy" and "|groupBy".


## v0.11.0 [2016-03-22]
Expand Down
33 changes: 33 additions & 0 deletions integrations/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,39 @@ batch
testBatcherWithOutput(t, "TestBatch_SimpleMR", script, 30*time.Second, er)
}

func TestBatch_DoubleGroupBy(t *testing.T) {

var script = `
batch
|query('''
SELECT mean("value")
FROM "telegraf"."default".cpu_usage_idle
WHERE "host" = 'serverA' AND "cpu" != 'cpu-total'
''')
.period(10s)
.every(10s)
.groupBy(time(2s), 'cpu')
|groupBy()
|max('mean')
|httpOut('TestBatch_SimpleMR')
`

er := kapacitor.Result{
Series: imodels.Rows{
{
Name: "cpu_usage_idle",
Columns: []string{"time", "max"},
Values: [][]interface{}{[]interface{}{
time.Date(1971, 1, 1, 0, 0, 18, 0, time.UTC),
95.98484848485191,
}},
},
},
}

testBatcherWithOutput(t, "TestBatch_SimpleMR", script, 30*time.Second, er)
}

func TestBatch_Join(t *testing.T) {

var script = `
Expand Down
4 changes: 1 addition & 3 deletions pipeline/alert.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package pipeline

import (
"github.com/influxdata/kapacitor/tick"
)
import "github.com/influxdata/kapacitor/tick"

// Number of previous states to remember when computing flapping percentage.
const defaultFlapHistory = 21
Expand Down
47 changes: 46 additions & 1 deletion pipeline/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package pipeline
import (
"bytes"
"time"

"github.com/influxdata/kapacitor/tick"
)

// A node that handles creating several child BatchNodes.
Expand Down Expand Up @@ -72,6 +74,9 @@ func (b *SourceBatchNode) dot(buf *bytes.Buffer) {
type BatchNode struct {
chainnode

// self describer
describer *tick.ReflectionDescriber

// The query text
//tick:ignore
QueryStr string
Expand Down Expand Up @@ -125,9 +130,11 @@ type BatchNode struct {
}

func newBatchNode() *BatchNode {
return &BatchNode{
b := &BatchNode{
chainnode: newBasicChainNode("batch", BatchEdge, BatchEdge),
}
b.describer, _ = tick.NewReflectionDescriber(b)
return b
}

// Group the data by a set of dimensions.
Expand Down Expand Up @@ -155,3 +162,41 @@ func (b *BatchNode) Align() *BatchNode {
b.AlignFlag = true
return b
}

// Tick Describer methods

//tick:ignore
func (b *BatchNode) Desc() string {
return b.describer.Desc()
}

//tick:ignore
func (b *BatchNode) HasChainMethod(name string) bool {
if name == "groupBy" {
return true
}
return b.describer.HasChainMethod(name)
}

//tick:ignore
func (b *BatchNode) CallChainMethod(name string, args ...interface{}) (interface{}, error) {
if name == "groupBy" {
return b.chainnode.GroupBy(args...), nil
}
return b.describer.CallChainMethod(name, args...)
}

//tick:ignore
func (b *BatchNode) HasProperty(name string) bool {
return b.describer.HasProperty(name)
}

//tick:ignore
func (b *BatchNode) Property(name string) interface{} {
return b.describer.Property(name)
}

//tick:ignore
func (b *BatchNode) SetProperty(name string, args ...interface{}) (interface{}, error) {
return b.describer.SetProperty(name, args...)
}

0 comments on commit e8fa639

Please sign in to comment.