-
Notifications
You must be signed in to change notification settings - Fork 3
/
gossip.go
63 lines (52 loc) · 1.88 KB
/
gossip.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
package gosnowth
import (
"context"
"fmt"
)
// Gossip values contain gossip information from a node. This structure includes
// information on how the nodes are communicating with each other, and if any
// nodes are behind with each other with regards to data replication.
type Gossip []GossipDetail
// GossipDetail values represent gossip information about a node.
type GossipDetail struct {
ID string `json:"id"`
Time float64 `json:"gossip_time,string"`
Age float64 `json:"gossip_age,string"`
CurrentTopo string `json:"topo_current"`
NextTopo string `json:"topo_next"`
TopoState string `json:"topo_state"`
Latency GossipLatency `json:"latency"`
}
// GossipLatency values contain a map of node UUID's to latencies in seconds.
type GossipLatency map[string]string
// GetGossipInfo fetches the gossip information from an IRONdb node. The gossip
// response body will include a list of "GossipDetail" which provide
// the identifier of the node, the node's gossip_time, gossip_age, as well
// as topology state, current and next topology.
func (sc *SnowthClient) GetGossipInfo(nodes ...*SnowthNode) (*Gossip, error) {
return sc.GetGossipInfoContext(context.Background(), nodes...)
}
// GetGossipInfoContext is the context aware version of GetGossipInfo.
func (sc *SnowthClient) GetGossipInfoContext(ctx context.Context,
nodes ...*SnowthNode,
) (*Gossip, error) {
var node *SnowthNode
if len(nodes) > 0 && nodes[0] != nil {
node = nodes[0]
} else {
node = sc.GetActiveNode()
}
if node == nil {
return nil, fmt.Errorf("unable to get active node")
}
r := &Gossip{}
body, _, err := sc.DoRequestContext(ctx, node, "GET", "/gossip/json",
nil, nil)
if err != nil {
return nil, err
}
if err := decodeJSON(body, &r); err != nil {
return nil, fmt.Errorf("unable to decode IRONdb response: %w", err)
}
return r, nil
}