Skip to content

Commit

Permalink
Warn on shorthand options overriding scenarios
Browse files Browse the repository at this point in the history
This is currently implemented only for scenarios as that is the case
that is most confusing. Implementing this for duration overriding stages
(for example) is possible, but it seems to not be nearly hit enough.

Unfortunately due to too many of things of #883 and the way shorthand
options are handled in particular, the code can't be in any Apply
function with enough information to have a nice message.

Fixes #2529
  • Loading branch information
mstoykov committed Jan 14, 2025
1 parent 75487a1 commit 284d801
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,15 @@ func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib

conf = cliConf.Apply(fileConf)

warnOnShortHandOverride(conf.Options, runnerOpts, "script", gs.Logger)
conf = conf.Apply(Config{Options: runnerOpts})

conf = conf.Apply(envConf).Apply(cliConf)
warnOnShortHandOverride(conf.Options, envConf.Options, "env", gs.Logger)
conf = conf.Apply(envConf)

warnOnShortHandOverride(conf.Options, cliConf.Options, "cli", gs.Logger)
conf = conf.Apply(cliConf)

conf = applyDefault(conf)

// TODO(imiric): Move this validation where it makes sense in the configuration
Expand All @@ -215,6 +221,15 @@ func getConsolidatedConfig(gs *state.GlobalState, cliConf Config, runnerOpts lib
return conf, nil
}

func warnOnShortHandOverride(a, b lib.Options, bName string, logger logrus.FieldLogger) {
if a.Scenarios != nil &&
(b.Duration.Valid || b.Iterations.Valid || b.Stages != nil || b.Scenarios != nil) {
logger.Warnf(
"%q level configuration overrode scenarios configuration entirely",
bName)
}
}

// applyDefault applies the default options value if it is not specified.
// This happens with types which are not supported by "gopkg.in/guregu/null.v3".
//
Expand Down
4 changes: 3 additions & 1 deletion cmd/config_consolidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ func getConfigConsolidationTestCases() []configConsolidationTestCase {
env: []string{"K6_ITERATIONS=25"},
cli: []string{"--vus", "12"},
},
exp{},
exp{
logWarning: true,
},
verifySharedIters(I(12), I(25)),
},
{
Expand Down

0 comments on commit 284d801

Please sign in to comment.