in internal/benchrunner/runners/rally/runner.go [867:944]
func (r *runner) runRally(ctx context.Context) ([]rallyStat, error) {
logger.Debug("running rally...")
profileConfig, err := stack.StackInitConfig(r.options.Profile)
if err != nil {
return nil, fmt.Errorf("failed to load config from profile: %w", err)
}
elasticsearchHost, found := os.LookupEnv(stack.ElasticsearchHostEnv)
if !found {
status, err := stack.Status(ctx, stack.Options{Profile: r.options.Profile})
if err != nil {
return nil, fmt.Errorf("failed to check status of stack in current profile: %w", err)
}
if len(status) == 0 {
return nil, stack.ErrUnavailableStack
}
elasticsearchHost = profileConfig.ElasticsearchHostPort
logger.Debugf("Configuring rally with Elasticsearch host from current profile (profile: %s, host: %q)", r.options.Profile.ProfileName, elasticsearchHost)
}
elasticsearchPassword, found := os.LookupEnv(stack.ElasticsearchPasswordEnv)
if !found {
elasticsearchPassword = profileConfig.ElasticsearchPassword
}
elasticsearchUsername, found := os.LookupEnv(stack.ElasticsearchUsernameEnv)
if !found {
elasticsearchUsername = profileConfig.ElasticsearchUsername
}
_, err = exec.LookPath("esrally")
if err != nil {
return nil, errors.New("could not run esrally track in path: esrally not found, please follow instruction at https://esrally.readthedocs.io/en/stable/install.html")
}
cmd := exec.Command(
"esrally",
"race",
"--race-id="+r.svcInfo.Test.RunID,
"--report-format=csv",
fmt.Sprintf(`--report-file=%s`, r.reportFile),
fmt.Sprintf(`--target-hosts={"default":["%s"]}`, elasticsearchHost),
fmt.Sprintf(`--track-path=%s`, r.trackFile),
fmt.Sprintf(`--client-options={"default":{"basic_auth_user":"%s","basic_auth_password":"%s","use_ssl":true,"verify_certs":false}}`, elasticsearchUsername, elasticsearchPassword),
"--pipeline=benchmark-only",
"--kill-running-processes",
)
errOutput := new(bytes.Buffer)
cmd.Stderr = errOutput
logger.Debugf("output command: %s", cmd)
output, err := cmd.Output()
if err != nil {
return nil, fmt.Errorf("could not run esrally track in path: %s (stdout=%q, stderr=%q): %w", r.svcInfo.Logs.Folder.Local, output, errOutput.String(), err)
}
reportCSV, err := os.Open(r.reportFile)
if err != nil {
return nil, fmt.Errorf("could not open esrally report in path: %s: %w", r.svcInfo.Logs.Folder.Local, err)
}
reader := csv.NewReader(reportCSV)
stats := make([]rallyStat, 0)
for {
record, err := reader.Read()
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("could not read esrally report in path: %s (stderr=%q): %w", r.svcInfo.Logs.Folder.Local, errOutput.String(), err)
}
stats = append(stats, rallyStat{Metric: record[0], Task: record[1], Value: record[2], Unit: record[3]})
}
return stats, nil
}