-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: tricklenode #2530
Merged
Merged
feat: tricklenode #2530
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
144a0bf
feat: tricklenode
docmerlin 463747f
chore: update changelog
docmerlin 95e24ef
test: fix TestTrickle ast test
docmerlin 7a99ba6
chore: cleanup imports
docmerlin c1245a7
Merge branch 'master' into tricklenode
docmerlin adeba23
Merge branch 'master' into tricklenode
docmerlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking my understanding: this test is showing that
trickle()
followed bywindow
is a way to re-batch data? i.e. in this case, re-batching from 4s windows into 10s windows?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also that the results of trickle are unbached as window cannot accept batch data, but the inputs to trickle are batched.