From 51255eede77de7ee77da57851a735d7ce618c42f Mon Sep 17 00:00:00 2001 From: freddygv Date: Wed, 29 Jul 2020 09:10:06 -0600 Subject: [PATCH] Support ConnectedWithProxy --- agent/ui_endpoint.go | 44 +++++++++++++++++++++------------------ agent/ui_endpoint_test.go | 42 ++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/agent/ui_endpoint.go b/agent/ui_endpoint.go index 202297d986..b37b06bfa3 100644 --- a/agent/ui_endpoint.go +++ b/agent/ui_endpoint.go @@ -24,19 +24,19 @@ type GatewayConfig struct { // ServiceSummary is used to summarize a service type ServiceSummary struct { - Kind structs.ServiceKind `json:",omitempty"` - Name string - Tags []string - Nodes []string - InstanceCount int - ProxyFor []string `json:",omitempty"` - proxyForSet map[string]struct{} // internal to track uniqueness - ChecksPassing int - ChecksWarning int - ChecksCritical int - ExternalSources []string - externalSourceSet map[string]struct{} // internal to track uniqueness - GatewayConfig GatewayConfig `json:",omitempty"` + Kind structs.ServiceKind `json:",omitempty"` + Name string + Tags []string + Nodes []string + InstanceCount int + ChecksPassing int + ChecksWarning int + ChecksCritical int + ExternalSources []string + externalSourceSet map[string]struct{} // internal to track uniqueness + GatewayConfig GatewayConfig `json:",omitempty"` + ConnectedWithProxy bool + ConnectedWithGateway bool structs.EnterpriseMeta } @@ -206,6 +206,10 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S // Collect the summary information var services []structs.ServiceID summary := make(map[structs.ServiceID]*ServiceSummary) + + hasGateway := make(map[structs.ServiceID]bool) + hasProxy := make(map[structs.ServiceID]bool) + getService := func(service structs.ServiceID) *ServiceSummary { serv, ok := summary[service] if !ok { @@ -241,13 +245,7 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S sum.Kind = svc.Kind sum.InstanceCount += 1 if svc.Kind == structs.ServiceKindConnectProxy { - if _, ok := sum.proxyForSet[svc.Proxy.DestinationServiceName]; !ok { - if sum.proxyForSet == nil { - sum.proxyForSet = make(map[string]struct{}) - } - sum.proxyForSet[svc.Proxy.DestinationServiceName] = struct{}{} - sum.ProxyFor = append(sum.ProxyFor, svc.Proxy.DestinationServiceName) - } + hasProxy[structs.NewServiceID(svc.Proxy.DestinationServiceName, &svc.EnterpriseMeta)] = true } for _, tag := range svc.Tags { found := false @@ -298,6 +296,12 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S for idx, service := range services { // Sort the nodes and tags sum := summary[service] + if hasProxy[service] { + sum.ConnectedWithProxy = true + } + if hasGateway[service] { + sum.ConnectedWithGateway = true + } sort.Strings(sum.Nodes) sort.Strings(sum.Tags) output[idx] = sum diff --git a/agent/ui_endpoint_test.go b/agent/ui_endpoint_test.go index 4694e392b8..a40fdc12c0 100644 --- a/agent/ui_endpoint_test.go +++ b/agent/ui_endpoint_test.go @@ -315,20 +315,20 @@ func TestUiServices(t *testing.T) { // internal accounting that users don't see can be blown away for _, sum := range summary { sum.externalSourceSet = nil - sum.proxyForSet = nil } expected := []*ServiceSummary{ { - Kind: structs.ServiceKindTypical, - Name: "api", - Tags: []string{"tag1", "tag2"}, - Nodes: []string{"foo"}, - InstanceCount: 1, - ChecksPassing: 2, - ChecksWarning: 1, - ChecksCritical: 0, - EnterpriseMeta: *structs.DefaultEnterpriseMeta(), + Kind: structs.ServiceKindTypical, + Name: "api", + Tags: []string{"tag1", "tag2"}, + Nodes: []string{"foo"}, + InstanceCount: 1, + ChecksPassing: 2, + ChecksWarning: 1, + ChecksCritical: 0, + ConnectedWithProxy: true, + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, { Kind: structs.ServiceKindTypical, @@ -347,7 +347,6 @@ func TestUiServices(t *testing.T) { Tags: nil, Nodes: []string{"bar", "foo"}, InstanceCount: 2, - ProxyFor: []string{"api"}, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 1, @@ -384,20 +383,20 @@ func TestUiServices(t *testing.T) { // internal accounting that users don't see can be blown away for _, sum := range summary { sum.externalSourceSet = nil - sum.proxyForSet = nil } expected := []*ServiceSummary{ { - Kind: structs.ServiceKindTypical, - Name: "api", - Tags: []string{"tag1", "tag2"}, - Nodes: []string{"foo"}, - InstanceCount: 1, - ChecksPassing: 2, - ChecksWarning: 1, - ChecksCritical: 0, - EnterpriseMeta: *structs.DefaultEnterpriseMeta(), + Kind: structs.ServiceKindTypical, + Name: "api", + Tags: []string{"tag1", "tag2"}, + Nodes: []string{"foo"}, + InstanceCount: 1, + ChecksPassing: 2, + ChecksWarning: 1, + ChecksCritical: 0, + ConnectedWithProxy: true, + EnterpriseMeta: *structs.DefaultEnterpriseMeta(), }, { Kind: structs.ServiceKindConnectProxy, @@ -405,7 +404,6 @@ func TestUiServices(t *testing.T) { Tags: nil, Nodes: []string{"bar", "foo"}, InstanceCount: 2, - ProxyFor: []string{"api"}, ChecksPassing: 2, ChecksWarning: 1, ChecksCritical: 1,