Skip to content

Command line option to pass --run-name to name a test run. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/f1/metrics/labels/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package labels

const (
Test = "test"
Stage = "stage"
Result = "result"
)
18 changes: 10 additions & 8 deletions pkg/f1/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package metrics
import (
"sync"

"github.com/form3tech-oss/f1/pkg/f1/metrics/labels"

"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -37,14 +39,14 @@ func Instance() *Metrics {
Name: "setup",
Help: "Duration of setup functions.",
Objectives: percentileObjectives,
}, []string{"test", "result"}),
}, []string{labels.Test, labels.Result}),
Iteration: prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: "form3",
Subsystem: "loadtest",
Name: "iteration",
Help: "Duration of iteration functions.",
Objectives: percentileObjectives,
}, []string{"test", "stage", "result"}),
}, []string{labels.Test, labels.Stage, labels.Result}),
Progress: prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: "form3",
Subsystem: "loadtest",
Expand All @@ -58,7 +60,7 @@ func Instance() *Metrics {
Name: "teardown",
Help: "Duration of teardown functions.",
Objectives: percentileObjectives,
}, []string{"test", "result"}),
}, []string{labels.Test, labels.Result}),
}
prometheus.MustRegister(
m.Setup,
Expand All @@ -85,14 +87,14 @@ func (metrics *Metrics) Reset() {
metrics.Teardown.Reset()
}

func (metrics *Metrics) Record(metric MetricType, name string, stage string, result string, nanoseconds int64) {
func (metrics *Metrics) Record(metric MetricType, test string, stage string, result string, nanoseconds int64) {
switch metric {
case SetupResult:
metrics.Setup.WithLabelValues(name, result).Observe(float64(nanoseconds))
metrics.Setup.WithLabelValues(test, result).Observe(float64(nanoseconds))
case IterationResult:
metrics.Iteration.WithLabelValues(name, stage, result).Observe(float64(nanoseconds))
metrics.Progress.WithLabelValues(name, stage, result).Observe(float64(nanoseconds))
metrics.Iteration.WithLabelValues(test, stage, result).Observe(float64(nanoseconds))
metrics.Progress.WithLabelValues(test, stage, result).Observe(float64(nanoseconds))
case TeardownResult:
metrics.Teardown.WithLabelValues(name, result).Observe(float64(nanoseconds))
metrics.Teardown.WithLabelValues(test, result).Observe(float64(nanoseconds))
}
}
3 changes: 2 additions & 1 deletion pkg/f1/options/run_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

type RunOptions struct {
Scenario string
RunName string
ScenarioName string
MaxDuration time.Duration
Concurrency int
Env map[string]string
Expand Down
14 changes: 13 additions & 1 deletion pkg/f1/run/run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func Cmd(builders []api.Builder, hookFunc logging.RegisterLogHookFunc) *cobra.Co
triggerCmd.Flags().IntP("concurrency", "c", 100, "--concurrency 2 (allow at most 2 groups of iterations to run concurrently)")
triggerCmd.Flags().Int32P("max-iterations", "i", 0, "--max-iterations 100 (stop after 100 iterations, regardless of remaining duration)")
triggerCmd.Flags().Bool("ignore-dropped", false, "dropped requests will not fail the run")
triggerCmd.Flags().String("run-name", "", "Sets the name of the run that appears in metrics")
triggerCmd.Flags().AddFlagSet(t.Flags)
runCmd.AddCommand(triggerCmd)
}
Expand All @@ -55,6 +56,16 @@ func runCmdExecute(t api.Builder, hookFunc logging.RegisterLogHookFunc) func(cmd
if err != nil {
return errors.New(fmt.Sprintf("Invalid duration value: %s", err))
}

runName, err := cmd.Flags().GetString("run-name")
if err != nil {
return errors.New(fmt.Sprintf("Invalid run name value: %s", err))
}

if runName == "" {
runName = scenarioName
}

concurrency, err := cmd.Flags().GetInt("concurrency")
if err != nil || concurrency < 1 {
return errors.New(fmt.Sprintf("Invalid concurrency value: %s", err))
Expand Down Expand Up @@ -84,7 +95,8 @@ func runCmdExecute(t api.Builder, hookFunc logging.RegisterLogHookFunc) func(cmd
}

run, err := NewRun(options.RunOptions{
Scenario: scenarioName,
RunName: runName,
ScenarioName: scenarioName,
MaxDuration: duration,
Concurrency: concurrency,
Env: loadEnvironment(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/f1/run/run_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *RunTestStage) a_concurrency_of(concurrency int) *RunTestStage {
func (s *RunTestStage) i_execute_the_run_command() *RunTestStage {
run, err := NewRun(
options.RunOptions{
Scenario: s.scenario,
ScenarioName: s.scenario,
MaxDuration: s.duration,
Concurrency: s.concurrency,
MaxIterations: s.maxIterations,
Expand Down Expand Up @@ -244,7 +244,7 @@ func (s *RunTestStage) an_iteration_limit_of(iterations int32) *RunTestStage {
func (s *RunTestStage) the_test_run_is_started() *RunTestStage {
go func() {
run, err := NewRun(options.RunOptions{
Scenario: s.scenario,
ScenarioName: s.scenario,
MaxDuration: s.duration,
Concurrency: s.concurrency,
MaxIterations: s.maxIterations,
Expand Down
12 changes: 6 additions & 6 deletions pkg/f1/run/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewRun(options options.RunOptions, t *api.Trigger) (*Run, error) {
}
prometheusUrl := os.Getenv("PROMETHEUS_PUSH_GATEWAY")
if prometheusUrl != "" {
run.pusher = push.New(prometheusUrl, "f1-"+options.Scenario).Gatherer(prometheus.DefaultGatherer)
run.pusher = push.New(prometheusUrl, "f1").Gatherer(prometheus.DefaultGatherer)
}
if run.Options.RegisterLogHookFunc == nil {
run.Options.RegisterLogHookFunc = logging.NoneRegisterLogHookFunc
Expand Down Expand Up @@ -78,7 +78,7 @@ type Run struct {
var startTemplate = template.Must(template.New("result parse").
Funcs(templateFunctions).
Parse(`{u}{bold}{intensive_blue}F1 Load Tester{-}
Running {yellow}{{.Options.Scenario}}{-} scenario for {{if .Options.MaxIterations}}up to {{.Options.MaxIterations}} iterations or up to {{end}}{{duration .Options.MaxDuration}} at a rate of {{.RateDescription}}.
Running {yellow}{{.Options.ScenarioName}}{-} scenario for {{if .Options.MaxIterations}}up to {{.Options.MaxIterations}} iterations or up to {{end}}{{duration .Options.MaxDuration}} at a rate of {{.RateDescription}}.
`))

func (r *Run) Do() *RunResult {
Expand All @@ -90,7 +90,7 @@ func (r *Run) Do() *RunResult {

metrics.Instance().Reset()
var err error
r.activeScenario, err = testing.NewActiveScenarios(r.Options.Scenario, r.Options.Env, testing.GetScenario(r.Options.Scenario), 0)
r.activeScenario, err = testing.NewActiveScenarios(r.Options.ScenarioName, r.Options.RunName, r.Options.Env, testing.GetScenario(r.Options.ScenarioName), 0)
r.pushMetrics()
fmt.Println(r.result.Setup())

Expand Down Expand Up @@ -120,9 +120,9 @@ func (r *Run) Do() *RunResult {
}

func (r *Run) configureLogging() {
r.Options.RegisterLogHookFunc(r.Options.Scenario)
r.Options.RegisterLogHookFunc(r.Options.ScenarioName)
if !r.Options.Verbose {
r.result.LogFile = redirectLoggingToFile(r.Options.Scenario)
r.result.LogFile = redirectLoggingToFile(r.Options.ScenarioName)
welcomeMessage := renderTemplate(startTemplate, r)
log.Info(welcomeMessage)
fmt.Printf("Saving logs to %s\n\n", r.result.LogFile)
Expand All @@ -140,7 +140,7 @@ func (r *Run) teardown() {
r.fail(err, "teardown failed")
}
} else {
log.Infof("nil teardown function for scenario %s", r.Options.Scenario)
log.Infof("nil teardown function for scenario %s", r.Options.ScenarioName)
}
}

Expand Down
14 changes: 8 additions & 6 deletions pkg/f1/testing/active_scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ type ActiveScenario struct {
Stages []Stage
TeardownFn TeardownFn
env map[string]string
Name string
ScenarioName string
RunName string
id string
autoTeardownTimer *CancellableTimer
autoTeardownTimerMu sync.RWMutex
AutoTeardownAfter time.Duration
m *metrics.Metrics
}

func NewActiveScenarios(name string, env map[string]string, fn MultiStageSetupFn, autoTeardownIdleDuration time.Duration) (*ActiveScenario, error) {
func NewActiveScenarios(scenarioName string, runName string, env map[string]string, fn MultiStageSetupFn, autoTeardownIdleDuration time.Duration) (*ActiveScenario, error) {

s := &ActiveScenario{
Name: name,
ScenarioName: scenarioName,
RunName: runName,
id: uuid.New().String(),
env: env,
AutoTeardownAfter: autoTeardownIdleDuration,
Expand Down Expand Up @@ -68,7 +70,7 @@ func (s *ActiveScenario) SetAutoTeardown(timer *CancellableTimer) {
}

func (s *ActiveScenario) Run(metric metrics.MetricType, stage, vu, iter string, f func(t *T)) error {
t := NewT(s.env, vu, iter, s.Name)
t := NewT(s.env, vu, iter, s.ScenarioName)
start := time.Now()
done := make(chan struct{})
go func() {
Expand All @@ -80,7 +82,7 @@ func (s *ActiveScenario) Run(metric metrics.MetricType, stage, vu, iter string,
}
// wait for completion
<-done
s.m.Record(metric, s.Name, stage, metrics.Result(t.HasFailed()), time.Since(start).Nanoseconds())
s.m.Record(metric, s.RunName, stage, metrics.Result(t.HasFailed()), time.Since(start).Nanoseconds())
if t.HasFailed() {
return errors.New("failed")
}
Expand Down Expand Up @@ -114,5 +116,5 @@ func (s *ActiveScenario) autoTeardown() {
}

func (s *ActiveScenario) RecordDroppedIteration() {
s.m.Record(metrics.IterationResult, s.Name, "single", "dropped", 0)
s.m.Record(metrics.IterationResult, s.RunName, "single", "dropped", 0)
}