Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
113741: CRDB-31650 : Add Spot instance support to roachtest  r=BabuSrithar a=BabuSrithar

Fixes CRDB-31650 

Add UseSpot instance option. 

Co-authored-by: babusrithar <babusrithar@cockroachlabs.com>
  • Loading branch information
craig[bot] and BabuSrithar committed Nov 10, 2023
2 parents 70157c7 + 4099752 commit aa7c338
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pkg/cmd/roachtest/spec/cluster_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ type ClusterSpec struct {
ReusePolicy clusterReusePolicy
TerminateOnMigration bool
UbuntuVersion vm.UbuntuVersion

// Use a spot instance or equivalent of a cloud provider.
UseSpot bool
// FileSystem determines the underlying FileSystem
// to be used. The default is ext4.
FileSystem fileSystemType
Expand Down Expand Up @@ -196,6 +197,7 @@ func getGCEOpts(
minCPUPlatform string,
arch vm.CPUArch,
volumeType string,
useSpot bool,
) vm.ProviderOpts {
opts := gce.DefaultProviderOpts()
opts.MachineType = machineType
Expand All @@ -220,6 +222,7 @@ func getGCEOpts(
opts.UseMultipleDisks = !RAID0
}
opts.TerminateOnMigration = terminateOnMigration
opts.UseSpot = useSpot
if volumeType != "" {
opts.PDVolumeType = volumeType
}
Expand Down Expand Up @@ -426,7 +429,7 @@ func (s *ClusterSpec) RoachprodOpts(
case GCE:
providerOpts = getGCEOpts(machineType, zones, s.VolumeSize, ssdCount,
createVMOpts.SSDOpts.UseLocalSSD, s.RAID0, s.TerminateOnMigration,
s.GCE.MinCPUPlatform, vm.ParseArch(createVMOpts.Arch), s.GCE.VolumeType,
s.GCE.MinCPUPlatform, vm.ParseArch(createVMOpts.Arch), s.GCE.VolumeType, s.UseSpot,
)
case Azure:
providerOpts = getAzureOpts(machineType, zones)
Expand Down
13 changes: 13 additions & 0 deletions pkg/cmd/roachtest/spec/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ func TerminateOnMigration() Option {
}
}

// UseSpotInstances creates a spot instance or equivalent of a cloud provider.
// Using this option creates SpotVMs instead of on demand VMS. SpotVMS are
// cheaper but can be terminated at any time by the cloud provider.
// This option is only supported by GCE for now.
// See https://cloud.google.com/compute/docs/instances/spot,
// https://azure.microsoft.com/en-in/products/virtual-machines/spot
// and https://aws.amazon.com/ec2/spot/ for more details.
func UseSpotInstances() Option {
return func(spec *ClusterSpec) {
spec.UseSpot = true
}
}

// SetFileSystem is an Option which can be used to set
// the underlying file system to be used.
func SetFileSystem(fs fileSystemType) Option {
Expand Down
12 changes: 6 additions & 6 deletions pkg/roachprod/vm/gce/gcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ func DefaultProviderOpts() *ProviderOpts {
PDVolumeType: "pd-ssd",
PDVolumeSize: 500,
TerminateOnMigration: false,
UseSpot: false,
useSharedUser: true,
preemptible: false,
useSpot: false,
}
}

Expand All @@ -295,17 +295,17 @@ type ProviderOpts struct {
PDVolumeType string
PDVolumeSize int
UseMultipleDisks bool
// use spot instances (i.e., latest version of preemptibles which can run > 24 hours)
UseSpot bool

// GCE allows two availability policies in case of a maintenance event (see --maintenance-policy via gcloud),
// 'TERMINATE' or 'MIGRATE'. The default is 'MIGRATE' which we denote by 'TerminateOnMigration == false'.
TerminateOnMigration bool

// useSharedUser indicates that the shared user rather than the personal
// user should be used to ssh into the remote machines.
useSharedUser bool
// use preemptible instances
preemptible bool
// use spot instances (i.e., latest version of preemptibles which can run > 24 hours)
useSpot bool
}

// Provider is the GCE implementation of the vm.Provider interface.
Expand Down Expand Up @@ -835,7 +835,7 @@ func (o *ProviderOpts) ConfigureCreateFlags(flags *pflag.FlagSet) {
strings.Join(defaultZones, ",")))
flags.BoolVar(&o.preemptible, ProviderName+"-preemptible", false,
"use preemptible GCE instances (lifetime cannot exceed 24h)")
flags.BoolVar(&o.useSpot, ProviderName+"-use-spot", false,
flags.BoolVar(&o.UseSpot, ProviderName+"-use-spot", false,
"use spot GCE instances (like preemptible but lifetime can exceed 24h)")
flags.BoolVar(&o.TerminateOnMigration, ProviderName+"-terminateOnMigration", false,
"use 'TERMINATE' maintenance policy (for GCE live migrations)")
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func (p *Provider) Create(
// Preemptible instances require the following arguments set explicitly
args = append(args, "--maintenance-policy", "TERMINATE")
args = append(args, "--no-restart-on-failure")
} else if providerOpts.useSpot {
} else if providerOpts.UseSpot {
args = append(args, "--provisioning-model", "SPOT")
} else {
if providerOpts.TerminateOnMigration {
Expand Down

0 comments on commit aa7c338

Please sign in to comment.