Skip to content

Commit

Permalink
feat: add global job tag
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissnell committed Oct 30, 2024
1 parent 80d9808 commit 0c631c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func NewRunnerJob(k6 v1alpha1.TestRunI, index int, token string) (*batchv1.Job,
// Add an job tag: in case metrics are stored, they need to be distinguished by job
command = append(command, "--tag", fmt.Sprintf("job_name=%s", name))

// Add a base job tag, in order to encompass all metrics from all instances of the parent job
command = append(command, "--tag", fmt.Sprintf("base_job_name=%s", k6.NamespacedName().Name))

if v1alpha1.IsTrue(k6, v1alpha1.CloudPLZTestRun) {
command = append(command, "--no-setup", "--no-teardown", "--linger")
}
Expand Down
22 changes: 11 additions & 11 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestNewRunnerJob(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: corev1.PullNever,
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -684,7 +684,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -800,7 +800,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -917,7 +917,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{
{
Name: "ENVOY_ADMIN_API",
Expand Down Expand Up @@ -1046,7 +1046,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--out", "cloud", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "--out", "cloud", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: append(aggregationEnvVars,
corev1.EnvVar{
Name: "K6_CLOUD_PUSH_REF_ID",
Expand Down Expand Up @@ -1172,7 +1172,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: "",
Name: "k6",
Command: []string{"sh", "-c", "if [ ! -f /test/test.js ]; then echo \"LocalFile not found exiting...\"; exit 1; fi;\nk6 run --quiet /test/test.js --address=0.0.0.0:6565 --paused --tag instance_id=1 --tag job_name=test-1"},
Command: []string{"sh", "-c", "if [ ! -f /test/test.js ]; then echo \"LocalFile not found exiting...\"; exit 1; fi;\nk6 run --quiet /test/test.js --address=0.0.0.0:6565 --paused --tag instance_id=1 --tag job_name=test-1 --tag base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -1305,7 +1305,7 @@ func TestNewRunnerJobWithInitContainer(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: corev1.PullNever,
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -1484,7 +1484,7 @@ func TestNewRunnerJobWithVolume(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: corev1.PullNever,
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: expectedVolumeMounts,
Expand Down Expand Up @@ -1654,7 +1654,7 @@ func TestNewRunnerJobPLZTestRun(t *testing.T) {
Image: "ghcr.io/grafana/k6-operator:latest-runner",
ImagePullPolicy: corev1.PullNever,
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--no-setup", "--no-teardown", "--linger"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1", "--tag", "base_job_name=test", "--no-setup", "--no-teardown", "--linger"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down

0 comments on commit 0c631c2

Please sign in to comment.