Skip to content

Commit

Permalink
feat: adds wait parameter for a sleep time between download and uploa…
Browse files Browse the repository at this point in the history
…d job
  • Loading branch information
xsteadfastx committed Nov 22, 2021
1 parent 5e75df2 commit 1492c8c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ type config struct {
Colors bool `validate:"required"`
}
Iperf3 struct {
Time int `validate:"required"`
Time int `validate:"required"`
Wait time.Duration `validation:"required,min=1ms"`
}
}

Expand Down Expand Up @@ -268,15 +269,20 @@ func probeHandler(w http.ResponseWriter, r *http.Request) {
logger.Info().Msg("getting download metrics")

if err := download(ctx, t, logger); err != nil {
scrapeErrors.Inc()
logger.Error().Err(err).Msg("could not create download metrics")
http.Error(w, err.Error(), http.StatusInternalServerError)

return
}

logger.Debug().Dur("wait", c.Iperf3.Wait).Msg("waiting")
time.Sleep(c.Iperf3.Wait)

logger.Info().Msg("getting upload metrics")

if err := upload(ctx, t, logger); err != nil {
scrapeErrors.Inc()
logger.Error().Err(err).Msg("could not create upload metrics")
http.Error(w, err.Error(), http.StatusInternalServerError)

Expand Down Expand Up @@ -350,6 +356,13 @@ func init() { //nolint:gochecknoinits,funlen
}

viper.SetDefault("iperf3.time", 5) //nolint:gomnd

// IPerf3.Wait.
rootCmd.PersistentFlags().Duration("wait", time.Second, "time to wait between download and upload runs")

if err := viper.BindPFlag("iperf3.wait", rootCmd.PersistentFlags().Lookup("wait")); err != nil {
log.Fatal().Err(err).Msg("could not bind flag")
}
}

func initConfig() {
Expand Down

0 comments on commit 1492c8c

Please sign in to comment.