Skip to content

Commit

Permalink
Fix up telemetry settings in generated Jobs. (#6)
Browse files Browse the repository at this point in the history
* Remove environment value from telemetry events, for the generate sub command.
* Add the namespace value to telemetry events, for the generate sub command.
* Tidy up unused values.
* Environment telemetry settings are sent to the Artillery test workers.
  • Loading branch information
ezodude authored May 11, 2022
1 parent 479e640 commit c82a2de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
6 changes: 0 additions & 6 deletions cmd/kubectl-artillery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ const (

// WorkerImage the Artillery image used by workers to run load tests.
WorkerImage = "artilleryio/artillery:latest"

// TestScriptVol the volume used by created LoadTest Pods to load the test script ConfigMap.
TestScriptVol = "test-script"

// TestScriptFilename expected filename used by the test script ConfigMap.
TestScriptFilename = "test-script.yaml"
)

// kubectl-artillery CLI entrypoint
Expand Down
10 changes: 5 additions & 5 deletions commands/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func newCmdGenerate(
Aliases: []string{"gen"},
Short: "Generates a k8s Job packaged with Kustomize to execute a test",
Example: fmt.Sprintf(generatetestExample, cliName),
RunE: makeRunGenTest(workingDir, io),
RunE: makeRunGenTest(workingDir, io, tCfg),
PostRunE: func(cmd *cobra.Command, args []string) error {
testScriptPath, _ := cmd.Flags().GetString("script")
env, _ := cmd.Flags().GetString("env")
ns, _ := cmd.Flags().GetString("namespace")
outPath, _ := cmd.Flags().GetString("out")
count, _ := cmd.Flags().GetInt("count")

logger := artillery.NewIOLogger(io.Out, io.ErrOut)
telemetry.TelemeterGenerateManifests(args[0], testScriptPath, env, outPath, count, tClient, tCfg, logger)
telemetry.TelemeterGenerateManifests(args[0], testScriptPath, ns, outPath, count, tClient, tCfg, logger)
return nil
},
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func newCmdGenerate(
}

// makeRunGenTest creates the RunE function used to generate a test
func makeRunGenTest(workingDir string, io genericclioptions.IOStreams) func(cmd *cobra.Command, args []string) error {
func makeRunGenTest(workingDir string, io genericclioptions.IOStreams, cfg telemetry.Config) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
if err := validateTest(args); err != nil {
return err
Expand Down Expand Up @@ -137,7 +137,7 @@ func makeRunGenTest(workingDir string, io genericclioptions.IOStreams) func(cmd
return err
}

job := artillery.NewTestJob(testName, ns, configMapName, filepath.Base(testScriptPath), count)
job := artillery.NewTestJob(testName, ns, configMapName, filepath.Base(testScriptPath), count, cfg)
kustomization := artillery.NewKustomization(artillery.TestFilename, ns, configMapName, testScriptPath, artillery.LabelPrefix)

msg, err := artillery.Generatables{
Expand Down
6 changes: 5 additions & 1 deletion internal/artillery/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package artillery
import (
"encoding/json"

"github.com/artilleryio/kubectl-artillery/internal/telemetry"
"k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,7 +26,7 @@ type Job struct {
}

// NewTestJob returns a configured Kubernetes Job wrapper for an Artillery test.
func NewTestJob(testName, namespace, configMapName, testScriptFilename string, count int) *Job {
func NewTestJob(testName, namespace, configMapName, testScriptFilename string, count int, cfg telemetry.Config) *Job {
var (
parallelism int32 = 1
completions int32 = 1
Expand Down Expand Up @@ -87,6 +88,9 @@ func NewTestJob(testName, namespace, configMapName, testScriptFilename string, c
},
},
},
// These are telemetry settings passed to to the Artillery image
// as per an end user's environment.
cfg.ToK8sEnvVar()...,
),
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/telemetry/telemeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TelemeterServicesScaffold(

// TelemeterGenerateManifests enqueues a kubectl-artillery generate command event.
func TelemeterGenerateManifests(
name, testScriptPath, env, outPath string,
name, testScriptPath, namespace, outPath string,
count int,
tClient posthog.Client,
tConfig Config,
Expand All @@ -66,7 +66,7 @@ func TelemeterGenerateManifests(
"name": hashEncode(name),
"testScript": hashEncode(testScriptPath),
"count": count,
"environment": hashEncode(env),
"namespace": hashEncode(namespace),
"defaultOutputDir": len(outPath) == 0,
},
},
Expand Down

0 comments on commit c82a2de

Please sign in to comment.