Skip to content

Commit

Permalink
feat: use name instead of index for instance id tag (#135)
Browse files Browse the repository at this point in the history
* feat: use name instead of index for instance id tag

* feat: add tag for job_name instead of changing instance_id

* test: add the new tag to unit tests
  • Loading branch information
spoukke authored Sep 1, 2022
1 parent 25e028e commit 02dfbc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/crd/bases/k6.io_k6s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,6 @@ spec:
- name
type: object
type: array
# ref: https://github.com/kubernetes/kubernetes/blob/7e2c02d4c86d73051b6d4f47298d35a7ffb42b6a/api/openapi-spec/v3/apis__apps__v1_openapi.json#L1681
envFrom:
items:
description: EnvFromSource represents the source of a set of
Expand Down
3 changes: 3 additions & 0 deletions pkg/resources/jobs/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func NewRunnerJob(k6 *v1alpha1.K6, index int, testRunId, token string) (*batchv1
// Add an instance tag: in case metrics are stored, they need to be distinguished by instance
command = append(command, "--tag", fmt.Sprintf("instance_id=%d", index))

// 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))

command = script.UpdateCommand(command)

var (
Expand Down
16 changes: 8 additions & 8 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestNewRunnerJob(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=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"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestNewRunnerJobNoisy(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1"},
Command: []string{"k6", "run", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestNewRunnerJobUnpaused(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--tag", "instance_id=1"},
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--tag", "instance_id=1", "--tag", "job_name=test-1"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -585,7 +585,7 @@ func TestNewRunnerJobArguments(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--cool-thing", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=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"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -679,7 +679,7 @@ func TestNewRunnerJobServiceAccount(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=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"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down Expand Up @@ -774,7 +774,7 @@ func TestNewRunnerJobIstio(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"scuttle", "k6", "run", "--quiet", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=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"},
Env: []corev1.EnvVar{
{
Name: "ENVOY_ADMIN_API",
Expand Down Expand Up @@ -881,7 +881,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
Name: "k6",
Command: []string{"k6", "run", "--quiet", "--out", "cloud", "/test/test.js", "--address=0.0.0.0:6565", "--paused", "--tag", "instance_id=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"},
Env: []corev1.EnvVar{
{
Name: "K6_CLOUD_PUSH_REF_ID",
Expand Down Expand Up @@ -979,7 +979,7 @@ func TestNewRunnerJobLocalFile(t *testing.T) {
Containers: []corev1.Container{{
Image: "ghcr.io/grafana/operator:latest-runner",
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"},
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"},
Env: []corev1.EnvVar{},
Resources: corev1.ResourceRequirements{},
VolumeMounts: script.VolumeMount(),
Expand Down

0 comments on commit 02dfbc9

Please sign in to comment.