forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_out.go
73 lines (67 loc) · 1.67 KB
/
http_out.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
69
70
71
72
73
package pipeline
import (
"encoding/json"
"fmt"
)
// An HTTPOutNode caches the most recent data for each group it has received.
//
// The cached data is available at the given endpoint.
// The endpoint is the relative path from the API endpoint of the running task.
// For example if the task endpoint is at `/kapacitor/v1/tasks/<task_id>` and endpoint is
// `top10`, then the data can be requested from `/kapacitor/v1/tasks/<task_id>/top10`.
//
// Example:
// stream
// |window()
// .period(10s)
// .every(5s)
// |top('value', 10)
// //Publish the top 10 results over the last 10s updated every 5s.
// |httpOut('top10')
//
type HTTPOutNode struct {
chainnode
// The relative path where the cached data is exposed
// tick:ignore
Endpoint string `json:"endpoint"`
}
func newHTTPOutNode(wants EdgeType, endpoint string) *HTTPOutNode {
return &HTTPOutNode{
chainnode: newBasicChainNode("http_out", wants, wants),
Endpoint: endpoint,
}
}
// MarshalJSON converts HTTPOutNode to JSON
func (n *HTTPOutNode) MarshalJSON() ([]byte, error) {
type Alias HTTPOutNode
var raw = &struct {
TypeOf
*Alias
}{
TypeOf: TypeOf{
Type: "httpOut",
ID: n.ID(),
},
Alias: (*Alias)(n),
}
return json.Marshal(raw)
}
// UnmarshalJSON converts JSON to an HTTPOutNode
func (n *HTTPOutNode) UnmarshalJSON(data []byte) error {
type Alias HTTPOutNode
var raw = &struct {
TypeOf
*Alias
}{
Alias: (*Alias)(n),
}
err := json.Unmarshal(data, raw)
if err != nil {
return err
}
if raw.Type != "httpOut" {
return fmt.Errorf("error unmarshaling node %d of type %s as HTTPOutNode", raw.ID, raw.Type)
}
n.setID(raw.ID)
return nil
}