Skip to content

Commit 9ab4888

Browse files
committed
run: Parse query files early
1 parent 2f4156f commit 9ab4888

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

cmd/run/main.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func Run(_ *cobra.Command, args []string) {
5959
}
6060
defaultRunNameBuilder.WriteString(st.Id)
6161
}
62+
} else {
63+
os.Exit(-1)
6264
}
6365
}
6466
if defaultRunNameBuilder != nil {
@@ -68,8 +70,7 @@ func Run(_ *cobra.Command, args []string) {
6870
}
6971
log.Info().Str("run_name", mainStage.States.RunName).Send()
7072

71-
_, _, err := stage.ParseStageGraph(mainStage)
72-
if err != nil {
73+
if _, _, err := stage.ParseStageGraph(mainStage); err != nil {
7374
log.Fatal().Err(err).Msg("failed to parse benchmark stage graph")
7475
}
7576

@@ -103,9 +104,10 @@ func processStagePath(path string) (st *stage.Stage, returnErr error) {
103104
continue
104105
}
105106
fullPath := filepath.Join(path, entry.Name())
106-
newStage, err := processStagePath(fullPath)
107-
if err == nil {
107+
if newStage, err := processStagePath(fullPath); err == nil {
108108
st.MergeWith(newStage)
109+
} else {
110+
return nil, err
109111
}
110112
}
111113
return st, nil

stage/map.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ func ReadStageFromFile(filePath string) (*Stage, error) {
5757
if err = json.Unmarshal(bytes, stage); err != nil {
5858
return nil, fmt.Errorf("failed to parse json %s: %w", filePath, err)
5959
}
60+
for i, queryFile := range stage.QueryFiles {
61+
if !filepath.IsAbs(queryFile) {
62+
queryFile = filepath.Join(stage.BaseDir, queryFile)
63+
stage.QueryFiles[i] = queryFile
64+
}
65+
if _, err = os.Stat(queryFile); err != nil {
66+
return nil, fmt.Errorf("%s links to an invalid query file %s: %w", stage.Id, queryFile, err)
67+
}
68+
}
6069
log.Debug().Str("id", stage.Id).Str("path", filePath).Msg("read stage file")
6170
return stage, nil
6271
}
@@ -80,14 +89,6 @@ func ParseStage(stage *Stage, stages Map) (*Stage, error) {
8089
log.Debug().Msgf("%s already parsed, returned", stage.Id)
8190
return stageFound, nil
8291
}
83-
for _, queryFile := range stage.QueryFiles {
84-
if !filepath.IsAbs(queryFile) {
85-
queryFile = filepath.Join(stage.BaseDir, queryFile)
86-
}
87-
if _, err := os.Stat(queryFile); err != nil {
88-
return nil, fmt.Errorf("%s links to an invalid query file %s: %w", stage.Id, queryFile, err)
89-
}
90-
}
9192
for i, nextStagePath := range stage.NextStagePaths {
9293
if !filepath.IsAbs(nextStagePath) {
9394
nextStagePath = filepath.Join(stage.BaseDir, nextStagePath)

stage/no_influx.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import (
77
"errors"
88
)
99

10-
func NewInfluxRunRecorder(_ string) RunRecorder {
10+
func NewInfluxRunRecorder(cfgPath string) RunRecorder {
11+
if cfgPath == "" {
12+
return nil
13+
}
1114
return &NotSupportedRecorder{}
1215
}
1316

stage/stage.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,15 @@ func (s *Stage) runSequentially(ctx context.Context) (returnErr error) {
271271
}
272272

273273
func (s *Stage) runQueryFile(ctx context.Context, queryFile string, expectedRowCountStartIndex *int, fileAlias *string) error {
274-
queryFileAbsPath := queryFile
275-
if !filepath.IsAbs(queryFileAbsPath) {
276-
queryFileAbsPath = filepath.Join(s.BaseDir, queryFileAbsPath)
274+
file, err := os.Open(queryFile)
275+
if fileAlias == nil {
276+
if relPath, relErr := filepath.Rel(s.BaseDir, queryFile); relErr == nil {
277+
fileAlias = &relPath
278+
} else {
279+
fileAlias = &queryFile
280+
}
277281
}
278-
file, err := os.Open(queryFileAbsPath)
282+
279283
var queries []string
280284
if err == nil {
281285
queries, err = presto.SplitQueries(file)
@@ -292,9 +296,7 @@ func (s *Stage) runQueryFile(ctx context.Context, queryFile string, expectedRowC
292296
}
293297
return err
294298
}
295-
if fileAlias == nil {
296-
fileAlias = &queryFile
297-
}
299+
298300
if expectedRowCountStartIndex != nil {
299301
err = s.runQueries(ctx, queries, fileAlias, *expectedRowCountStartIndex)
300302
*expectedRowCountStartIndex += len(queries)
@@ -345,7 +347,11 @@ func (s *Stage) runRandomly(ctx context.Context) error {
345347
}
346348
} else {
347349
queryFile := s.QueryFiles[idx-len(s.Queries)]
348-
fileAlias := fmt.Sprintf("rand_%d/%s", i, queryFile)
350+
fileAlias := queryFile
351+
if relPath, relErr := filepath.Rel(s.BaseDir, queryFile); relErr == nil {
352+
fileAlias = relPath
353+
}
354+
fileAlias = fmt.Sprintf("rand_%d_%s", i, fileAlias)
349355
if err := s.runQueryFile(ctx, queryFile, nil, &fileAlias); err != nil {
350356
return err
351357
}

0 commit comments

Comments
 (0)