Skip to content

Commit 4365fec

Browse files
author
Andrea Spacca
committed
minor fixes in benhcmark rally
1 parent 7f14825 commit 4365fec

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

internal/benchrunner/runners/rally/options.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ func WithBenchmarkName(name string) OptionFunc {
6767
}
6868
}
6969

70-
func WithDeferCleanup(d time.Duration) OptionFunc {
71-
return func(opts *Options) {
72-
opts.DeferCleanup = d
73-
}
74-
}
75-
76-
func WithMetricsInterval(d time.Duration) OptionFunc {
77-
return func(opts *Options) {
78-
opts.MetricsInterval = d
79-
}
80-
}
81-
8270
func WithDataReindexing(b bool) OptionFunc {
8371
return func(opts *Options) {
8472
opts.ReindexData = b

internal/benchrunner/runners/rally/runner.go

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616
"os/exec"
1717
"path/filepath"
1818
"strings"
19+
"text/template"
1920
"time"
2021

2122
"github.com/elastic/elastic-package/internal/packages/installer"
2223

2324
"github.com/magefile/mage/sh"
2425

25-
"github.com/elastic/elastic-package/internal/corpusgenerator"
2626
"github.com/elastic/elastic-package/internal/stack"
2727

2828
"github.com/google/uuid"
@@ -50,6 +50,42 @@ const (
5050

5151
// BenchType defining rally benchmark
5252
BenchType benchrunner.Type = "rally"
53+
54+
rallyTrackTemplate = `{% import "rally.helpers" as rally with context %}
55+
{
56+
"version": 2,
57+
"description": "Track for [[.DataStream]]",
58+
"datastream": [
59+
{
60+
"name": "[[.DataStream]]",
61+
"body": "[[.CorpusFilename]]"
62+
}
63+
],
64+
"corpora": [
65+
{
66+
"name": "[[.CorpusFilename]]",
67+
"documents": [
68+
{
69+
"target-data-stream": "[[.DataStream]]",
70+
"source-file": "[[.CorpusFilename]]",
71+
"document-count": [[.CorpusDocsCount]],
72+
"uncompressed-bytes": [[.CorpusSizeInBytes]]
73+
}
74+
]
75+
}
76+
],
77+
"schedule": [
78+
{
79+
"operation": {
80+
"operation-type": "bulk",
81+
"bulk-size": {{bulk_size | default(5000)}},
82+
"ingest-percentage": {{ingest_percentage | default(100)}}
83+
},
84+
"clients": {{bulk_indexing_clients | default(8)}}
85+
}
86+
]
87+
}
88+
`
5389
)
5490

5591
var ErrDryRun = errors.New("dry run: rally benchmark not executed")
@@ -513,7 +549,7 @@ func (r *runner) runGenerator(destDir string) error {
513549
return fmt.Errorf("cannot not create rally track file: %w", err)
514550
}
515551
r.trackFile = trackFile.Name()
516-
rallyTrackContent, err := corpusgenerator.GenerateRallyTrack(r.runtimeDataStream, corpusFile, corpusDocsCount)
552+
rallyTrackContent, err := generateRallyTrack(r.runtimeDataStream, corpusFile, corpusDocsCount)
517553
if err != nil {
518554
return fmt.Errorf("cannot not generate rally track content: %w", err)
519555
}
@@ -871,3 +907,34 @@ func createRunID() string {
871907
func getDataStreamPath(packageRoot, dataStream string) string {
872908
return filepath.Join(packageRoot, "data_stream", dataStream)
873909
}
910+
911+
func generateRallyTrack(dataStream string, corpusFile *os.File, corpusDocsCount uint64) ([]byte, error) {
912+
t := template.New("rallytrack")
913+
914+
parsedTpl, err := t.Delims("[[", "]]").Parse(rallyTrackTemplate)
915+
if err != nil {
916+
return nil, fmt.Errorf("error while parsing rally track template: %w", err)
917+
}
918+
919+
fi, err := corpusFile.Stat()
920+
if err != nil {
921+
return nil, fmt.Errorf("error with stat on rally corpus file: %w", err)
922+
}
923+
924+
corpusSizeInBytes := fi.Size()
925+
926+
buf := new(bytes.Buffer)
927+
templateData := map[string]any{
928+
"DataStream": dataStream,
929+
"CorpusFilename": filepath.Base(corpusFile.Name()),
930+
"CorpusDocsCount": corpusDocsCount,
931+
"CorpusSizeInBytes": corpusSizeInBytes,
932+
}
933+
934+
err = parsedTpl.Execute(buf, templateData)
935+
if err != nil {
936+
return nil, fmt.Errorf("error on parsin on rally track template: %w", err)
937+
}
938+
939+
return buf.Bytes(), nil
940+
}

internal/benchrunner/runners/rally/scenario.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package rally
77
import (
88
"errors"
99
"fmt"
10-
"os"
1110
"path/filepath"
1211

1312
"github.com/elastic/go-ucfg/yaml"
@@ -56,7 +55,7 @@ func readConfig(path, scenario, packageName, packageVersion string) (*scenario,
5655
configPath := filepath.Join(path, devPath, fmt.Sprintf("%s.yml", scenario))
5756
c := defaultConfig()
5857
cfg, err := yaml.NewConfigWithFile(configPath)
59-
if err != nil && !errors.Is(err, os.ErrNotExist) {
58+
if err != nil {
6059
return nil, fmt.Errorf("can't load benchmark configuration: %s: %w", configPath, err)
6160
}
6261

@@ -69,5 +68,9 @@ func readConfig(path, scenario, packageName, packageVersion string) (*scenario,
6968
c.Package = packageName
7069
c.Version = packageVersion
7170

71+
if c.DataStream.Name == "" {
72+
return nil, errors.New("can't read data stream name from benchmark configuration: empty")
73+
}
74+
7275
return c, nil
7376
}

0 commit comments

Comments
 (0)