@@ -57,15 +57,17 @@ type scenarioRunConfig struct {
5757 timeout time.Duration
5858 doNotRegisterSearchAttributes bool
5959 ignoreAlreadyStarted bool
60+ exportHistoriesDir string
61+ exportHistoriesFilter string
6062}
6163
6264func (r * scenarioRunner ) addCLIFlags (fs * pflag.FlagSet ) {
6365 r .scenario .AddCLIFlags (fs )
6466 r .scenarioRunConfig .addCLIFlags (fs )
6567 fs .DurationVar (& r .connectTimeout , "connect-timeout" , 0 , "Duration to try to connect to server before failing" )
66- r .clientOptions .AddCLIFlags ( fs )
67- r .metricsOptions .AddCLIFlags ( fs , "" )
68- r .loggingOptions .AddCLIFlags ( fs )
68+ fs . AddFlagSet ( r .clientOptions .FlagSet () )
69+ fs . AddFlagSet ( r .metricsOptions .FlagSet ( "" ) )
70+ fs . AddFlagSet ( r .loggingOptions .FlagSet () )
6971}
7072
7173func (r * scenarioRunConfig ) addCLIFlags (fs * pflag.FlagSet ) {
@@ -84,6 +86,8 @@ func (r *scenarioRunConfig) addCLIFlags(fs *pflag.FlagSet) {
8486 "If the search attributes are not registed by the scenario they must be registered through some other method" )
8587 fs .BoolVar (& r .ignoreAlreadyStarted , "ignore-already-started" , false ,
8688 "Ignore if a workflow with the same ID already exists. A Scenario may choose to override this behavior." )
89+ fs .StringVar (& r .exportHistoriesDir , "export-histories-dir" , "" , "Export workflow histories to this directory" )
90+ fs .StringVar (& r .exportHistoriesFilter , "export-histories-filter" , "all" , "Filter which workflows are exported by execution status (options: 'failed', 'terminated', 'failed,terminated', 'all'). Default is 'all'" )
8791}
8892
8993func (r * scenarioRunner ) preRun () {
@@ -121,8 +125,8 @@ func (r *scenarioRunner) run(ctx context.Context) error {
121125 scenarioOptions [key ] = value
122126 }
123127
124- metrics := r .metricsOptions .MustCreateMetrics (r .logger )
125- defer metrics .Shutdown (ctx )
128+ metrics := r .metricsOptions .MustCreateMetrics (ctx , r .logger )
129+ defer metrics .Shutdown (ctx , r . logger )
126130 start := time .Now ()
127131 var client client.Client
128132 var err error
@@ -145,9 +149,16 @@ func (r *scenarioRunner) run(ctx context.Context) error {
145149 return fmt .Errorf ("failed to get root directory: %w" , err )
146150 }
147151
152+ // Generate a random execution ID to ensure no two executions with the same RunID collide
153+ executionID , err := generateExecutionID ()
154+ if err != nil {
155+ return fmt .Errorf ("failed to generate execution ID: %w" , err )
156+ }
157+
148158 scenarioInfo := loadgen.ScenarioInfo {
149159 ScenarioName : r .scenario .Scenario ,
150160 RunID : r .scenario .RunID ,
161+ ExecutionID : executionID ,
151162 Logger : r .logger ,
152163 MetricsHandler : metrics .NewHandler (),
153164 Client : client ,
@@ -164,11 +175,19 @@ func (r *scenarioRunner) run(ctx context.Context) error {
164175 ScenarioOptions : scenarioOptions ,
165176 Namespace : r .clientOptions .Namespace ,
166177 RootPath : repoDir ,
178+ ExportOptions : loadgen.ExportOptions {
179+ ExportHistoriesDir : r .exportHistoriesDir ,
180+ ExportHistoriesFilter : r .exportHistoriesFilter ,
181+ },
167182 }
168183 executor := scenario .ExecutorFn ()
169184 err = executor .Run (ctx , scenarioInfo )
170185 if err != nil {
171186 return fmt .Errorf ("failed scenario: %w" , err )
172187 }
188+ err = loadgen .ExportWorkflowHistories (ctx , scenarioInfo )
189+ if err != nil {
190+ scenarioInfo .Logger .Errorf ("Error exporting workflow histories:\n %v" , err )
191+ }
173192 return nil
174193}
0 commit comments