From d4ed460044bb8e67cbc198c8f74137329cc35ebc Mon Sep 17 00:00:00 2001 From: VoigtS Date: Tue, 10 Dec 2024 14:23:09 +0100 Subject: [PATCH] fix: check missing resource reports before checking toplogy --- internal/plugins/capacity_liquid.go | 28 +++++++++++++++------------- internal/plugins/liquid.go | 27 ++++++++++++++------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/internal/plugins/capacity_liquid.go b/internal/plugins/capacity_liquid.go index b487cf45..76f60b65 100644 --- a/internal/plugins/capacity_liquid.go +++ b/internal/plugins/capacity_liquid.go @@ -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 { @@ -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, } diff --git a/internal/plugins/liquid.go b/internal/plugins/liquid.go index c6105de5..13a08872 100644 --- a/internal/plugins/liquid.go +++ b/internal/plugins/liquid.go @@ -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 { @@ -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)