agent: aggregate service instance meta for UI purposes

This commit is contained in:
Mitchell Hashimoto 2018-09-06 12:19:05 -07:00
parent 9b96b4baea
commit e9ea190df0
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 16 additions and 0 deletions

View File

@ -15,6 +15,7 @@ type ServiceSummary struct {
Kind structs.ServiceKind `json:",omitempty"`
Name string
Tags []string
Meta map[string]string
Nodes []string
ChecksPassing int
ChecksWarning int
@ -152,6 +153,18 @@ func summarizeServices(dump structs.NodeDump) []*ServiceSummary {
sum.Tags = service.Tags
sum.Nodes = append(sum.Nodes, node.Node)
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
}
for _, check := range node.Checks {

View File

@ -168,6 +168,7 @@ func TestSummarizeServices(t *testing.T) {
Kind: structs.ServiceKindConnectProxy,
Service: "web",
Tags: []string{},
Meta: map[string]string{"bar": "baz"},
},
},
Checks: []*structs.HealthCheck{
@ -193,6 +194,7 @@ func TestSummarizeServices(t *testing.T) {
Kind: structs.ServiceKindConnectProxy,
Service: "web",
Tags: []string{},
Meta: map[string]string{"foo": "bar"},
},
},
Checks: []*structs.HealthCheck{
@ -249,6 +251,7 @@ func TestSummarizeServices(t *testing.T) {
Kind: structs.ServiceKindConnectProxy,
Name: "web",
Tags: []string{},
Meta: map[string]string{"foo": "bar", "bar": "baz"},
Nodes: []string{"bar", "foo"},
ChecksPassing: 2,
ChecksWarning: 0,