From 0d9c99b227aed9fc0e271d59f5b2c8b15f8e9624 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Wed, 23 Mar 2022 12:47:12 -0700 Subject: [PATCH] Clean up ent meta id usage in overview summary --- agent/consul/internal_endpoint_test.go | 11 ++--------- agent/consul/server_overview.go | 25 +++++++++++++++---------- agent/structs/structs_oss.go | 4 ---- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/agent/consul/internal_endpoint_test.go b/agent/consul/internal_endpoint_test.go index 25c9c75f40..e639c003fe 100644 --- a/agent/consul/internal_endpoint_test.go +++ b/agent/consul/internal_endpoint_test.go @@ -2485,13 +2485,10 @@ func TestInternal_CatalogOverview(t *testing.T) { } t.Parallel() - dir1, s1 := testServerWithConfig(t, func(c *Config) { + _, s1 := testServerWithConfig(t, func(c *Config) { c.MetricsReportingInterval = 100 * time.Millisecond }) - defer os.RemoveAll(dir1) - defer s1.Shutdown() codec := rpcClient(t, s1) - defer codec.Close() testrpc.WaitForLeader(t, s1.RPC, "dc1") @@ -2540,17 +2537,13 @@ func TestInternal_CatalogOverview_ACLDeny(t *testing.T) { t.Parallel() - dir1, s1 := testServerWithConfig(t, func(c *Config) { + _, s1 := testServerWithConfig(t, func(c *Config) { c.PrimaryDatacenter = "dc1" c.ACLsEnabled = true c.ACLInitialManagementToken = TestDefaultInitialManagementToken c.ACLResolverSettings.ACLDefaultPolicy = "deny" }) - defer os.RemoveAll(dir1) - defer s1.Shutdown() - codec := rpcClient(t, s1) - defer codec.Close() testrpc.WaitForLeader(t, s1.RPC, "dc1") diff --git a/agent/consul/server_overview.go b/agent/consul/server_overview.go index 149743d3f2..7417f80324 100644 --- a/agent/consul/server_overview.go +++ b/agent/consul/server_overview.go @@ -69,11 +69,15 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar serviceInstanceChecks := make(map[string][]*structs.HealthCheck) checkSummaries := make(map[string]structs.HealthSummary) + entMetaIDString := func(id string, entMeta structs.EnterpriseMeta) string { + return fmt.Sprintf("%s/%s/%s", id, entMeta.PartitionOrEmpty(), entMeta.NamespaceOrEmpty()) + } + // Compute the health check summaries by taking the pass/warn/fail counts // of each unique part/ns/checkname combo and storing them. Also store the // per-node and per-service instance checks for their respective summaries below. for _, check := range catalog.Checks { - checkID := fmt.Sprintf("%s/%s", check.EnterpriseMeta.String(), check.Name) + checkID := entMetaIDString(check.Name, check.EnterpriseMeta) summary, ok := checkSummaries[checkID] if !ok { summary = structs.HealthSummary{ @@ -86,11 +90,10 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar checkSummaries[checkID] = summary if check.ServiceID != "" { - serviceInstanceID := fmt.Sprintf("%s/%s/%s", check.EnterpriseMeta.String(), check.Node, check.ServiceID) + serviceInstanceID := entMetaIDString(fmt.Sprintf("%s/%s", check.Node, check.ServiceID), check.EnterpriseMeta) serviceInstanceChecks[serviceInstanceID] = append(serviceInstanceChecks[serviceInstanceID], check) } else { - nodeMeta := check.NodeIdentity().EnterpriseMeta - nodeID := fmt.Sprintf("%s/%s", nodeMeta.String(), check.Node) + nodeID := structs.NodeNameString(check.Node, &check.EnterpriseMeta) nodeChecks[nodeID] = append(nodeChecks[nodeID], check) } } @@ -110,7 +113,7 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar } // Compute whether this service instance is healthy based on its associated checks. - serviceInstanceID := fmt.Sprintf("%s/%s/%s", svc.EnterpriseMeta.String(), svc.Node, svc.ServiceID) + serviceInstanceID := entMetaIDString(fmt.Sprintf("%s/%s", svc.Node, svc.ServiceID), svc.EnterpriseMeta) status := api.HealthPassing for _, checks := range serviceInstanceChecks[serviceInstanceID] { if checks.Status == api.HealthWarning && status == api.HealthPassing { @@ -130,8 +133,7 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar // each partition. nodeSummaries := make(map[string]structs.HealthSummary) for _, node := range catalog.Nodes { - nodeMeta := structs.NodeEnterpriseMetaInPartition(node.Partition) - summary, ok := nodeSummaries[nodeMeta.String()] + summary, ok := nodeSummaries[node.Partition] if !ok { summary = structs.HealthSummary{ EnterpriseMeta: *structs.NodeEnterpriseMetaInPartition(node.Partition), @@ -140,7 +142,7 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar // Compute whether this node is healthy based on its associated checks. status := api.HealthPassing - nodeID := fmt.Sprintf("%s/%s", nodeMeta.String(), node.Node) + nodeID := structs.NodeNameString(node.Node, structs.NodeEnterpriseMetaInPartition(node.Partition)) for _, checks := range nodeChecks[nodeID] { if checks.Status == api.HealthWarning && status == api.HealthPassing { status = api.HealthWarning @@ -151,7 +153,7 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar } summary.Add(status) - nodeSummaries[nodeMeta.String()] = summary + nodeSummaries[node.Partition] = summary } // Construct the summary. @@ -171,7 +173,10 @@ func getCatalogOverview(catalog *structs.CatalogContents) *structs.CatalogSummar if slice[i].Name < slice[j].Name { return true } - return slice[i].EnterpriseMeta.String() < slice[j].EnterpriseMeta.String() + if slice[i].NamespaceOrEmpty() < slice[j].NamespaceOrEmpty() { + return true + } + return slice[i].PartitionOrEmpty() < slice[j].PartitionOrEmpty() } } sort.Slice(summary.Nodes, summarySort(summary.Nodes)) diff --git a/agent/structs/structs_oss.go b/agent/structs/structs_oss.go index 7f56c43553..669361802b 100644 --- a/agent/structs/structs_oss.go +++ b/agent/structs/structs_oss.go @@ -15,10 +15,6 @@ var emptyEnterpriseMeta = EnterpriseMeta{} // EnterpriseMeta stub type EnterpriseMeta struct{} -func (m *EnterpriseMeta) String() string { - return "" -} - func (m *EnterpriseMeta) ToEnterprisePolicyMeta() *acl.EnterprisePolicyMeta { return nil }