@@ -16,13 +16,13 @@ import (
16
16
"os/exec"
17
17
"path/filepath"
18
18
"strings"
19
+ "text/template"
19
20
"time"
20
21
21
22
"github.com/elastic/elastic-package/internal/packages/installer"
22
23
23
24
"github.com/magefile/mage/sh"
24
25
25
- "github.com/elastic/elastic-package/internal/corpusgenerator"
26
26
"github.com/elastic/elastic-package/internal/stack"
27
27
28
28
"github.com/google/uuid"
@@ -50,6 +50,42 @@ const (
50
50
51
51
// BenchType defining rally benchmark
52
52
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
+ `
53
89
)
54
90
55
91
var ErrDryRun = errors .New ("dry run: rally benchmark not executed" )
@@ -513,7 +549,7 @@ func (r *runner) runGenerator(destDir string) error {
513
549
return fmt .Errorf ("cannot not create rally track file: %w" , err )
514
550
}
515
551
r .trackFile = trackFile .Name ()
516
- rallyTrackContent , err := corpusgenerator . GenerateRallyTrack (r .runtimeDataStream , corpusFile , corpusDocsCount )
552
+ rallyTrackContent , err := generateRallyTrack (r .runtimeDataStream , corpusFile , corpusDocsCount )
517
553
if err != nil {
518
554
return fmt .Errorf ("cannot not generate rally track content: %w" , err )
519
555
}
@@ -871,3 +907,34 @@ func createRunID() string {
871
907
func getDataStreamPath (packageRoot , dataStream string ) string {
872
908
return filepath .Join (packageRoot , "data_stream" , dataStream )
873
909
}
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
+ }
0 commit comments