@@ -293,8 +293,8 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
293293
294294 for _ , candidate := range i .region .instanceTypeInformation {
295295
296- logger .Println ("Comparing " , candidate . instanceType , " with " ,
297- current .instanceType )
296+ logger .Printf ("Comparing %s with %s " ,
297+ current .instanceType , candidate . instanceType )
298298
299299 candidatePrice := i .calculatePrice (candidate )
300300
@@ -307,7 +307,7 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
307307 bestPrice = candidatePrice
308308 chosenSpotType = candidate .instanceType
309309 cheapest = candidate
310- debug .Println ("Best option is now : " , chosenSpotType , " at " , bestPrice )
310+ logger .Println ("Found compatible instance type : " , chosenSpotType , " at " , bestPrice )
311311 } else if chosenSpotType != "" {
312312 debug .Println ("Current best option: " , chosenSpotType , " at " , bestPrice )
313313 }
@@ -320,7 +320,7 @@ func (i *instance) getCheapestCompatibleSpotInstanceType(allowedList []string, d
320320}
321321
322322func (i * instance ) launchSpotReplacement () error {
323- instanceType , err := i .getCheapestCompatibleSpotInstanceType (
323+ spotInstanceType , err := i .getCheapestCompatibleSpotInstanceType (
324324 i .asg .getAllowedInstanceTypes (i ),
325325 i .asg .getDisallowedInstanceTypes (i ))
326326
@@ -329,10 +329,9 @@ func (i *instance) launchSpotReplacement() error {
329329 return err
330330 }
331331
332- bidPrice := i .getPricetoBid (instanceType .pricing .onDemand ,
333- instanceType .pricing .spot [* i .Placement .AvailabilityZone ])
332+ bidPrice := i .getPricetoBid (spotInstanceType .pricing .spot [* i .Placement .AvailabilityZone ])
334333
335- runInstancesInput := i .createRunInstancesInput (instanceType .instanceType , bidPrice )
334+ runInstancesInput := i .createRunInstancesInput (spotInstanceType .instanceType , bidPrice )
336335 resp , err := i .region .services .ec2 .RunInstances (runInstancesInput )
337336
338337 if err != nil {
@@ -349,18 +348,20 @@ func (i *instance) launchSpotReplacement() error {
349348 return nil
350349}
351350
352- func (i * instance ) getPricetoBid (
353- baseOnDemandPrice float64 , currentSpotPrice float64 ) float64 {
351+ func (i * instance ) getPricetoBid (currentSpotPrice float64 ) float64 {
354352
355353 logger .Println ("BiddingPolicy: " , i .region .conf .BiddingPolicy )
356354
357355 if i .region .conf .BiddingPolicy == DefaultBiddingPolicy {
358- logger .Println ("Launching spot instance with a bid =" , baseOnDemandPrice )
359- return baseOnDemandPrice
356+ logger .Println ("Launching spot instance with bid price" , i .price ,
357+ "set to the price of the original on-demand instances" )
358+ return i .price
360359 }
361-
362- bufferPrice := math .Min (baseOnDemandPrice , currentSpotPrice * (1.0 + i .region .conf .SpotPriceBufferPercentage / 100.0 ))
363- logger .Println ("Launching spot instance with a bid =" , bufferPrice )
360+ p := i .region .conf .SpotPriceBufferPercentage
361+ bufferPrice := math .Min (i .price , currentSpotPrice * (1.0 + p / 100.0 ))
362+ logger .Printf ("Launching spot instance with bid price %.5f set based on " +
363+ "the current spot price %.5f with an additional buffer of %.2f%%\n " ,
364+ bufferPrice , currentSpotPrice , p )
364365 return bufferPrice
365366}
366367
0 commit comments