Skip to content

Commit

Permalink
Merge pull request #620 from sapcc/resource_topology_fix
Browse files Browse the repository at this point in the history
Fix: Check resource toplogy
  • Loading branch information
majewsky authored Dec 10, 2024
2 parents 8e808e2 + 032b886 commit 58337d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/collector/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,10 @@ func Test_TopologyScrapes(t *testing.T) {
plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"capacity": {Topology: liquid.AZSeparatedResourceTopology}, "things": {Topology: liquid.AZSeparatedResourceTopology}}
plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"unknown": {}}
mustFailT(t, job.ProcessOne(s.Ctx, withLabel), errors.New("during resource scrape of project germany/berlin: service: unittest, resource: capacity: scrape with topology type: az-separated returned AZs: [unknown]\nservice: unittest, resource: things: scrape with topology type: az-separated returned AZs: [unknown]"))

s.Clock.StepBy(scrapeInterval)
// negative: empty toplogy should be treated as FlatResourceTopology
plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"things": {Topology: ""}}
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]"))
}
9 changes: 4 additions & 5 deletions internal/plugins/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ func CheckResourceTopologies(serviceInfo liquid.ServiceInfo) (err error) {

resourceNames := SortedMapKeys(resources)
for _, resourceName := range resourceNames {
topology := resources[resourceName].Topology
if topology == "" {
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 := resources[resourceName]
resInfo.Topology = liquid.FlatResourceTopology
resources[resourceName] = resInfo
}
if !topology.IsValid() {
errs = append(errs, fmt.Errorf("invalid topology: %s on resource: %s", topology, resourceName))
if !resInfo.Topology.IsValid() {
errs = append(errs, fmt.Errorf("invalid topology: %s on resource: %s", resInfo.Topology, resourceName))
}
}
if len(errs) > 0 {
Expand Down

0 comments on commit 58337d1

Please sign in to comment.