19320: Deduplicate instance types in spot price request.
authorTom Clegg <tom@curii.com>
Tue, 24 Jan 2023 23:04:07 +0000 (18:04 -0500)
committerTom Clegg <tom@curii.com>
Tue, 24 Jan 2023 23:04:07 +0000 (18:04 -0500)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/cloud/ec2/ec2.go

index a4f6b2da7c1f627c9d215713f1d0851dc8f10e9b..b90eff6d571301085c2acd3d9bb8df56d1cfe54c 100644 (file)
@@ -337,7 +337,8 @@ func (instanceSet *ec2InstanceSet) updateSpotPrices(instances []cloud.Instance)
        updateTime := time.Now()
        staleTime := updateTime.Add(-instanceSet.ec2config.SpotPriceUpdateInterval.Duration())
        needUpdate := false
-       var typeFilterValues []*string
+       allTypes := map[string]bool{}
+
        for _, inst := range instances {
                ec2inst := inst.(*ec2Instance).instance
                if aws.StringValue(ec2inst.InstanceLifecycle) == "spot" {
@@ -349,12 +350,16 @@ func (instanceSet *ec2InstanceSet) updateSpotPrices(instances []cloud.Instance)
                        if instanceSet.pricesUpdated[pk].Before(staleTime) {
                                needUpdate = true
                        }
-                       typeFilterValues = append(typeFilterValues, ec2inst.InstanceType)
+                       allTypes[*ec2inst.InstanceType] = true
                }
        }
        if !needUpdate {
                return
        }
+       var typeFilterValues []*string
+       for instanceType := range allTypes {
+               typeFilterValues = append(typeFilterValues, aws.String(instanceType))
+       }
        // Get 3x update interval worth of pricing data. (Ideally the
        // AWS API would tell us "we have shown you all of the price
        // changes up to time T", but it doesn't, so we'll just ask