Skip to content

Commit

Permalink
roachtest: add overrides to perturbation/* tests
Browse files Browse the repository at this point in the history
Allow the user to override perturbations by specifying the environment
variable `PERTURBATION_OVERRIDE`. This applies to all perturbation
tests, but is useful for reproducing specific metamorphic failures where
it is unclear which parameter change caused the difference.

An example of using an override to modify the test block size:

```
PERTURBATION_OVERRIDE=blockSize=1024 roachtest run
perturbation/full/addNode
```

Epic: none

Release note: None
  • Loading branch information
andrewbaptist committed Nov 15, 2024
1 parent e61fbff commit 62303c3
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions pkg/cmd/roachtest/tests/perturbation/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"io"
"math"
"math/rand"
"os"
"reflect"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -278,6 +280,16 @@ func (v variations) perturbationName() string {

// finishSetup completes initialization of the variations.
func (v variations) finishSetup() variations {
// Apply any environment variable overrides first.
if overrides, found := os.LookupEnv("PERTURBATION_OVERRIDE"); found {
for _, override := range strings.Split(overrides, ",") {
parts := strings.Split(override, "=")
if err := v.applyEnvOverride(parts[0], parts[1]); err != nil {
panic(fmt.Sprintf("can't apply override: %s: %v", override, err))
}
}
}

for k, val := range v.acMode.getSettings() {
v.clusterSettings[k] = val
}
Expand All @@ -286,6 +298,64 @@ func (v variations) finishSetup() variations {
return v
}

// applyEnvOverride applies a single override to the test.
func (v *variations) applyEnvOverride(key string, val string) (err error) {
switch key {
case "fillDuration":
v.fillDuration, err = time.ParseDuration(val)
case "blockSize":
v.maxBlockBytes, err = strconv.Atoi(val)
case "perturbationDuration":
v.perturbationDuration, err = time.ParseDuration(val)
case "validationDuration":
v.validationDuration, err = time.ParseDuration(val)
case "ratioOfMax":
v.ratioOfMax, err = strconv.ParseFloat(val, 64)
case "splits":
v.splits, err = strconv.Atoi(val)
case "numNodes":
v.numNodes, err = strconv.Atoi(val)
case "numWorkloadNodes":
v.numWorkloadNodes, err = strconv.Atoi(val)
case "vcpu":
v.vcpu, err = strconv.Atoi(val)
case "disks":
v.disks, err = strconv.Atoi(val)
case "mem":
v.mem = spec.ParseMemCPU(val)
if v.mem == -1 {
err = errors.Errorf("unknown memory setting: %s", val)
}
case "leaseType":
for _, l := range leases {
if l.String() == val {
v.leaseType = l
return nil
}
}
return errors.Errorf("unknown lease type: %s", val)
case "cloud":
for _, c := range cloudSets {
if c.String() == val {
v.cloud = c
return nil
}
}
return errors.Errorf("unknown cloud: %s", val)
case "acMode":
for _, a := range admissionControlOptions {
if a.String() == val {
v.acMode = a
return nil
}
}
return errors.Errorf("unknown admission control mode: %s", val)
default:
return errors.Errorf("unknown key: %s", key)
}
return err
}

func addMetamorphic(r registry.Registry, p perturbation) {
rng, seed := randutil.NewPseudoRand()
v := p.setupMetamorphic(rng)
Expand Down

0 comments on commit 62303c3

Please sign in to comment.