Skip to content

Commit

Permalink
fix MatchLiquidReportToTopology map type - fix unit test typing
Browse files Browse the repository at this point in the history
  • Loading branch information
VoigtS committed Dec 5, 2024
1 parent 463e9ea commit df05bc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions internal/collector/scrape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,9 @@ func Test_TopologyScrapes(t *testing.T) {
tr, tr0 := easypg.NewTracker(t, s.DB.Db)
tr0.AssertEqualToFile("fixtures/scrape0.sql")

var status *any
// positive: Sync az-separated quota values with the backend
plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"capacity": {Topology: liquid.AZSeparatedResourceTopology}, "things": {Topology: liquid.AZSeparatedResourceTopology}}
plugin.ReportedAZs = map[liquid.AvailabilityZone]*any{"az-one": status, "az-two": status}
plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"az-one": {}, "az-two": {}}
mustT(t, job.ProcessOne(s.Ctx, withLabel))
mustT(t, job.ProcessOne(s.Ctx, withLabel))

Expand Down Expand Up @@ -703,18 +702,18 @@ func Test_TopologyScrapes(t *testing.T) {

// negative: scrape with flat topology returns invalid AZs
plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"capacity": {Topology: liquid.FlatResourceTopology}}
plugin.ReportedAZs = map[liquid.AvailabilityZone]*any{"az-one": status, "az-two": status}
plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"az-one": {}, "az-two": {}}
mustFailT(t, job.ProcessOne(s.Ctx, withLabel), errors.New("during resource scrape of project germany/berlin: service: unittest, resource: capacity: scrape with topology type: flat returned AZs: [az-one az-two]"))

// negative: scrape with az-aware topology returns invalid any AZ
plugin.LiquidServiceInfo.Resources["capacity"] = liquid.ResourceInfo{Topology: liquid.AZAwareResourceTopology}
plugin.ReportedAZs = map[liquid.AvailabilityZone]*any{"any": status}
plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"any": {}}
mustFailT(t, job.ProcessOne(s.Ctx, withLabel), errors.New("during resource scrape of project germany/dresden: service: unittest, resource: capacity: scrape with topology type: az-aware returned AZs: [any]"))

s.Clock.StepBy(scrapeInterval)
// negative: scrape with az-separated topology returns invalid AZs any and unknown
plugin.LiquidServiceInfo.Resources["capacity"] = liquid.ResourceInfo{Topology: liquid.AZSeparatedResourceTopology}
plugin.ReportedAZs = map[liquid.AvailabilityZone]*any{"az-one": status, "unknown": status}
plugin.ReportedAZs = map[liquid.AvailabilityZone]struct{}{"az-one": {}, "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: [az-one unknown]"))

// negative: reject liquid initialization with invalid topologies
Expand All @@ -724,6 +723,6 @@ func Test_TopologyScrapes(t *testing.T) {
s.Clock.StepBy(scrapeInterval)
// negative: multiple resources with mismatching topology to AZ responses
plugin.LiquidServiceInfo.Resources = map[liquid.ResourceName]liquid.ResourceInfo{"capacity": {Topology: liquid.AZSeparatedResourceTopology}, "things": {Topology: liquid.AZSeparatedResourceTopology}}
plugin.ReportedAZs = map[liquid.AvailabilityZone]*any{"unknown": status}
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]"))
}
2 changes: 1 addition & 1 deletion internal/plugins/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CheckResourceTopologies(serviceInfo liquid.ServiceInfo) (err error) {
return
}

func MatchLiquidReportToTopology[V any](perAZReport map[liquid.AvailabilityZone]*V, topology liquid.ResourceTopology) (err error) {
func MatchLiquidReportToTopology[V any](perAZReport map[liquid.AvailabilityZone]V, topology liquid.ResourceTopology) (err error) {
_, anyExists := perAZReport[liquid.AvailabilityZoneAny]
_, unknownExists := perAZReport[liquid.AvailabilityZoneUnknown]
switch topology {
Expand Down
10 changes: 5 additions & 5 deletions internal/test/plugins/quota_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ type GenericQuotaPlugin struct {
StaticResourceAttributes map[liquid.ResourceName]map[string]any `yaml:"-"`
OverrideQuota map[string]map[liquid.ResourceName]liquid.ResourceQuotaRequest `yaml:"-"` // first key is project UUID
// behavior flags that can be set by a unit test
ReportedAZs map[liquid.AvailabilityZone]*any `yaml:"-"`
ScrapeFails bool `yaml:"-"`
SetQuotaFails bool `yaml:"-"`
MinQuota map[liquid.ResourceName]uint64 `yaml:"-"`
MaxQuota map[liquid.ResourceName]uint64 `yaml:"-"`
ReportedAZs map[liquid.AvailabilityZone]struct{} `yaml:"-"`
ScrapeFails bool `yaml:"-"`
SetQuotaFails bool `yaml:"-"`
MinQuota map[liquid.ResourceName]uint64 `yaml:"-"`
MaxQuota map[liquid.ResourceName]uint64 `yaml:"-"`
}

// Init implements the core.QuotaPlugin interface.
Expand Down

0 comments on commit df05bc7

Please sign in to comment.