Skip to content

Commit 59a2032

Browse files
ppitonakadrianriobo
authored andcommitted
feat(spot): more detailed debug logs
1. on demand: print which instance type was randomly chosen 2. spot: print more details when no good choice was found Signed-off-by: Pavol Pitonak <ppitonak@redhat.com>
1 parent 56ee9b7 commit 59a2032

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

pkg/provider/aws/data/spot.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func SpotInfo(mCtx *mc.Context, args *SpotInfoArgs) (*spot.SpotResults, error) {
210210
len(args.InstaceTypes) < maxNumberOfTypesForSpot,
211211
len(args.InstaceTypes),
212212
maxNumberOfTypesForSpot)
213-
c, err := selectSpotChoice(
213+
c, err := selectSpotChoice(mCtx,
214214
&spotChoiceArgs{
215215
placementScores: placementScores,
216216
spotPricing: spotPricing,
@@ -251,7 +251,7 @@ type spotChoiceArgs struct {
251251
// # Also function take cares to transfrom from AzID to AZName
252252
//
253253
// first option matching the requirements will be returned
254-
func selectSpotChoice(args *spotChoiceArgs, numberOfTypesForSpot int) (*SpotInfoResult, error) {
254+
func selectSpotChoice(mCtx *mc.Context, args *spotChoiceArgs, numberOfTypesForSpot int) (*SpotInfoResult, error) {
255255
result := make(map[string]*SpotInfoResult)
256256
// This can bexecuted async
257257
for r, pss := range args.spotPricing {
@@ -283,15 +283,45 @@ func selectSpotChoice(args *spotChoiceArgs, numberOfTypesForSpot int) (*SpotInfo
283283
return s.Price
284284
})
285285
if len(spis) == 0 {
286-
return nil, fmt.Errorf("no good choice was found")
286+
if mCtx.Debug() {
287+
// Log diagnostic details to help understand why no choice was found
288+
pricingRegions := utilMaps.Keys(args.spotPricing)
289+
placementRegions := utilMaps.Keys(args.placementScores)
290+
logging.Debugf("No spot choice found. Regions with pricing data: %v", pricingRegions)
291+
logging.Debugf("No spot choice found. Regions with placement scores: %v", placementRegions)
292+
for r, pss := range args.spotPricing {
293+
// Count unique instance types with pricing in this region, grouped by AZ
294+
azTypes := make(map[string][]string)
295+
for _, ps := range pss {
296+
azTypes[ps.AvailabilityZone] = append(azTypes[ps.AvailabilityZone], ps.InstanceType)
297+
}
298+
for az, types := range azTypes {
299+
hasPlacement := false
300+
if scores, ok := args.placementScores[r]; ok {
301+
for _, s := range scores {
302+
if s.azName == az {
303+
hasPlacement = true
304+
break
305+
}
306+
}
307+
}
308+
logging.Debugf(" Region %s, AZ %s: %d instance type(s) with pricing %v, has placement score: %t (need %d types per AZ)",
309+
r, az, len(types), types, hasPlacement, numberOfTypesForSpot)
310+
}
311+
}
312+
}
313+
return nil, fmt.Errorf("no good spot choice was found: need %d instance types in the same AZ with both spot pricing and placement scores above minimum threshold, but no AZ met this requirement",
314+
numberOfTypesForSpot)
287315
}
288-
logging.Debugf("Sorted %d spot options by price", len(spis))
289-
for i, spi := range spis {
290-
logging.Debugf(" Option %d: Region %s, AZ %s, Price $%.4f, Score %d, Instance types: %v",
291-
i+1, spi.Region, spi.AvailabilityZone, spi.Price, spi.Score, spi.InstanceType)
316+
if mCtx.Debug() {
317+
logging.Debugf("Sorted %d spot options by price", len(spis))
318+
for i, spi := range spis {
319+
logging.Debugf(" Option %d: Region %s, AZ %s, Price $%.4f, Score %d, Instance types: %v",
320+
i+1, spi.Region, spi.AvailabilityZone, spi.Price, spi.Score, spi.InstanceType)
321+
}
322+
logging.Debugf("Selected cheapest option - Region %s, AZ %s, Price $%.4f, Score %d, Instance types: %v",
323+
spis[0].Region, spis[0].AvailabilityZone, spis[0].Price, spis[0].Score, spis[0].InstanceType)
292324
}
293-
logging.Debugf("Selected cheapest option - Region %s, AZ %s, Price $%.4f, Score %d, Instance types: %v",
294-
spis[0].Region, spis[0].AvailabilityZone, spis[0].Price, spis[0].Score, spis[0].InstanceType)
295325
return spis[0], nil
296326
}
297327

pkg/provider/aws/modules/ec2/compute/compute.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ func (r *ComputeRequest) onDemandInstance(ctx *pulumi.Context) (*ec2.Instance, e
105105
if r.DiskSize != nil {
106106
volSize = *r.DiskSize
107107
}
108+
instanceType := util.RandomItemFromArray(r.InstaceTypes)
109+
logging.Debugf("Requesting an on-demand instance of type: %s", instanceType)
108110
args := ec2.InstanceArgs{
109111
SubnetId: r.Subnet.ID(),
110112
Ami: pulumi.String(r.AMI.Id),
111-
InstanceType: pulumi.String(util.RandomItemFromArray(r.InstaceTypes)),
113+
InstanceType: pulumi.String(instanceType),
112114
KeyName: r.KeyResources.AWSKeyPair.KeyName,
113115
AssociatePublicIpAddress: pulumi.Bool(true),
114116
VpcSecurityGroupIds: r.SecurityGroups,

0 commit comments

Comments
 (0)