@@ -58,6 +58,8 @@ type runner struct {
5858 mcollector * collector
5959 corporaFile string
6060
61+ service servicedeployer.DeployedService
62+
6163 // Execution order of following handlers is defined in runner.TearDown() method.
6264 deletePolicyHandler func (context.Context ) error
6365 resetAgentPolicyHandler func (context.Context ) error
@@ -152,7 +154,26 @@ func (r *runner) setUp(ctx context.Context) error {
152154 }
153155 r .svcInfo .OutputDir = outputDir
154156
155- scenario , err := readConfig (r .options .BenchPath , r .options .BenchName , r .svcInfo )
157+ serviceName , err := r .serviceDefinedInConfig ()
158+ if err != nil {
159+ return fmt .Errorf ("failed to determine if service is defined in config: %w" , err )
160+ }
161+
162+ if serviceName != "" {
163+ // Just in the case service deployer is needed (input_service field), setup the service now so all the
164+ // required information is available in r.svcInfo (e.g. hostname, port, etc).
165+ // This info may be needed to render the variables in the configuration.
166+ s , err := r .setupService (ctx , serviceName )
167+ if errors .Is (err , os .ErrNotExist ) {
168+ logger .Debugf ("No service deployer defined for this benchmark" )
169+ } else if err != nil {
170+ return err
171+ }
172+ r .service = s
173+ }
174+
175+ // Read the configuration again to have any possible service-related variable rendered.
176+ scenario , err := readConfig (r .options .BenchPath , r .options .BenchName , & r .svcInfo )
156177 if err != nil {
157178 return err
158179 }
@@ -242,18 +263,22 @@ func (r *runner) setUp(ctx context.Context) error {
242263 return nil
243264}
244265
245- func (r * runner ) run (ctx context.Context ) (report reporters.Reportable , err error ) {
246- var service servicedeployer.DeployedService
247- if r .scenario .Corpora .InputService != nil {
248- s , err := r .setupService (ctx )
249- if errors .Is (err , os .ErrNotExist ) {
250- logger .Debugf ("No service deployer defined for this benchmark" )
251- } else if err != nil {
252- return nil , err
253- }
254- service = s
266+ func (r * runner ) serviceDefinedInConfig () (string , error ) {
267+ // Read of the configuration to know if a service deployer is needed.
268+ // No need to render any template at this point.
269+ scenario , err := readRawConfig (r .options .BenchPath , r .options .BenchName )
270+ if err != nil {
271+ return "" , err
255272 }
256273
274+ if scenario .Corpora .InputService == nil {
275+ return "" , nil
276+ }
277+
278+ return scenario .Corpora .InputService .Name , nil
279+ }
280+
281+ func (r * runner ) run (ctx context.Context ) (report reporters.Reportable , err error ) {
257282 r .startMetricsColletion (ctx )
258283 defer r .mcollector .stop ()
259284
@@ -271,8 +296,8 @@ func (r *runner) run(ctx context.Context) (report reporters.Reportable, err erro
271296 }
272297
273298 // Signal to the service that the agent is ready (policy is assigned).
274- if service != nil && r .scenario .Corpora .InputService != nil && r .scenario .Corpora .InputService .Signal != "" {
275- if err = service .Signal (ctx , r .scenario .Corpora .InputService .Signal ); err != nil {
299+ if r . service != nil && r .scenario .Corpora .InputService != nil && r .scenario .Corpora .InputService .Signal != "" {
300+ if err = r . service .Signal (ctx , r .scenario .Corpora .InputService .Signal ); err != nil {
276301 return nil , fmt .Errorf ("failed to notify benchmark service: %w" , err )
277302 }
278303 }
@@ -297,7 +322,7 @@ func (r *runner) run(ctx context.Context) (report reporters.Reportable, err erro
297322 return createReport (r .options .BenchName , r .corporaFile , r .scenario , msum )
298323}
299324
300- func (r * runner ) setupService (ctx context.Context ) (servicedeployer.DeployedService , error ) {
325+ func (r * runner ) setupService (ctx context.Context , serviceName string ) (servicedeployer.DeployedService , error ) {
301326 stackVersion , err := r .options .KibanaClient .Version ()
302327 if err != nil {
303328 return nil , fmt .Errorf ("cannot request Kibana version: %w" , err )
@@ -320,7 +345,7 @@ func (r *runner) setupService(ctx context.Context) (servicedeployer.DeployedServ
320345 return nil , fmt .Errorf ("could not create service runner: %w" , err )
321346 }
322347
323- r .svcInfo .Name = r . scenario . Corpora . InputService . Name
348+ r .svcInfo .Name = serviceName
324349 service , err := serviceDeployer .SetUp (ctx , r .svcInfo )
325350 if err != nil {
326351 return nil , fmt .Errorf ("could not setup service: %w" , err )
0 commit comments