forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: tricklenode * chore: update changelog * test: fix TestTrickle ast test * chore: cleanup imports
- Loading branch information
Showing
13 changed files
with
267 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "cpu_usage_idle", | ||
"tags": { | ||
"cpu": "cpu-total" | ||
}, | ||
"points": [ | ||
{ | ||
"fields": { | ||
"mean": 90.38281469458698 | ||
}, | ||
"time": "2015-10-30T17:14:12Z" | ||
}, | ||
{ | ||
"fields": { | ||
"mean": 80.38281469458698 | ||
}, | ||
"time": "2015-10-30T17:14:13Z" | ||
} | ||
] | ||
} | ||
{ | ||
"name": "cpu_usage_idle", | ||
"tags": { | ||
"cpu": "cpu0" | ||
}, | ||
"points": [ | ||
{ | ||
"fields": { | ||
"mean": 83.56930693069836 | ||
}, | ||
"time": "2015-10-30T17:14:12Z" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package tick | ||
|
||
import ( | ||
"github.com/influxdata/kapacitor/pipeline" | ||
"github.com/influxdata/kapacitor/tick/ast" | ||
) | ||
|
||
// TrickleNode converts the StatsNode pipeline node into the TICKScript AST | ||
type TrickleNode struct { | ||
Function | ||
} | ||
|
||
// NewTrickle creates a TrickleNode function builder | ||
func NewTrickle(parents []ast.Node) *TrickleNode { | ||
return &TrickleNode{ | ||
Function{ | ||
Parents: parents, | ||
}, | ||
} | ||
} | ||
|
||
// Build NewTrickle ast.Node | ||
func (n *TrickleNode) Build(s *pipeline.TrickleNode) (ast.Node, error) { | ||
n.Pipe("trickle") | ||
return n.prev, n.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package tick_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestTrickle(t *testing.T) { | ||
pipe, _, from := StreamFrom() | ||
w := from.Window() | ||
w.Every = time.Second | ||
w.Trickle() | ||
want := `stream | ||
|from() | ||
|window() | ||
.every(1s) | ||
|trickle() | ||
` | ||
PipelineTickTestHelper(t, pipe, want) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package pipeline | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
) | ||
|
||
// A node that converts from batchedges to streamedges. | ||
// Example: | ||
// var errors = stream | ||
// |from() | ||
// |trickle() | ||
// Children of trickle will be treated as if they are in a stream. | ||
type TrickleNode struct { | ||
chainnode `json:"-"` | ||
} | ||
|
||
func newTrickleNode() *TrickleNode { | ||
return &TrickleNode{ | ||
chainnode: newBasicChainNode("trickle", BatchEdge, StreamEdge), | ||
} | ||
} | ||
|
||
// MarshalJSON converts TrickleNode to JSON | ||
// tick:ignore | ||
func (n *TrickleNode) MarshalJSON() ([]byte, error) { | ||
var raw = &struct { | ||
TypeOf | ||
}{ | ||
TypeOf: TypeOf{ | ||
Type: "trickle", | ||
ID: n.ID(), | ||
}, | ||
} | ||
return json.Marshal(raw) | ||
} | ||
|
||
// UnmarshalJSON converts JSON to an TrickleNode | ||
// tick:ignore | ||
func (n *TrickleNode) UnmarshalJSON(data []byte) error { | ||
var raw = &struct { | ||
TypeOf | ||
}{} | ||
err := json.Unmarshal(data, raw) | ||
if err != nil { | ||
return err | ||
} | ||
if raw.Type != "trickle" { | ||
return fmt.Errorf("error unmarshaling node %d of type %s as TrickleNode", raw.ID, raw.Type) | ||
} | ||
n.setID(raw.ID) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.