diff --git a/pkg/cloud/aggregation.go b/pkg/cloud/aggregation.go index c335daed..f2f07789 100644 --- a/pkg/cloud/aggregation.go +++ b/pkg/cloud/aggregation.go @@ -8,29 +8,18 @@ import ( corev1 "k8s.io/api/core/v1" ) -var aggregationVarNames = map[int][]string{ - 1: []string{ - // cloud output v1: to be removed in the future - "K6_CLOUD_AGGREGATION_MIN_SAMPLES", - "K6_CLOUD_AGGREGATION_PERIOD", - "K6_CLOUD_AGGREGATION_WAIT_PERIOD", - "K6_CLOUD_METRIC_PUSH_INTERVAL", - "K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE", - "K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY", - }, - 2: []string{ - // cloud output v2 - "K6_CLOUD_API_VERSION", - "K6_CLOUD_AGGREGATION_PERIOD", - "K6_CLOUD_AGGREGATION_WAIT_PERIOD", - "K6_CLOUD_METRIC_PUSH_INTERVAL", - "K6_CLOUD_METRIC_PUSH_CONCURRENCY", - }, +var aggregationVarNames = []string{ + // cloud output v2 + "K6_CLOUD_API_VERSION", + "K6_CLOUD_AGGREGATION_PERIOD", + "K6_CLOUD_AGGREGATION_WAIT_PERIOD", + "K6_CLOUD_METRIC_PUSH_INTERVAL", + "K6_CLOUD_METRIC_PUSH_CONCURRENCY", } func EncodeAggregationConfig(testRun *cloudapi.Config) string { return fmt.Sprintf("%d|%s|%s|%s|%d", - 2, // use v2 for all new test runs + 2, // version of protocol testRun.AggregationPeriod.String(), testRun.AggregationWaitPeriod.String(), testRun.MetricPushInterval.String(), @@ -40,32 +29,18 @@ func EncodeAggregationConfig(testRun *cloudapi.Config) string { func DecodeAggregationConfig(encoded string) ([]corev1.EnvVar, error) { values := strings.Split(encoded, "|") - // in order not to break existing deployments, - // let's support decoding of cloud output v1 for some time - var ( - apiV1VarNames = len(aggregationVarNames[1]) - apiV2VarNames = len(aggregationVarNames[2]) - ) - - if len(values) != apiV1VarNames && len(values) != apiV2VarNames { + if len(values) != len(aggregationVarNames) { return nil, fmt.Errorf( - "Aggregation vars got corrupted: there are %d values instead of %d or %d. Encoded value: `%s`.", + "Aggregation vars got corrupted: there are %d values instead of %d. Encoded value: `%s`.", len(values), - apiV1VarNames, apiV2VarNames, + len(aggregationVarNames), encoded) } - var varNames []string - if len(values) == apiV1VarNames { - varNames = aggregationVarNames[1] - } else { - varNames = aggregationVarNames[2] - } - vars := make([]corev1.EnvVar, len(values)) for i := range values { vars[i] = corev1.EnvVar{ - Name: varNames[i], + Name: aggregationVarNames[i], Value: values[i], } } diff --git a/pkg/cloud/aggregation_test.go b/pkg/cloud/aggregation_test.go index 27504636..b7561ac5 100644 --- a/pkg/cloud/aggregation_test.go +++ b/pkg/cloud/aggregation_test.go @@ -30,38 +30,9 @@ func Test_EncodeAggregationConfig(t *testing.T) { func Test_DecodeAggregationConfig(t *testing.T) { var ( - // For now, we support both versions in decoding. - v1Encoded = "50|3s|8s|6s|10000|10" - v2Encoded = "2|5s|3s|10s|10" + encoded = "2|5s|3s|10s|10" - v1EnvVars = []corev1.EnvVar{ - { - Name: "K6_CLOUD_AGGREGATION_MIN_SAMPLES", - Value: "50", - }, - { - Name: "K6_CLOUD_AGGREGATION_PERIOD", - Value: "3s", - }, - { - Name: "K6_CLOUD_AGGREGATION_WAIT_PERIOD", - Value: "8s", - }, - { - Name: "K6_CLOUD_METRIC_PUSH_INTERVAL", - Value: "6s", - }, - { - Name: "K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE", - Value: "10000", - }, - { - Name: "K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY", - Value: "10", - }, - } - - v2EnvVars = []corev1.EnvVar{ + expected = []corev1.EnvVar{ { Name: "K6_CLOUD_API_VERSION", Value: "2", @@ -85,16 +56,10 @@ func Test_DecodeAggregationConfig(t *testing.T) { } ) - envVars, err := DecodeAggregationConfig(v1Encoded) + envVars, err := DecodeAggregationConfig(encoded) assert.Equal(t, nil, err) - for i, expectedEnvVar := range v1EnvVars { - assert.Equal(t, expectedEnvVar, envVars[i]) - } - - envVars, err = DecodeAggregationConfig(v2Encoded) - assert.Equal(t, nil, err) - for i, expectedEnvVar := range v2EnvVars { + for i, expectedEnvVar := range expected { assert.Equal(t, expectedEnvVar, envVars[i]) } } diff --git a/pkg/resources/jobs/runner_test.go b/pkg/resources/jobs/runner_test.go index 22078cf5..6a7ad1a6 100644 --- a/pkg/resources/jobs/runner_test.go +++ b/pkg/resources/jobs/runner_test.go @@ -17,23 +17,20 @@ import ( // these are default values hard-coded in k6 var aggregationEnvVars = []corev1.EnvVar{ - corev1.EnvVar{ - Name: "K6_CLOUD_AGGREGATION_MIN_SAMPLES", - Value: "50", - }, corev1.EnvVar{ + { + Name: "K6_CLOUD_API_VERSION", + Value: "2", + }, { Name: "K6_CLOUD_AGGREGATION_PERIOD", - Value: "3s", - }, corev1.EnvVar{ + Value: "5s", + }, { Name: "K6_CLOUD_AGGREGATION_WAIT_PERIOD", - Value: "8s", - }, corev1.EnvVar{ + Value: "3s", + }, { Name: "K6_CLOUD_METRIC_PUSH_INTERVAL", - Value: "6s", - }, corev1.EnvVar{ - Name: "K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE", - Value: "10000", - }, corev1.EnvVar{ - Name: "K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY", + Value: "10s", + }, { + Name: "K6_CLOUD_METRIC_PUSH_CONCURRENCY", Value: "10", }, } @@ -1114,7 +1111,7 @@ func TestNewRunnerJobCloud(t *testing.T) { // testrunid has to be set hard-coded here. Status: v1alpha1.TestRunStatus{ TestRunID: "testrunid", - AggregationVars: "50|3s|8s|6s|10000|10", + AggregationVars: "2|5s|3s|10s|10", }, } diff --git a/pkg/types/script.go b/pkg/types/script.go index e8f99bd9..3ccdbc66 100644 --- a/pkg/types/script.go +++ b/pkg/types/script.go @@ -10,7 +10,7 @@ import ( // Internal type created to support Spec.script options type Script struct { Name string // Name of ConfigMap or VolumeClaim or "LocalFile" - ReadOnly bool // VolumeClaim only + ReadOnly bool // VolumeClaim only Filename string Path string Type string // ConfigMap | VolumeClaim | LocalFile