Skip to content

Commit

Permalink
Merge pull request #621 from sapcc/match_toplogy
Browse files Browse the repository at this point in the history
fix: check missing resource reports before checking toplogy
  • Loading branch information
majewsky authored Dec 10, 2024
2 parents 58337d1 + d4ed460 commit 3f9bd94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
28 changes: 15 additions & 13 deletions internal/plugins/capacity_liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@ func (p *liquidCapacityPlugin) Scrape(ctx context.Context, backchannel core.Capa
logg.Fatal("ServiceInfo version for %s changed from %d to %d; restarting now to reload ServiceInfo...",
p.LiquidServiceType, p.LiquidServiceInfo.Version, resp.InfoVersion)
}
resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[resourceName].PerAZ
topology := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, topology)
if err != nil {
errs = append(errs, fmt.Errorf("resource: %s: %w", resourceName, err))
}
}
if len(errs) > 0 {
return nil, nil, errors.Join(errs...)
}

resultInService := make(map[liquid.ResourceName]core.PerAZ[core.CapacityData], len(p.LiquidServiceInfo.Resources))
for resName, resInfo := range p.LiquidServiceInfo.Resources {
Expand All @@ -128,6 +115,21 @@ func (p *liquidCapacityPlugin) Scrape(ctx context.Context, backchannel core.Capa
}
resultInService[resName] = resData
}

resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[resourceName].PerAZ
topology := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, topology)
if err != nil {
errs = append(errs, fmt.Errorf("resource: %s: %w", resourceName, err))
}
}
if len(errs) > 0 {
return nil, nil, errors.Join(errs...)
}

result = map[db.ServiceType]map[liquid.ResourceName]core.PerAZ[core.CapacityData]{
p.ServiceType: resultInService,
}
Expand Down
27 changes: 14 additions & 13 deletions internal/plugins/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,6 @@ func (p *liquidQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePro
logg.Fatal("ServiceInfo version for %s changed from %d to %d; restarting now to reload ServiceInfo...",
p.LiquidServiceType, p.LiquidServiceInfo.Version, resp.InfoVersion)
}
resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[resourceName].PerAZ
topology := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, topology)
if err != nil {
errs = append(errs, fmt.Errorf("resource: %s: %w", resourceName, err))
}
}
if len(errs) > 0 {
return nil, nil, errors.Join(errs...)
}

result = make(map[liquid.ResourceName]core.ResourceData, len(p.LiquidServiceInfo.Resources))
for resName, resInfo := range p.LiquidServiceInfo.Resources {
Expand Down Expand Up @@ -167,6 +154,20 @@ func (p *liquidQuotaPlugin) Scrape(ctx context.Context, project core.KeystonePro
result[resName] = resData
}

resourceNames := SortedMapKeys(p.LiquidServiceInfo.Resources)
var errs []error
for _, resourceName := range resourceNames {
perAZ := resp.Resources[resourceName].PerAZ
topology := p.LiquidServiceInfo.Resources[resourceName].Topology
err := MatchLiquidReportToTopology(perAZ, topology)
if err != nil {
errs = append(errs, fmt.Errorf("resource: %s: %w", resourceName, err))
}
}
if len(errs) > 0 {
return nil, nil, errors.Join(errs...)
}

serializedMetrics, err = liquidSerializeMetrics(p.LiquidServiceInfo.UsageMetricFamilies, resp.Metrics)
if err != nil {
return nil, nil, fmt.Errorf("while serializing metrics: %w", err)
Expand Down

0 comments on commit 3f9bd94

Please sign in to comment.