Skip to content

Commit f0b961c

Browse files
committed
Improved organization of pbench output directory to navigate easier for streams runs
1 parent 8fa7a6f commit f0b961c

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

stage/run_recorder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ func (f *FileBasedRunRecorder) RecordQuery(_ context.Context, _ *Stage, result *
4242
}
4343

4444
func (f *FileBasedRunRecorder) RecordRun(_ context.Context, s *Stage, _ []*QueryResult) {
45-
_ = os.WriteFile(filepath.Join(s.States.OutputPath, s.Id+"_summary.csv"), []byte(f.summaryBuilder.String()), 0644)
45+
_ = os.WriteFile(filepath.Join(s.States.OutputPath, s.States.RunName+"_summary.csv"), []byte(f.summaryBuilder.String()), 0644)
4646
}

stage/stage.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
type Stage struct {
3030
// Id is used to uniquely identify a stage. It is usually the file name without its directory path and extension.
3131
Id string `json:"-"`
32+
// ParentStageId is used to keep track of the parent stage of this child stage.
33+
ParentStageId string `json:"-"`
3234
// The values in Catalog, Schema, and SessionParams are inherited by the descendant stages. Please note that if
3335
// they have new values assigned in a stage, those values are NOT applied tn the Presto client until a stage
3436
// creates its own client by setting StartOnNewClient = true.
@@ -233,6 +235,7 @@ func (s *Stage) run(ctx context.Context) (returnErr error) {
233235
s.setDefaults()
234236
s.prepareClient()
235237
s.propagateStates()
238+
s.createNextStagesOutputDirectories()
236239
preStageErr := s.runShellScripts(ctx, s.PreStageShellScripts)
237240
if preStageErr != nil {
238241
return fmt.Errorf("pre-stage script execution failed: %w", preStageErr)
@@ -524,7 +527,7 @@ func (s *Stage) runQuery(ctx context.Context, query *Query) (result *QueryResult
524527
)
525528
if *s.SaveOutput {
526529
queryOutputFile, err = os.OpenFile(
527-
filepath.Join(s.States.OutputPath, querySourceStr)+".output",
530+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".output",
528531
utils.OpenNewFileFlags, 0644)
529532
if err != nil {
530533
return result, err

stage/stage_utils.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (s *Stage) saveQueryJsonFile(result *QueryResult) {
290290
querySourceStr := s.querySourceString(result)
291291
{
292292
queryJsonFile, err := os.OpenFile(
293-
filepath.Join(s.States.OutputPath, querySourceStr)+".json",
293+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".json",
294294
utils.OpenNewFileFlags, 0644)
295295
checkErr(err)
296296
if err == nil {
@@ -302,7 +302,7 @@ func (s *Stage) saveQueryJsonFile(result *QueryResult) {
302302
}
303303
if result.QueryError != nil {
304304
queryErrorFile, err := os.OpenFile(
305-
filepath.Join(s.States.OutputPath, querySourceStr)+".error.json",
305+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".error.json",
306306
utils.OpenNewFileFlags, 0644)
307307
checkErr(err)
308308
if err == nil {
@@ -332,7 +332,7 @@ func (s *Stage) saveColumnMetadataFile(qr *presto.QueryResults, result *QueryRes
332332
}
333333
}()
334334
columnMetadataFile, ioErr := os.OpenFile(
335-
filepath.Join(s.States.OutputPath, querySourceStr)+".cols.json",
335+
filepath.Join(s.States.OutputPath, s.ParentStageId, s.Id, querySourceStr)+".cols.json",
336336
utils.OpenNewFileFlags, 0644)
337337
if ioErr != nil {
338338
return ioErr
@@ -372,3 +372,12 @@ func (s *Stage) querySourceString(result *QueryResult) (sourceStr string) {
372372
}
373373
return
374374
}
375+
376+
func (s *Stage) createNextStagesOutputDirectories() {
377+
parentStageId := s.Id
378+
for _, nextStage := range s.NextStages {
379+
nextStage.ParentStageId = parentStageId
380+
stageOutputPath := filepath.Join(s.States.OutputPath, s.Id, nextStage.Id)
381+
utils.PrepareOutputDirectory(stageOutputPath)
382+
}
383+
}

0 commit comments

Comments
 (0)