Skip to content

Commit 5f59b9e

Browse files
Andrea Spaccajsoriano
andauthored
Benchmark rally add flags (#1576)
* dd package-from-registry and use-corpus-at-path flags * add extra info in docs * minor rewording * Update docs/howto/rally_benchmarking.md Co-authored-by: Jaime Soriano Pastor <[email protected]> * Update internal/benchrunner/runners/rally/runner.go Co-authored-by: Jaime Soriano Pastor <[email protected]> * cr fixes * cr fixes * cr fixes * comment on countLine code * refactor getPackageNameAndVersion --------- Co-authored-by: Jaime Soriano Pastor <[email protected]>
1 parent 5eb9eab commit 5f59b9e

File tree

5 files changed

+242
-25
lines changed

5 files changed

+242
-25
lines changed

cmd/benchmark.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ func getRallyCommand() *cobra.Command {
228228
cmd.Flags().String(cobraext.VariantFlagName, "", cobraext.VariantFlagDescription)
229229
cmd.Flags().StringP(cobraext.BenchCorpusRallyTrackOutputDirFlagName, "", "", cobraext.BenchCorpusRallyTrackOutputDirFlagDescription)
230230
cmd.Flags().BoolP(cobraext.BenchCorpusRallyDryRunFlagName, "", false, cobraext.BenchCorpusRallyDryRunFlagDescription)
231+
cmd.Flags().StringP(cobraext.BenchCorpusRallyUseCorpusAtPathFlagName, "", "", cobraext.BenchCorpusRallyUseCorpusAtPathFlagDescription)
232+
cmd.Flags().StringP(cobraext.BenchCorpusRallyPackageFromRegistryFlagName, "", "", cobraext.BenchCorpusRallyPackageFromRegistryFlagDescription)
231233

232234
return cmd
233235
}
@@ -260,12 +262,31 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
260262
return cobraext.FlagParsingError(err, cobraext.BenchCorpusRallyDryRunFlagName)
261263
}
262264

263-
packageRootPath, found, err := packages.FindPackageRoot()
264-
if !found {
265-
return errors.New("package root not found")
265+
corpusAtPath, err := cmd.Flags().GetString(cobraext.BenchCorpusRallyUseCorpusAtPathFlagName)
266+
if err != nil {
267+
return cobraext.FlagParsingError(err, cobraext.BenchCorpusRallyUseCorpusAtPathFlagName)
266268
}
269+
270+
packageFromRegistry, err := cmd.Flags().GetString(cobraext.BenchCorpusRallyPackageFromRegistryFlagName)
267271
if err != nil {
268-
return fmt.Errorf("locating package root failed: %w", err)
272+
return cobraext.FlagParsingError(err, cobraext.BenchCorpusRallyPackageFromRegistryFlagName)
273+
}
274+
275+
packageName, packageVersion, err := getPackageNameAndVersion(packageFromRegistry)
276+
if err != nil {
277+
return fmt.Errorf("getting package name and version failed, expected format: <package>-<version>: %w", err)
278+
}
279+
280+
var packageRootPath string
281+
var found bool
282+
if len(packageName) == 0 {
283+
packageRootPath, found, err = packages.FindPackageRoot()
284+
if !found {
285+
return errors.New("package root not found")
286+
}
287+
if err != nil {
288+
return fmt.Errorf("locating package root failed: %w", err)
289+
}
269290
}
270291

271292
profile, err := cobraext.GetProfileFlag(cmd)
@@ -299,6 +320,8 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
299320
rally.WithProfile(profile),
300321
rally.WithRallyTrackOutputDir(rallyTrackOutputDir),
301322
rally.WithRallyDryRun(rallyDryRun),
323+
rally.WithRallyPackageFromRegistry(packageName, packageVersion),
324+
rally.WithRallyCorpusAtPath(corpusAtPath),
302325
}
303326

304327
esMetricsClient, err := initializeESMetricsClient(cmd.Context())
@@ -345,6 +368,23 @@ func rallyCommandAction(cmd *cobra.Command, args []string) error {
345368
return nil
346369
}
347370

371+
func getPackageNameAndVersion(packageFromRegistry string) (string, string, error) {
372+
packageData := strings.SplitN(packageFromRegistry, "-", 2)
373+
374+
if len(packageData) != 2 {
375+
return "", "", fmt.Errorf("package name and version from registry not valid (%s)", packageFromRegistry)
376+
}
377+
378+
packageName := packageData[0]
379+
packageVersion := packageData[1]
380+
381+
if len(packageName) > 0 && len(packageVersion) == 0 {
382+
return "", "", fmt.Errorf("package name and version from registry not valid (%s)", packageFromRegistry)
383+
}
384+
385+
return packageName, packageVersion, nil
386+
}
387+
348388
func getSystemCommand() *cobra.Command {
349389
cmd := &cobra.Command{
350390
Use: "system",

docs/howto/rally_benchmarking.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,15 @@ esrally --target-hosts='{"defauelt":["%es_cluster_host:es_cluster_port%"]}' --tr
279279

280280
Please refer to [esrally CLI reference](https://esrally.readthedocs.io/en/stable/command_line_reference.html) for more details.
281281

282+
## Replaying an existing corpus
283+
If the `use-corpus-at-path` flag is used, the corpus will not be generated but rather loaded from the file passed as value of the flag.
284+
If the `rally-track-output-dir` flag is used alongside the `use-corpus-at-path` flag, the persisted rally track will reference a copy of the existing corpus saved in the directory passed as value of the `rally-track-output-dir` flag.
285+
286+
## Loading a package from registry
287+
If the `package-from-registry` flag is used, the package installed in Kibana and its assets referenced in the track will be loaded from registry. The format of the flag value is `%packageName%-%packageVersion%`.
288+
You still need to be in the root of the local package when running the command in order to read the benchmark scenario (`benchmark` flag).
289+
290+
## Running benchmark with the same corpus against different versions of a package
291+
If you use both the `use-corpus-at-path` flag and the `package-from-registry` flag multiple times, you can run benchmark with the same corpus against different versions of the same package, just updating the package version in the relevant flag between executions.
292+
If you add the `rally-track-output-dir` flag and the `dry-run` flag, you can persist multiple rally tracks with the same corpus for different package versions, using different values for the `rally-track-output-dir` flag.
293+

internal/benchrunner/runners/rally/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type Options struct {
2626
Profile *profile.Profile
2727
RallyTrackOutputDir string
2828
DryRun bool
29+
PackageName string
30+
PackageVersion string
31+
CorpusAtPath string
2932
}
3033

3134
type ClientOptions struct {
@@ -102,3 +105,16 @@ func WithRallyDryRun(d bool) OptionFunc {
102105
opts.DryRun = d
103106
}
104107
}
108+
109+
func WithRallyPackageFromRegistry(n, v string) OptionFunc {
110+
return func(opts *Options) {
111+
opts.PackageName = n
112+
opts.PackageVersion = v
113+
}
114+
}
115+
116+
func WithRallyCorpusAtPath(c string) OptionFunc {
117+
return func(opts *Options) {
118+
opts.CorpusAtPath = c
119+
}
120+
}

0 commit comments

Comments
 (0)