Skip to content

Commit

Permalink
Process thresholds only if some were defined
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Jan 27, 2023
1 parent 339bf6b commit 63ae6b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,12 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
stopOutputs(err)
}()

if !testRunState.RuntimeOptions.NoThresholds.Bool {
if !testRunState.RuntimeOptions.NoThresholds.Bool { //nolint:nestif
finalizeThresholds := metricsEngine.StartThresholdCalculations(runAbort)
defer func() {
if finalizeThresholds == nil {
return
}
// This gets called after the Samples channel has been closed and
// the OutputManager has flushed all of the cached samples to
// outputs (including MetricsEngine's ingester). So we are sure
Expand Down
4 changes: 4 additions & 0 deletions cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ func TestSetupTeardownThresholds(t *testing.T) {
assert.Failf(t, "unexpected log message", "level %s, msg '%s'", msg.Level, msg.Message)
}
}
assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Running thresholds on 3 metrics..."))
assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Finalizing thresholds..."))
assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Metrics emission of VUs and VUsMax metrics stopped"))
assert.True(t, testutils.LogContains(logMsgs, logrus.DebugLevel, "Metrics processing finished!"))
}
Expand Down Expand Up @@ -799,6 +801,8 @@ func TestAbortedByUserWithRestAPI(t *testing.T) {
assert.Contains(t, stdout, `level=debug msg="Metrics emission of VUs and VUsMax metrics stopped"`)
assert.Contains(t, stdout, `level=debug msg="Metrics processing finished!"`)
assert.Contains(t, stdout, `level=debug msg="Sending test finished" output=cloud ref=111 run_status=5 tainted=false`)
assert.NotContains(t, stdout, `Running thresholds`)
assert.NotContains(t, stdout, `Finalizing thresholds`)
}

func TestAbortedByScriptSetupErrorWithDependency(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions js/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func TestDataIsolation(t *testing.T) {
defer stopOutputs(nil)

finalizeThresholds := metricsEngine.StartThresholdCalculations(runAbort)
require.Nil(t, finalizeThresholds)

require.Empty(t, runner.defaultGroup.Groups)

Expand All @@ -416,8 +417,6 @@ func TestDataIsolation(t *testing.T) {
close(samples)
require.NoError(t, err)
waitForMetricsFlushed()
breached := finalizeThresholds()
require.Empty(t, breached)
}
require.Contains(t, runner.defaultGroup.Groups, "setup")
require.Contains(t, runner.defaultGroup.Groups, "teardown")
Expand Down
4 changes: 4 additions & 0 deletions metrics/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func (me *MetricsEngine) initSubMetricsAndThresholds() error {
func (me *MetricsEngine) StartThresholdCalculations(abortRun func(error)) (
finalize func() (breached []string),
) {
if len(me.metricsWithThresholds) == 0 {
return nil // no thresholds were defined
}

stop := make(chan struct{})
done := make(chan struct{})

Expand Down

0 comments on commit 63ae6b0

Please sign in to comment.