-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement sub-commands and validate container image
Signed-off-by: Adrien Mannocci <[email protected]>
- Loading branch information
Showing
29 changed files
with
336 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cmd/apmsoak/apmsoak | ||
.vscode | ||
.vscode | ||
.states | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.20.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Base image for build | ||
ARG base_image_version=1.20.7 | ||
FROM golang:${base_image_version} as builder | ||
|
||
# Switch workdir | ||
WORKDIR /opt/apm-perf | ||
|
||
# Copy files | ||
COPY . . | ||
|
||
# Build | ||
RUN \ | ||
go mod download \ | ||
&& make build | ||
|
||
# Base image for build | ||
FROM debian:bookworm | ||
|
||
# Arguments | ||
ARG commit_sha | ||
ARG current_time | ||
ARG image_id | ||
ARG project_url | ||
|
||
# Labels | ||
LABEL \ | ||
org.opencontainers.image.created="${current_time}" \ | ||
org.opencontainers.image.authors="amannocci <[email protected]>" \ | ||
org.opencontainers.image.url="${project_url}" \ | ||
org.opencontainers.image.documentation="${project_url}" \ | ||
org.opencontainers.image.source="${project_url}" \ | ||
org.opencontainers.image.version="${image_id}" \ | ||
org.opencontainers.image.revision="${commit_sha}" \ | ||
org.opencontainers.image.vendor="Elastic" \ | ||
org.opencontainers.image.licenses="Elastic License 2.0" | ||
|
||
# Switch workdir | ||
WORKDIR /opt/apm-perf | ||
|
||
# Copy files | ||
COPY --from=builder /opt/apm-perf/dist/apmsoak /usr/bin/apmsoak | ||
COPY ./internal/loadgen/events ./events | ||
COPY ./cmd/apmsoak/scenarios.yml /opt/apm-perf/scenarios.yml | ||
|
||
CMD [ "/usr/bin/apmsoak" ] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"go.elastic.co/ecszap" | ||
"go.uber.org/zap" | ||
|
||
"github.com/elastic/apm-perf/internal/soaktest" | ||
) | ||
|
||
type RunOptions struct { | ||
Scenario string | ||
ScenariosPath string | ||
ServerURL string | ||
SecretToken string | ||
ApiKeys string | ||
BypassProxy bool | ||
} | ||
|
||
func (opts *RunOptions) toRunnerConfig() (*soaktest.RunnerConfig, error) { | ||
apiKeys := make(map[string]string) | ||
pairs := strings.Split(opts.ApiKeys, ",") | ||
for _, pair := range pairs { | ||
kv := strings.Split(pair, ":") | ||
if len(kv) != 2 { | ||
return nil, errors.New("invalid api keys provided. example: project_id:my_api_key") | ||
} | ||
apiKeys[kv[0]] = kv[1] | ||
} | ||
return &soaktest.RunnerConfig{ | ||
Scenario: opts.Scenario, | ||
ScenariosPath: opts.ScenariosPath, | ||
ServerURL: opts.ServerURL, | ||
SecretToken: opts.SecretToken, | ||
ApiKeys: apiKeys, | ||
BypassProxy: opts.BypassProxy, | ||
}, nil | ||
} | ||
|
||
func NewCmdRun() *cobra.Command { | ||
options := &RunOptions{} | ||
cmd := &cobra.Command{ | ||
Use: "run", | ||
Short: "Run apmsoak", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
encoderConfig := ecszap.NewDefaultEncoderConfig() | ||
core := ecszap.NewCore(encoderConfig, os.Stdout, zap.InfoLevel) | ||
logger := zap.New(core, zap.AddCaller()) | ||
|
||
config, err := options.toRunnerConfig() | ||
if err != nil { | ||
logger.Fatal("Fail to parse flags", zap.Error(err)) | ||
} | ||
|
||
runner, err := soaktest.NewRunner(config, logger) | ||
if err != nil { | ||
logger.Fatal("Fail to initialize runner", zap.Error(err)) | ||
} | ||
|
||
if err := runner.Run(cmd.Context()); err != nil { | ||
if !errors.Is(err, context.Canceled) { | ||
logger.Fatal("runner exited with error", zap.Error(err)) | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().StringVar(&options.ServerURL, "server-url", "", "Server URL (default http://127.0.0.1:8200), if specified <project_id>, it will be replaced with the project_id provided by the config, (example: https://<project_id>.apm.elastic.cloud)") | ||
cmd.Flags().StringVar(&options.Scenario, "scenario", "steady", "Specify which scenario to use. the value should match one of the scenario key defined in given scenarios YAML file") | ||
cmd.Flags().StringVarP(&options.ScenariosPath, "file", "f", "./scenarios.yml", "Path to scenarios file") | ||
cmd.Flags().StringVar(&options.SecretToken, "secret-token", "", "Secret token for APM Server. Managed intake service doesn't support secret token") | ||
cmd.Flags().StringVar(&options.ApiKeys, "api-keys", "", "API keys for managed service. Specify key value pairs as `project_id_1:my_api_key,project_id_2:my_key`") | ||
cmd.Flags().BoolVar(&options.BypassProxy, "bypass-proxy", false, "Detach from proxy dependency and provide projectID via header. Useful when testing locally") | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/elastic/apm-perf/internal/version" | ||
) | ||
|
||
func NewCmdVersion() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Show current version info", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var buf bytes.Buffer | ||
fmt.Fprintf(&buf, "%s %s", version.CommitSha(), version.BuildTime()) | ||
fmt.Fprintf(cmd.OutOrStdout(), | ||
"apmsoak version %s (%s/%s) [%s]\n", | ||
version.Version, runtime.GOOS, runtime.GOARCH, | ||
buf.String(), | ||
) | ||
}, | ||
} | ||
return cmd | ||
} |
Oops, something went wrong.