From 207ef83e62b7ac097b6f024e9ca5a8ff56d93ba0 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Tue, 8 Mar 2022 15:05:18 +0200 Subject: [PATCH] Move some output init calls away from the Engine --- cmd/outputs.go | 13 +++++++++++-- core/engine.go | 8 -------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/outputs.go b/cmd/outputs.go index 565a193e704..08893380f4f 100644 --- a/cmd/outputs.go +++ b/cmd/outputs.go @@ -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 diff --git a/core/engine.go b/core/engine.go index 599421e187c..805f5527ce7 100644 --- a/core/engine.go +++ b/core/engine.go @@ -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) { @@ -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