Skip to content

Commit

Permalink
Fix map key sort
Browse files Browse the repository at this point in the history
  • Loading branch information
VoigtS committed Dec 5, 2024
1 parent d1b5560 commit 697f0e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/plugins/capacity_liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (p *liquidCapacityPlugin) Scrape(ctx context.Context, backchannel core.Capa
resourceNames := SortMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[liquid.ResourceName(resourceName)].PerAZ
toplogy := p.LiquidServiceInfo.Resources[liquid.ResourceName(resourceName)].Topology
perAZ := resp.Resources[resourceName].PerAZ
toplogy := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, toplogy)
if err != nil {
errs = append(errs, fmt.Errorf("service: %s, resource: %s: %w", p.ServiceType, resourceName, err))
Expand Down
4 changes: 2 additions & 2 deletions internal/plugins/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (p *liquidQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePro
resourceNames := SortMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[liquid.ResourceName(resourceName)].PerAZ
toplogy := p.LiquidServiceInfo.Resources[liquid.ResourceName(resourceName)].Topology
perAZ := resp.Resources[resourceName].PerAZ
toplogy := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, toplogy)
if err != nil {
errs = append(errs, fmt.Errorf("service: %s, resource: %s: %w", p.ServiceType, resourceName, err))
Expand Down
13 changes: 5 additions & 8 deletions internal/plugins/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ package plugins
import (
"errors"
"fmt"
"sort"
"maps"
"slices"

"github.com/sapcc/go-api-declarations/liquid"
)
Expand All @@ -31,13 +32,9 @@ func p2u64(val uint64) *uint64 {
return &val
}

func SortMapKeys[M map[K]V, K ~string, V any](mapToSort M) []string {
var sortedKeys []string
for key := range mapToSort {
sortedKeys = append(sortedKeys, string(key))
}
sort.Strings(sortedKeys)

func SortMapKeys[M map[K]V, K ~string, V any](mapToSort M) []K {
sortedKeys := slices.Collect(maps.Keys(mapToSort))
slices.Sort(sortedKeys)
return sortedKeys
}

Expand Down
2 changes: 1 addition & 1 deletion internal/test/plugins/quota_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (p *GenericQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePr
var errs []error
resourceNames := plugins.SortMapKeys(p.LiquidServiceInfo.Resources)
for _, resourceName := range resourceNames {
toplogy := p.LiquidServiceInfo.Resources[liquid.ResourceName(resourceName)].Topology
toplogy := p.LiquidServiceInfo.Resources[resourceName].Topology
err := plugins.MatchLiquidReportToTopology(p.ReportedAZs, toplogy)
if err != nil {
errs = append(errs, fmt.Errorf("service: %s, resource: %s: %w", p.ServiceType, resourceName, err))
Expand Down

0 comments on commit 697f0e9

Please sign in to comment.