Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func getSystemCommand() *cobra.Command {
RunE: systemCommandAction,
}

cmd.Flags().StringP(cobraext.BenchPathFlagName, "", "_dev/benchmark/system", cobraext.BenchPathFlagDescription)
cmd.Flags().StringP(cobraext.BenchNameFlagName, "", "", cobraext.BenchNameFlagDescription)
cmd.Flags().BoolP(cobraext.BenchReindexToMetricstoreFlagName, "", false, cobraext.BenchReindexToMetricstoreFlagDescription)
cmd.Flags().DurationP(cobraext.BenchMetricsIntervalFlagName, "", time.Second, cobraext.BenchMetricsIntervalFlagDescription)
Expand All @@ -544,6 +545,11 @@ func systemCommandAction(cmd *cobra.Command, args []string) error {
return cobraext.FlagParsingError(err, cobraext.VariantFlagName)
}

benchPath, err := cmd.Flags().GetString(cobraext.BenchPathFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.BenchPathFlagName)
}

benchName, err := cmd.Flags().GetString(cobraext.BenchNameFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.BenchNameFlagName)
Expand Down Expand Up @@ -595,6 +601,7 @@ func systemCommandAction(cmd *cobra.Command, args []string) error {

withOpts := []system.OptionFunc{
system.WithVariant(variant),
system.WithBenchmarkPath(benchPath),
system.WithBenchmarkName(benchName),
system.WithDeferCleanup(deferCleanup),
system.WithMetricsInterval(metricsInterval),
Expand Down
7 changes: 7 additions & 0 deletions internal/benchrunner/runners/system/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Options struct {
MetricsInterval time.Duration
ReindexData bool
ESMetricsAPI *elasticsearch.API
BenchPath string
BenchName string
PackageRootPath string
Variant string
Expand Down Expand Up @@ -54,6 +55,12 @@ func WithPackageRootPath(path string) OptionFunc {
}
}

func WithBenchmarkPath(path string) OptionFunc {
return func(opts *Options) {
opts.BenchPath = path
}
}

func WithBenchmarkName(name string) OptionFunc {
return func(opts *Options) {
opts.BenchName = name
Expand Down
10 changes: 5 additions & 5 deletions internal/benchrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (
// ServiceLogsAgentDir is folder path where log files produced by the service
// are stored on the Agent container's filesystem.
ServiceLogsAgentDir = "/tmp/service_logs"
devDeployDir = "_dev/benchmark/system/deploy"

// BenchType defining system benchmark
BenchType benchrunner.Type = "system"
Expand Down Expand Up @@ -145,7 +144,7 @@ func (r *runner) setUp() error {
}
r.ctxt.OutputDir = outputDir

scenario, err := readConfig(r.options.PackageRootPath, r.options.BenchName, r.ctxt)
scenario, err := readConfig(r.options.BenchPath, r.options.BenchName, r.ctxt)
if err != nil {
return err
}
Expand Down Expand Up @@ -237,6 +236,7 @@ func (r *runner) run() (report reporters.Reportable, err error) {

// Setup service.
logger.Debug("setting up service...")
devDeployDir := filepath.Clean(filepath.Join(r.options.BenchPath, "deploy"))
opts := servicedeployer.FactoryOptions{
PackageRootPath: r.options.PackageRootPath,
DevDeployDir: devDeployDir,
Expand Down Expand Up @@ -484,7 +484,7 @@ func (r *runner) getGeneratorConfig() (*config.Config, error) {
)

if r.scenario.Corpora.Generator.Config.Path != "" {
configPath := filepath.Clean(filepath.Join(devPath, r.scenario.Corpora.Generator.Config.Path))
configPath := filepath.Clean(filepath.Join(r.options.BenchPath, r.scenario.Corpora.Generator.Config.Path))
configPath = os.ExpandEnv(configPath)
if _, err := os.Stat(configPath); err != nil {
return nil, fmt.Errorf("can't find config file %s: %w", configPath, err)
Expand Down Expand Up @@ -515,7 +515,7 @@ func (r *runner) getGeneratorFields() (fields.Fields, error) {
)

if r.scenario.Corpora.Generator.Fields.Path != "" {
fieldsPath := filepath.Clean(filepath.Join(devPath, r.scenario.Corpora.Generator.Fields.Path))
fieldsPath := filepath.Clean(filepath.Join(r.options.BenchPath, r.scenario.Corpora.Generator.Fields.Path))
fieldsPath = os.ExpandEnv(fieldsPath)
if _, err := os.Stat(fieldsPath); err != nil {
return nil, fmt.Errorf("can't find fields file %s: %w", fieldsPath, err)
Expand Down Expand Up @@ -547,7 +547,7 @@ func (r *runner) getGeneratorTemplate() ([]byte, error) {
)

if r.scenario.Corpora.Generator.Template.Path != "" {
tplPath := filepath.Clean(filepath.Join(devPath, r.scenario.Corpora.Generator.Template.Path))
tplPath := filepath.Clean(filepath.Join(r.options.BenchPath, r.scenario.Corpora.Generator.Template.Path))
tplPath = os.ExpandEnv(tplPath)
if _, err := os.Stat(tplPath); err != nil {
return nil, fmt.Errorf("can't find template file %s: %w", tplPath, err)
Expand Down
7 changes: 2 additions & 5 deletions internal/benchrunner/runners/system/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/elastic/elastic-package/internal/servicedeployer"
)

const devPath = "_dev/benchmark/system"

type scenario struct {
Package string `config:"package" json:"package"`
Description string `config:"description" json:"description"`
Expand Down Expand Up @@ -79,8 +77,8 @@ func defaultConfig() *scenario {
}
}

func readConfig(path, scenario string, ctxt servicedeployer.ServiceContext) (*scenario, error) {
configPath := filepath.Join(path, devPath, fmt.Sprintf("%s.yml", scenario))
func readConfig(benchPath string, scenario string, ctxt servicedeployer.ServiceContext) (*scenario, error) {
configPath := filepath.Clean(filepath.Join(benchPath, fmt.Sprintf("%s.yml", scenario)))
data, err := os.ReadFile(configPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
Expand All @@ -97,7 +95,6 @@ func readConfig(path, scenario string, ctxt servicedeployer.ServiceContext) (*sc
cfg, err := yaml.NewConfig(data, ucfg.PathSep("."))
if err != nil {
if errors.Is(err, os.ErrNotExist) {
configPath = filepath.Join(path, devPath, fmt.Sprintf("%s.yaml", scenario))
cfg, err = yaml.NewConfigWithFile(configPath)
}
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/cobraext/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
AllowSnapshotFlagName = "allow-snapshot"
AllowSnapshotDescription = "allow to export dashboards from a Elastic stack SNAPSHOT version"

BenchPathFlagName = "path"
BenchPathFlagDescription = "path of the benchmark scenario to run"

BenchNameFlagName = "benchmark"
BenchNameFlagDescription = "name of the benchmark scenario to run"

Expand Down