Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a global job tag to all instances of a given job #483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading