Clean up ent meta id usage in overview summary

This commit is contained in:
Kyle Havlovitz 2022-03-23 12:47:12 -07:00
parent e530fbfb33
commit 0d9c99b227
3 changed files with 17 additions and 23 deletions

View File

@ -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")

View File

@ -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))

View File

@ -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
}