mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 06:16:08 +00:00
agent: aggregate service instance meta for UI purposes
This commit is contained in:
parent
9b96b4baea
commit
e9ea190df0
@ -15,6 +15,7 @@ type ServiceSummary struct {
|
|||||||
Kind structs.ServiceKind `json:",omitempty"`
|
Kind structs.ServiceKind `json:",omitempty"`
|
||||||
Name string
|
Name string
|
||||||
Tags []string
|
Tags []string
|
||||||
|
Meta map[string]string
|
||||||
Nodes []string
|
Nodes []string
|
||||||
ChecksPassing int
|
ChecksPassing int
|
||||||
ChecksWarning int
|
ChecksWarning int
|
||||||
@ -152,6 +153,18 @@ func summarizeServices(dump structs.NodeDump) []*ServiceSummary {
|
|||||||
sum.Tags = service.Tags
|
sum.Tags = service.Tags
|
||||||
sum.Nodes = append(sum.Nodes, node.Node)
|
sum.Nodes = append(sum.Nodes, node.Node)
|
||||||
sum.Kind = service.Kind
|
sum.Kind = service.Kind
|
||||||
|
|
||||||
|
// The service meta is per instance, but we aggregate it
|
||||||
|
// here for the UI to know it exists for _some_ instance.
|
||||||
|
if len(service.Meta) > 0 {
|
||||||
|
if len(sum.Meta) == 0 {
|
||||||
|
sum.Meta = make(map[string]string)
|
||||||
|
}
|
||||||
|
for k, v := range service.Meta {
|
||||||
|
sum.Meta[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodeServices[idx] = sum
|
nodeServices[idx] = sum
|
||||||
}
|
}
|
||||||
for _, check := range node.Checks {
|
for _, check := range node.Checks {
|
||||||
|
@ -168,6 +168,7 @@ func TestSummarizeServices(t *testing.T) {
|
|||||||
Kind: structs.ServiceKindConnectProxy,
|
Kind: structs.ServiceKindConnectProxy,
|
||||||
Service: "web",
|
Service: "web",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Meta: map[string]string{"bar": "baz"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Checks: []*structs.HealthCheck{
|
Checks: []*structs.HealthCheck{
|
||||||
@ -193,6 +194,7 @@ func TestSummarizeServices(t *testing.T) {
|
|||||||
Kind: structs.ServiceKindConnectProxy,
|
Kind: structs.ServiceKindConnectProxy,
|
||||||
Service: "web",
|
Service: "web",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Meta: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Checks: []*structs.HealthCheck{
|
Checks: []*structs.HealthCheck{
|
||||||
@ -249,6 +251,7 @@ func TestSummarizeServices(t *testing.T) {
|
|||||||
Kind: structs.ServiceKindConnectProxy,
|
Kind: structs.ServiceKindConnectProxy,
|
||||||
Name: "web",
|
Name: "web",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
|
Meta: map[string]string{"foo": "bar", "bar": "baz"},
|
||||||
Nodes: []string{"bar", "foo"},
|
Nodes: []string{"bar", "foo"},
|
||||||
ChecksPassing: 2,
|
ChecksPassing: 2,
|
||||||
ChecksWarning: 0,
|
ChecksWarning: 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user