@@ -266,8 +266,8 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
266
266
267
267
for _ , candidate := range i .region .instanceTypeInformation {
268
268
269
- logger .Println ("Comparing " , candidate . instanceType , " with " ,
270
- current .instanceType )
269
+ logger .Printf ("Comparing %s with %s " ,
270
+ current .instanceType , candidate . instanceType )
271
271
272
272
candidatePrice := i .calculatePrice (candidate )
273
273
@@ -280,7 +280,7 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
280
280
bestPrice = candidatePrice
281
281
chosenSpotType = candidate .instanceType
282
282
cheapest = candidate
283
- debug .Println ("Best option is now : " , chosenSpotType , " at " , bestPrice )
283
+ logger .Println ("Found compatible instance type : " , chosenSpotType , " at " , bestPrice )
284
284
} else if chosenSpotType != "" {
285
285
debug .Println ("Current best option: " , chosenSpotType , " at " , bestPrice )
286
286
}
@@ -293,7 +293,7 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
293
293
}
294
294
295
295
func (i * instance ) launchSpotReplacement () error {
296
- instanceType , err := i .getCheapestCompatibleSpotInstanceType (
296
+ spotInstanceType , err := i .getCheapestCompatibleSpotInstanceType (
297
297
i .asg .getAllowedInstanceTypes (i ),
298
298
i .asg .getDisallowedInstanceTypes (i ))
299
299
@@ -302,10 +302,9 @@ func (i *instance) launchSpotReplacement() error {
302
302
return err
303
303
}
304
304
305
- bidPrice := i .getPricetoBid (instanceType .pricing .onDemand ,
306
- instanceType .pricing .spot [* i .Placement .AvailabilityZone ])
305
+ bidPrice := i .getPricetoBid (spotInstanceType .pricing .spot [* i .Placement .AvailabilityZone ])
307
306
308
- runInstancesInput := i .createRunInstancesInput (instanceType .instanceType , bidPrice )
307
+ runInstancesInput := i .createRunInstancesInput (spotInstanceType .instanceType , bidPrice )
309
308
resp , err := i .region .services .ec2 .RunInstances (runInstancesInput )
310
309
311
310
if err != nil {
@@ -322,18 +321,20 @@ func (i *instance) launchSpotReplacement() error {
322
321
return nil
323
322
}
324
323
325
- func (i * instance ) getPricetoBid (
326
- baseOnDemandPrice float64 , currentSpotPrice float64 ) float64 {
324
+ func (i * instance ) getPricetoBid (currentSpotPrice float64 ) float64 {
327
325
328
326
logger .Println ("BiddingPolicy: " , i .region .conf .BiddingPolicy )
329
327
330
328
if i .region .conf .BiddingPolicy == DefaultBiddingPolicy {
331
- logger .Println ("Launching spot instance with a bid =" , baseOnDemandPrice )
332
- return baseOnDemandPrice
329
+ logger .Println ("Launching spot instance with bid price" , i .price ,
330
+ "set to the price of the original on-demand instances" )
331
+ return i .price
333
332
}
334
-
335
- bufferPrice := math .Min (baseOnDemandPrice , currentSpotPrice * (1.0 + i .region .conf .SpotPriceBufferPercentage / 100.0 ))
336
- logger .Println ("Launching spot instance with a bid =" , bufferPrice )
333
+ p := i .region .conf .SpotPriceBufferPercentage
334
+ bufferPrice := math .Min (i .price , currentSpotPrice * (1.0 + p / 100.0 ))
335
+ logger .Printf ("Launching spot instance with bid price %.5f set based on " +
336
+ "the current spot price %.5f with an additional buffer of %.2f%%\n " ,
337
+ bufferPrice , currentSpotPrice , p )
337
338
return bufferPrice
338
339
}
339
340
0 commit comments