From b9d840010b25bb8279e4c2c339273b06784f9ca7 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Thu, 12 Dec 2024 15:41:45 +0100 Subject: [PATCH] allow unspecified topology only for the one remaining legacy case --- internal/collector/scrape_test.go | 2 +- internal/plugins/utils.go | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/collector/scrape_test.go b/internal/collector/scrape_test.go index 0102707d..641e6706 100644 --- a/internal/collector/scrape_test.go +++ b/internal/collector/scrape_test.go @@ -757,7 +757,7 @@ func Test_TopologyScrapes(t *testing.T) { s.Clock.StepBy(scrapeInterval) // negative: empty toplogy should be treated as FlatResourceTopology - plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"things": {Topology: ""}} + plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"things": {Topology: liquid.FlatResourceTopology}} plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"az-one": {}} mustFailT(t, job.ProcessOne(s.Ctx, withLabel), errors.New("during resource scrape of project germany/dresden: service: unittest, resource: things: scrape with topology type: flat returned AZs: [az-one]")) } diff --git a/internal/plugins/utils.go b/internal/plugins/utils.go index ed627c08..fa9e30bc 100644 --- a/internal/plugins/utils.go +++ b/internal/plugins/utils.go @@ -26,7 +26,6 @@ import ( "slices" "github.com/sapcc/go-api-declarations/liquid" - "github.com/sapcc/go-bits/logg" ) func p2u64(val uint64) *uint64 { @@ -40,21 +39,23 @@ func SortedMapKeys[M map[K]V, K ~string, V any](mapToSort M) []K { } func CheckResourceTopologies(serviceInfo liquid.ServiceInfo) (err error) { + // TODO: remove this special case once liquid-ceph has rolled out their topology support + // (if you come across this, it's probably time; ping Stefan M. to ask for confirmation) + for resName, resInfo := range serviceInfo.Resources { + if resName == "objectstore_region_3_hdd_capacity" && resInfo.Topology == "" { + resInfo.Topology = liquid.FlatResourceTopology + serviceInfo.Resources[resName] = resInfo + } + } + var errs []error resources := serviceInfo.Resources resourceNames := SortedMapKeys(resources) for _, resourceName := range resourceNames { - resInfo := resources[resourceName] - if resInfo.Topology == "" { - // several algorithms inside Limes depend on a topology being chosen, so we have to pick a default for now - // TODO: make this a fatal error once liquid-ceph has rolled out their Topology patch - logg.Error("missing topology on resource: %s (assuming %q)", resourceName, liquid.FlatResourceTopology) - resInfo.Topology = liquid.FlatResourceTopology - resources[resourceName] = resInfo - } - if !resInfo.Topology.IsValid() { - errs = append(errs, fmt.Errorf("invalid topology: %s on resource: %s", resInfo.Topology, resourceName)) + topology := resources[resourceName].Topology + if !topology.IsValid() { + errs = append(errs, fmt.Errorf("invalid topology: %s on resource: %s", topology, resourceName)) } } if len(errs) > 0 {