Skip to content

Commit

Permalink
test(api): add force interrupting flag to perfomance test tool (#484)
Browse files Browse the repository at this point in the history
Added forceInterruption param to config for perfomance test tool Shatal.

Signed-off-by: Valeriy Khorunzhin <[email protected]>
Co-authored-by: Nikita Korolev <[email protected]>

---------

Signed-off-by: Valeriy Khorunzhin <[email protected]>
Co-authored-by: Nikita Korolev <[email protected]>
  • Loading branch information
eofff and universal-itengineer authored Oct 30, 2024
1 parent 9da0675 commit 4caec48
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
4 changes: 4 additions & 0 deletions tests/performance/shatal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ count: 100
# The flag to show debug level logs.
# Corresponds to the DEBUG environment variable.
debug: true
# Flag to enable forced interrupt mode
# If `true` - shatal stops immediately, all affected resources remain in the state at the moment of shatal interruption.
# If `false` - after shatal interruption all affected resources return to their initial state.
forceInterruption: false
drainer:
# The flag to enable node draining.
# Corresponds to the DRAINER_ENABLED environment variable.
Expand Down
1 change: 1 addition & 0 deletions tests/performance/shatal/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace: "default"
interval: "5s"
count: 100
debug: true
forceInterruption: false
drainer:
enabled: true
interval: "10s"
Expand Down
23 changes: 12 additions & 11 deletions tests/performance/shatal/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ import (
)

type Config struct {
Kubeconfig string `yaml:"kubeconfigBase64" env:"KUBECONFIG_BASE64" env-required:""`
ResourcesPrefix string `yaml:"resourcesPrefix" env:"RESOURCES_PREFIX" env-default:"performance"`
Namespace string `yaml:"namespace" env:"NAMESPACE" env-default:"default"`
Interval time.Duration `yaml:"interval" env:"INTERVAL" env-default:"5s"`
Count int `yaml:"count" env:"COUNT"`
Debug bool `yaml:"debug" env:"DEBUG" env-default:"false"`
Drainer DrainerFeature `yaml:"drainer"`
Creator CreatorFeature `yaml:"creator"`
Deleter DeleterFeature `yaml:"deleter"`
Modifier ModifierFeature `yaml:"modifier"`
Nothing NothingFeature `yaml:"nothing"`
Kubeconfig string `yaml:"kubeconfigBase64" env:"KUBECONFIG_BASE64" env-required:""`
ResourcesPrefix string `yaml:"resourcesPrefix" env:"RESOURCES_PREFIX" env-default:"performance"`
Namespace string `yaml:"namespace" env:"NAMESPACE" env-default:"default"`
Interval time.Duration `yaml:"interval" env:"INTERVAL" env-default:"5s"`
Count int `yaml:"count" env:"COUNT"`
Debug bool `yaml:"debug" env:"DEBUG" env-default:"false"`
Drainer DrainerFeature `yaml:"drainer"`
Creator CreatorFeature `yaml:"creator"`
Deleter DeleterFeature `yaml:"deleter"`
Modifier ModifierFeature `yaml:"modifier"`
Nothing NothingFeature `yaml:"nothing"`
ForceInterruption bool `yaml:"forceInterruption"`
}

type DrainerFeature struct {
Expand Down
18 changes: 14 additions & 4 deletions tests/performance/shatal/internal/shatal/shatal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package shatal
import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"sync"

"github.com/deckhouse/virtualization/shatal/internal/api"
Expand All @@ -38,13 +40,16 @@ type Shatal struct {
logger *slog.Logger
exit chan struct{}
wg sync.WaitGroup

forceInterruption bool
}

func New(api *api.Client, conf config.Config, log *slog.Logger) (*Shatal, error) {
shatal := Shatal{
api: api,
logger: log,
exit: make(chan struct{}),
api: api,
logger: log,
exit: make(chan struct{}),
forceInterruption: conf.ForceInterruption,
}

nodes, err := api.GetNodes(context.Background(), conf.Drainer.LabelSelector)
Expand Down Expand Up @@ -131,7 +136,12 @@ func (s *Shatal) Run() {
select {
case <-s.exit:
s.logger.Info("Stop runners")
cancel()
if s.forceInterruption {
fmt.Println("Performing force interruption")
os.Exit(1)
} else {
cancel()
}
case <-ctx.Done():
}
}()
Expand Down

0 comments on commit 4caec48

Please sign in to comment.