forked from drnic/consul-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhealth.go
91 lines (77 loc) · 2.91 KB
/
health.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package consuldiscovery
// Health is a set of functions for the health of services
type Health interface {
HealthByNode(nodeName string) ([]HealthCheck, error)
HealthByService(serviceName string) (HealthNodes, error)
HealthByState(state string) ([]HealthCheck, error)
}
// [{"Node":{"Node":"skailhq.local","Address":"192.168.50.1"},
// "Service":{"ID":"simple_service","Service":"simple_service","Tags":["tag1","tag2"],"Port":6666},
// "Checks":[{"Node":"skailhq.local","CheckID":"serfHealth","Name":"Serf Health Status","Status":"passing","Notes":"","Output":"","ServiceID":"","ServiceName":""}]}]
// HealthNodes summarizes the health checks for all Nodes for a single Service
type HealthNodes []HealthForNode
// HealthForNode summarizes the health checks for a single Nodes for a single Service
type HealthForNode struct {
Node HealthNode
Service HealthService
Checks []HealthCheck
}
// HealthNode indicates a server/node being described by HealthNodes
type HealthNode struct {
Node string
Address string
ID string
Datacenter string
TaggedAddresses TaggedAddressesNode
}
// HealthService indicates a service being described by HealthNodes
type HealthService struct {
ServiceID string `json:"ID"`
ServiceName string `json:"Service"`
ServiceTags []string `json:"Tags"`
ServicePort uint64 `json:"Port"`
ServiceAddress string `json:"Address"`
ServiceTaggedAddresses map[string]AddressService `json:"TaggedAddresses"`
ServiceMeta map[string]string `json:"Meta"`
}
// "TaggedAddressesNode":{"lan":{"Address":"192.168.0.55","Port":8000},"wan":{"Address":"198.18.0.23","Port":80}}
type TaggedAddressesNode struct {
Lan string `json:"lan"`
LanIpv4 string `json:"lan_ipv4"`
Wan string `json:"wan"`
WanIpv4 string `json:"wan_ipv4"`
}
type AddressService struct {
Address string
Port int
}
// HealthCheck contains a current health check result
type HealthCheck struct {
Node string
CheckID string
Name string
Status string
Notes string
Output string
ServiceID string
ServiceName string
ServiceTags []string
Type string
Namespace string
Partition string
}
// HealthByNode returns the health checks for a specific node
func (c *Client) HealthByNode(nodeName string) (result []HealthCheck, err error) {
err = c.doGET("health/node/"+nodeName, &result)
return
}
// HealthByService returns a list of advertised service names and their tags
func (c *Client) HealthByService(serviceName string) (result HealthNodes, err error) {
err = c.doGET("health/service/"+serviceName, &result)
return
}
// HealthByState returns the health checks with a specific state
func (c *Client) HealthByState(state string) (checks []HealthCheck, err error) {
err = c.doGET("health/state/"+state, &checks)
return
}