Skip to content

Commit c65647f

Browse files
authored
Share some functions in benchmark runners (#1717)
1 parent 7f4a339 commit c65647f

File tree

5 files changed

+31
-33
lines changed

5 files changed

+31
-33
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package common
6+
7+
import "path/filepath"
8+
9+
func DataStreamPath(packageRoot, dataStream string) string {
10+
return filepath.Join(packageRoot, "data_stream", dataStream)
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License;
3+
// you may not use this file except in compliance with the Elastic License.
4+
5+
package common
6+
7+
import "github.com/google/uuid"
8+
9+
func NewRunID() string {
10+
return uuid.New().String()
11+
}

internal/benchrunner/runners/rally/runner.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
"github.com/elastic/elastic-package/internal/stack"
2929

30-
"github.com/google/uuid"
3130
"gopkg.in/yaml.v3"
3231

3332
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib"
@@ -36,6 +35,7 @@ import (
3635

3736
"github.com/elastic/elastic-package/internal/benchrunner"
3837
"github.com/elastic/elastic-package/internal/benchrunner/reporters"
38+
"github.com/elastic/elastic-package/internal/benchrunner/runners/common"
3939
"github.com/elastic/elastic-package/internal/configuration/locations"
4040
"github.com/elastic/elastic-package/internal/elasticsearch"
4141
"github.com/elastic/elastic-package/internal/logger"
@@ -244,7 +244,7 @@ func (r *runner) setUp() error {
244244
rallyCorpusDir := locationManager.RallyCorpusDir()
245245
r.ctxt.Logs.Folder.Local = rallyCorpusDir
246246
r.ctxt.Logs.Folder.Agent = RallyCorpusAgentDir
247-
r.ctxt.Test.RunID = createRunID()
247+
r.ctxt.Test.RunID = common.NewRunID()
248248

249249
outputDir, err := servicedeployer.CreateOutputDir(locationManager, r.ctxt.Test.RunID)
250250
if err != nil {
@@ -282,7 +282,7 @@ func (r *runner) setUp() error {
282282

283283
dataStreamManifest, err := packages.ReadDataStreamManifest(
284284
filepath.Join(
285-
getDataStreamPath(r.options.PackageRootPath, r.scenario.DataStream.Name),
285+
common.DataStreamPath(r.options.PackageRootPath, r.scenario.DataStream.Name),
286286
packages.DataStreamManifestFile,
287287
),
288288
)
@@ -1188,14 +1188,6 @@ func waitUntilTrue(fn func() (bool, error), timeout time.Duration) (bool, error)
11881188
}
11891189
}
11901190

1191-
func createRunID() string {
1192-
return uuid.New().String()
1193-
}
1194-
1195-
func getDataStreamPath(packageRoot, dataStream string) string {
1196-
return filepath.Join(packageRoot, "data_stream", dataStream)
1197-
}
1198-
11991191
func generateRallyTrack(dataStream, indexTemplateBody, corpusFileName string, corpusDocsCount uint64, isTSDB bool) ([]byte, error) {
12001192
t := template.New("rallytrack")
12011193

internal/benchrunner/runners/stream/runner.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020

2121
"github.com/elastic/elastic-package/internal/packages/installer"
2222

23-
"github.com/google/uuid"
2423
"gopkg.in/yaml.v3"
2524

2625
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib"
@@ -29,6 +28,7 @@ import (
2928

3029
"github.com/elastic/elastic-package/internal/benchrunner"
3130
"github.com/elastic/elastic-package/internal/benchrunner/reporters"
31+
"github.com/elastic/elastic-package/internal/benchrunner/runners/common"
3232
"github.com/elastic/elastic-package/internal/elasticsearch"
3333
"github.com/elastic/elastic-package/internal/logger"
3434
"github.com/elastic/elastic-package/internal/multierror"
@@ -107,7 +107,7 @@ func (r *runner) setUp() error {
107107

108108
r.runtimeDataStreams = make(map[string]string)
109109

110-
r.ctxt.Test.RunID = createRunID()
110+
r.ctxt.Test.RunID = common.NewRunID()
111111

112112
pkgManifest, err := packages.ReadPackageManifestFromPackageRoot(r.options.PackageRootPath)
113113
if err != nil {
@@ -133,7 +133,7 @@ func (r *runner) setUp() error {
133133
var err error
134134
dataStreamManifest, err := packages.ReadDataStreamManifest(
135135
filepath.Join(
136-
getDataStreamPath(r.options.PackageRootPath, scenario.DataStream.Name),
136+
common.DataStreamPath(r.options.PackageRootPath, scenario.DataStream.Name),
137137
packages.DataStreamManifestFile,
138138
),
139139
)
@@ -629,11 +629,3 @@ func waitUntilTrue(fn func() (bool, error), timeout time.Duration) (bool, error)
629629
}
630630
}
631631
}
632-
633-
func createRunID() string {
634-
return uuid.New().String()
635-
}
636-
637-
func getDataStreamPath(packageRoot, dataStream string) string {
638-
return filepath.Join(packageRoot, "data_stream", dataStream)
639-
}

internal/benchrunner/runners/system/runner.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"strings"
1818
"time"
1919

20-
"github.com/google/uuid"
2120
"gopkg.in/yaml.v3"
2221

2322
"github.com/elastic/elastic-integration-corpus-generator-tool/pkg/genlib"
@@ -26,6 +25,7 @@ import (
2625

2726
"github.com/elastic/elastic-package/internal/benchrunner"
2827
"github.com/elastic/elastic-package/internal/benchrunner/reporters"
28+
"github.com/elastic/elastic-package/internal/benchrunner/runners/common"
2929
"github.com/elastic/elastic-package/internal/configuration/locations"
3030
"github.com/elastic/elastic-package/internal/elasticsearch"
3131
"github.com/elastic/elastic-package/internal/kibana"
@@ -136,7 +136,7 @@ func (r *runner) setUp() error {
136136
serviceLogsDir := locationManager.ServiceLogDir()
137137
r.ctxt.Logs.Folder.Local = serviceLogsDir
138138
r.ctxt.Logs.Folder.Agent = ServiceLogsAgentDir
139-
r.ctxt.Test.RunID = createRunID()
139+
r.ctxt.Test.RunID = common.NewRunID()
140140

141141
outputDir, err := servicedeployer.CreateOutputDir(locationManager, r.ctxt.Test.RunID)
142142
if err != nil {
@@ -173,7 +173,7 @@ func (r *runner) setUp() error {
173173
logger.Debug("deleting old data in data stream...")
174174
dataStreamManifest, err := packages.ReadDataStreamManifest(
175175
filepath.Join(
176-
getDataStreamPath(r.options.PackageRootPath, r.scenario.DataStream.Name),
176+
common.DataStreamPath(r.options.PackageRootPath, r.scenario.DataStream.Name),
177177
packages.DataStreamManifestFile,
178178
),
179179
)
@@ -994,11 +994,3 @@ func waitUntilTrue(fn func() (bool, error), timeout time.Duration) (bool, error)
994994
}
995995
}
996996
}
997-
998-
func createRunID() string {
999-
return uuid.New().String()
1000-
}
1001-
1002-
func getDataStreamPath(packageRoot, dataStream string) string {
1003-
return filepath.Join(packageRoot, "data_stream", dataStream)
1004-
}

0 commit comments

Comments
 (0)