From c4e39259bfb4868f73b58c5881b714708f4f92bc Mon Sep 17 00:00:00 2001 From: Omar Abdulaziz Date: Mon, 30 Mar 2026 11:47:38 +0200 Subject: [PATCH] remove vmCheck from health check task and add provision test task with VM deployment logic --- pkg/perf/healthcheck/healthcheck.go | 1 - pkg/perf/provisiontest/provisiontest.go | 87 +++++++++++++++++++ pkg/perf/{healthcheck => provisiontest}/vm.go | 2 +- 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 pkg/perf/provisiontest/provisiontest.go rename pkg/perf/{healthcheck => provisiontest}/vm.go (99%) diff --git a/pkg/perf/healthcheck/healthcheck.go b/pkg/perf/healthcheck/healthcheck.go index 648b61e0..2d038292 100644 --- a/pkg/perf/healthcheck/healthcheck.go +++ b/pkg/perf/healthcheck/healthcheck.go @@ -25,7 +25,6 @@ func NewTask() perf.Task { checks := map[string]checkFunc{ "cache": cacheCheck, "network": networkCheck, - "vm": vmCheck, } return &healthcheckTask{ checks: checks, diff --git a/pkg/perf/provisiontest/provisiontest.go b/pkg/perf/provisiontest/provisiontest.go new file mode 100644 index 00000000..5a58504b --- /dev/null +++ b/pkg/perf/provisiontest/provisiontest.go @@ -0,0 +1,87 @@ +package provisiontest + +import ( + "context" + "fmt" + "time" + + "github.com/cenkalti/backoff" + "github.com/rs/zerolog/log" + "github.com/threefoldtech/zosbase/pkg/perf" + "github.com/threefoldtech/zosbase/pkg/stubs" +) + +const ( + id = "provisiontest" + schedule = "0 0 0 * * *" + description = "daily provision test that deploys a test VM to verify the node can run virtual machines and sets flags for the power daemon" +) + +type provisionTestTask struct{} + +var _ perf.Task = (*provisionTestTask)(nil) + +func NewTask() perf.Task { + return &provisionTestTask{} +} + +func (t *provisionTestTask) ID() string { + return id +} + +func (t *provisionTestTask) Cron() string { + return schedule +} + +func (t *provisionTestTask) Description() string { + return description +} + +func (t *provisionTestTask) Jitter() uint32 { + return 30 * 60 +} + +func (t *provisionTestTask) Run(ctx context.Context) (interface{}, error) { + log.Debug().Msg("starting provision test task") + + cl := perf.MustGetZbusClient(ctx) + zui := stubs.NewZUIStub(cl) + + var result []string + + op := func() error { + errs := vmCheck(ctx) + result = errorsToStrings(errs) + + if err := zui.PushErrors(ctx, "vm", result); err != nil { + return err + } + + if len(errs) != 0 { + return fmt.Errorf("provision test failed: %s", result) + } + + return nil + } + + notify := func(err error, t time.Duration) { + log.Error().Err(err).Dur("retry-in", t).Msg("failed provision test. retrying") + } + + bo := backoff.NewExponentialBackOff() + bo.InitialInterval = 3 * time.Minute + bo.MaxInterval = 30 * time.Second + bo.MaxElapsedTime = 10 * time.Minute + + _ = backoff.RetryNotify(op, bo, notify) + + return result, nil +} + +func errorsToStrings(errs []error) []string { + s := make([]string, 0, len(errs)) + for _, err := range errs { + s = append(s, err.Error()) + } + return s +} diff --git a/pkg/perf/healthcheck/vm.go b/pkg/perf/provisiontest/vm.go similarity index 99% rename from pkg/perf/healthcheck/vm.go rename to pkg/perf/provisiontest/vm.go index 73a5100e..1479efb3 100644 --- a/pkg/perf/healthcheck/vm.go +++ b/pkg/perf/provisiontest/vm.go @@ -1,4 +1,4 @@ -package healthcheck +package provisiontest import ( "context"