mirror of https://github.com/status-im/consul.git
Support ConnectedWithProxy
This commit is contained in:
parent
dbb461a5d3
commit
51255eede7
|
@ -24,19 +24,19 @@ type GatewayConfig struct {
|
||||||
|
|
||||||
// ServiceSummary is used to summarize a service
|
// ServiceSummary is used to summarize a service
|
||||||
type ServiceSummary struct {
|
type ServiceSummary struct {
|
||||||
Kind structs.ServiceKind `json:",omitempty"`
|
Kind structs.ServiceKind `json:",omitempty"`
|
||||||
Name string
|
Name string
|
||||||
Tags []string
|
Tags []string
|
||||||
Nodes []string
|
Nodes []string
|
||||||
InstanceCount int
|
InstanceCount int
|
||||||
ProxyFor []string `json:",omitempty"`
|
ChecksPassing int
|
||||||
proxyForSet map[string]struct{} // internal to track uniqueness
|
ChecksWarning int
|
||||||
ChecksPassing int
|
ChecksCritical int
|
||||||
ChecksWarning int
|
ExternalSources []string
|
||||||
ChecksCritical int
|
externalSourceSet map[string]struct{} // internal to track uniqueness
|
||||||
ExternalSources []string
|
GatewayConfig GatewayConfig `json:",omitempty"`
|
||||||
externalSourceSet map[string]struct{} // internal to track uniqueness
|
ConnectedWithProxy bool
|
||||||
GatewayConfig GatewayConfig `json:",omitempty"`
|
ConnectedWithGateway bool
|
||||||
|
|
||||||
structs.EnterpriseMeta
|
structs.EnterpriseMeta
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,10 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S
|
||||||
// Collect the summary information
|
// Collect the summary information
|
||||||
var services []structs.ServiceID
|
var services []structs.ServiceID
|
||||||
summary := make(map[structs.ServiceID]*ServiceSummary)
|
summary := make(map[structs.ServiceID]*ServiceSummary)
|
||||||
|
|
||||||
|
hasGateway := make(map[structs.ServiceID]bool)
|
||||||
|
hasProxy := make(map[structs.ServiceID]bool)
|
||||||
|
|
||||||
getService := func(service structs.ServiceID) *ServiceSummary {
|
getService := func(service structs.ServiceID) *ServiceSummary {
|
||||||
serv, ok := summary[service]
|
serv, ok := summary[service]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -241,13 +245,7 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S
|
||||||
sum.Kind = svc.Kind
|
sum.Kind = svc.Kind
|
||||||
sum.InstanceCount += 1
|
sum.InstanceCount += 1
|
||||||
if svc.Kind == structs.ServiceKindConnectProxy {
|
if svc.Kind == structs.ServiceKindConnectProxy {
|
||||||
if _, ok := sum.proxyForSet[svc.Proxy.DestinationServiceName]; !ok {
|
hasProxy[structs.NewServiceID(svc.Proxy.DestinationServiceName, &svc.EnterpriseMeta)] = true
|
||||||
if sum.proxyForSet == nil {
|
|
||||||
sum.proxyForSet = make(map[string]struct{})
|
|
||||||
}
|
|
||||||
sum.proxyForSet[svc.Proxy.DestinationServiceName] = struct{}{}
|
|
||||||
sum.ProxyFor = append(sum.ProxyFor, svc.Proxy.DestinationServiceName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, tag := range svc.Tags {
|
for _, tag := range svc.Tags {
|
||||||
found := false
|
found := false
|
||||||
|
@ -298,6 +296,12 @@ func summarizeServices(dump structs.ServiceDump, cfg *config.RuntimeConfig) []*S
|
||||||
for idx, service := range services {
|
for idx, service := range services {
|
||||||
// Sort the nodes and tags
|
// Sort the nodes and tags
|
||||||
sum := summary[service]
|
sum := summary[service]
|
||||||
|
if hasProxy[service] {
|
||||||
|
sum.ConnectedWithProxy = true
|
||||||
|
}
|
||||||
|
if hasGateway[service] {
|
||||||
|
sum.ConnectedWithGateway = true
|
||||||
|
}
|
||||||
sort.Strings(sum.Nodes)
|
sort.Strings(sum.Nodes)
|
||||||
sort.Strings(sum.Tags)
|
sort.Strings(sum.Tags)
|
||||||
output[idx] = sum
|
output[idx] = sum
|
||||||
|
|
|
@ -315,20 +315,20 @@ func TestUiServices(t *testing.T) {
|
||||||
// internal accounting that users don't see can be blown away
|
// internal accounting that users don't see can be blown away
|
||||||
for _, sum := range summary {
|
for _, sum := range summary {
|
||||||
sum.externalSourceSet = nil
|
sum.externalSourceSet = nil
|
||||||
sum.proxyForSet = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := []*ServiceSummary{
|
expected := []*ServiceSummary{
|
||||||
{
|
{
|
||||||
Kind: structs.ServiceKindTypical,
|
Kind: structs.ServiceKindTypical,
|
||||||
Name: "api",
|
Name: "api",
|
||||||
Tags: []string{"tag1", "tag2"},
|
Tags: []string{"tag1", "tag2"},
|
||||||
Nodes: []string{"foo"},
|
Nodes: []string{"foo"},
|
||||||
InstanceCount: 1,
|
InstanceCount: 1,
|
||||||
ChecksPassing: 2,
|
ChecksPassing: 2,
|
||||||
ChecksWarning: 1,
|
ChecksWarning: 1,
|
||||||
ChecksCritical: 0,
|
ChecksCritical: 0,
|
||||||
EnterpriseMeta: *structs.DefaultEnterpriseMeta(),
|
ConnectedWithProxy: true,
|
||||||
|
EnterpriseMeta: *structs.DefaultEnterpriseMeta(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: structs.ServiceKindTypical,
|
Kind: structs.ServiceKindTypical,
|
||||||
|
@ -347,7 +347,6 @@ func TestUiServices(t *testing.T) {
|
||||||
Tags: nil,
|
Tags: nil,
|
||||||
Nodes: []string{"bar", "foo"},
|
Nodes: []string{"bar", "foo"},
|
||||||
InstanceCount: 2,
|
InstanceCount: 2,
|
||||||
ProxyFor: []string{"api"},
|
|
||||||
ChecksPassing: 2,
|
ChecksPassing: 2,
|
||||||
ChecksWarning: 1,
|
ChecksWarning: 1,
|
||||||
ChecksCritical: 1,
|
ChecksCritical: 1,
|
||||||
|
@ -384,20 +383,20 @@ func TestUiServices(t *testing.T) {
|
||||||
// internal accounting that users don't see can be blown away
|
// internal accounting that users don't see can be blown away
|
||||||
for _, sum := range summary {
|
for _, sum := range summary {
|
||||||
sum.externalSourceSet = nil
|
sum.externalSourceSet = nil
|
||||||
sum.proxyForSet = nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := []*ServiceSummary{
|
expected := []*ServiceSummary{
|
||||||
{
|
{
|
||||||
Kind: structs.ServiceKindTypical,
|
Kind: structs.ServiceKindTypical,
|
||||||
Name: "api",
|
Name: "api",
|
||||||
Tags: []string{"tag1", "tag2"},
|
Tags: []string{"tag1", "tag2"},
|
||||||
Nodes: []string{"foo"},
|
Nodes: []string{"foo"},
|
||||||
InstanceCount: 1,
|
InstanceCount: 1,
|
||||||
ChecksPassing: 2,
|
ChecksPassing: 2,
|
||||||
ChecksWarning: 1,
|
ChecksWarning: 1,
|
||||||
ChecksCritical: 0,
|
ChecksCritical: 0,
|
||||||
EnterpriseMeta: *structs.DefaultEnterpriseMeta(),
|
ConnectedWithProxy: true,
|
||||||
|
EnterpriseMeta: *structs.DefaultEnterpriseMeta(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: structs.ServiceKindConnectProxy,
|
Kind: structs.ServiceKindConnectProxy,
|
||||||
|
@ -405,7 +404,6 @@ func TestUiServices(t *testing.T) {
|
||||||
Tags: nil,
|
Tags: nil,
|
||||||
Nodes: []string{"bar", "foo"},
|
Nodes: []string{"bar", "foo"},
|
||||||
InstanceCount: 2,
|
InstanceCount: 2,
|
||||||
ProxyFor: []string{"api"},
|
|
||||||
ChecksPassing: 2,
|
ChecksPassing: 2,
|
||||||
ChecksWarning: 1,
|
ChecksWarning: 1,
|
||||||
ChecksCritical: 1,
|
ChecksCritical: 1,
|
||||||
|
|
Loading…
Reference in New Issue