Skip to content

Commit

Permalink
Move some output init calls away from the Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Mar 16, 2022
1 parent 85c5169 commit 1455a62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 11 additions & 2 deletions cmd/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ func createOutputs(gs *globalState, test *loadedTest, executionPlan []lib.Execut
params.ConfigArgument = outputArg
params.JSONConfig = test.derivedConfig.Collectors[outputType]

output, err := outputConstructor(params)
out, err := outputConstructor(params)
if err != nil {
return nil, fmt.Errorf("could not create the '%s' output: %w", outputType, err)
}
result = append(result, output)

if thresholdOut, ok := out.(output.WithThresholds); ok {
thresholdOut.SetThresholds(test.derivedConfig.Thresholds)
}

if builtinMetricOut, ok := out.(output.WithBuiltinMetrics); ok {
builtinMetricOut.SetBuiltinMetrics(test.builtInMetrics)
}

result = append(result, out)
}

return result, nil
Expand Down
8 changes: 0 additions & 8 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ func NewEngine(
func (e *Engine) StartOutputs() error {
e.logger.Debugf("Starting %d outputs...", len(e.outputs))
for i, out := range e.outputs {
if thresholdOut, ok := out.(output.WithThresholds); ok {
thresholdOut.SetThresholds(e.thresholds)
}

if stopOut, ok := out.(output.WithTestRunStop); ok {
stopOut.SetTestRunStopCallback(
func(err error) {
Expand All @@ -151,10 +147,6 @@ func (e *Engine) StartOutputs() error {
})
}

if builtinMetricOut, ok := out.(output.WithBuiltinMetrics); ok {
builtinMetricOut.SetBuiltinMetrics(e.builtinMetrics)
}

if err := out.Start(); err != nil {
e.stopOutputs(i)
return err
Expand Down

0 comments on commit 1455a62

Please sign in to comment.