Skip to content

Commit 0f3957c

Browse files
committed
cloud: remove decoding for cloud output v1
1 parent d9490de commit 0f3957c

File tree

3 files changed

+28
-91
lines changed

3 files changed

+28
-91
lines changed

pkg/cloud/aggregation.go

+12-37
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,18 @@ import (
88
corev1 "k8s.io/api/core/v1"
99
)
1010

11-
var aggregationVarNames = map[int][]string{
12-
1: []string{
13-
// cloud output v1: to be removed in the future
14-
"K6_CLOUD_AGGREGATION_MIN_SAMPLES",
15-
"K6_CLOUD_AGGREGATION_PERIOD",
16-
"K6_CLOUD_AGGREGATION_WAIT_PERIOD",
17-
"K6_CLOUD_METRIC_PUSH_INTERVAL",
18-
"K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE",
19-
"K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY",
20-
},
21-
2: []string{
22-
// cloud output v2
23-
"K6_CLOUD_API_VERSION",
24-
"K6_CLOUD_AGGREGATION_PERIOD",
25-
"K6_CLOUD_AGGREGATION_WAIT_PERIOD",
26-
"K6_CLOUD_METRIC_PUSH_INTERVAL",
27-
"K6_CLOUD_METRIC_PUSH_CONCURRENCY",
28-
},
11+
var aggregationVarNames = []string{
12+
// cloud output v2
13+
"K6_CLOUD_API_VERSION",
14+
"K6_CLOUD_AGGREGATION_PERIOD",
15+
"K6_CLOUD_AGGREGATION_WAIT_PERIOD",
16+
"K6_CLOUD_METRIC_PUSH_INTERVAL",
17+
"K6_CLOUD_METRIC_PUSH_CONCURRENCY",
2918
}
3019

3120
func EncodeAggregationConfig(testRun *cloudapi.Config) string {
3221
return fmt.Sprintf("%d|%s|%s|%s|%d",
33-
2, // use v2 for all new test runs
22+
2, // version of protocol
3423
testRun.AggregationPeriod.String(),
3524
testRun.AggregationWaitPeriod.String(),
3625
testRun.MetricPushInterval.String(),
@@ -40,32 +29,18 @@ func EncodeAggregationConfig(testRun *cloudapi.Config) string {
4029
func DecodeAggregationConfig(encoded string) ([]corev1.EnvVar, error) {
4130
values := strings.Split(encoded, "|")
4231

43-
// in order not to break existing deployments,
44-
// let's support decoding of cloud output v1 for some time
45-
var (
46-
apiV1VarNames = len(aggregationVarNames[1])
47-
apiV2VarNames = len(aggregationVarNames[2])
48-
)
49-
50-
if len(values) != apiV1VarNames && len(values) != apiV2VarNames {
32+
if len(values) != len(aggregationVarNames) {
5133
return nil, fmt.Errorf(
52-
"Aggregation vars got corrupted: there are %d values instead of %d or %d. Encoded value: `%s`.",
34+
"Aggregation vars got corrupted: there are %d values instead of %d. Encoded value: `%s`.",
5335
len(values),
54-
apiV1VarNames, apiV2VarNames,
36+
len(aggregationVarNames),
5537
encoded)
5638
}
5739

58-
var varNames []string
59-
if len(values) == apiV1VarNames {
60-
varNames = aggregationVarNames[1]
61-
} else {
62-
varNames = aggregationVarNames[2]
63-
}
64-
6540
vars := make([]corev1.EnvVar, len(values))
6641
for i := range values {
6742
vars[i] = corev1.EnvVar{
68-
Name: varNames[i],
43+
Name: aggregationVarNames[i],
6944
Value: values[i],
7045
}
7146
}

pkg/cloud/aggregation_test.go

+4-39
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,9 @@ func Test_EncodeAggregationConfig(t *testing.T) {
3030

3131
func Test_DecodeAggregationConfig(t *testing.T) {
3232
var (
33-
// For now, we support both versions in decoding.
34-
v1Encoded = "50|3s|8s|6s|10000|10"
35-
v2Encoded = "2|5s|3s|10s|10"
33+
encoded = "2|5s|3s|10s|10"
3634

37-
v1EnvVars = []corev1.EnvVar{
38-
{
39-
Name: "K6_CLOUD_AGGREGATION_MIN_SAMPLES",
40-
Value: "50",
41-
},
42-
{
43-
Name: "K6_CLOUD_AGGREGATION_PERIOD",
44-
Value: "3s",
45-
},
46-
{
47-
Name: "K6_CLOUD_AGGREGATION_WAIT_PERIOD",
48-
Value: "8s",
49-
},
50-
{
51-
Name: "K6_CLOUD_METRIC_PUSH_INTERVAL",
52-
Value: "6s",
53-
},
54-
{
55-
Name: "K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE",
56-
Value: "10000",
57-
},
58-
{
59-
Name: "K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY",
60-
Value: "10",
61-
},
62-
}
63-
64-
v2EnvVars = []corev1.EnvVar{
35+
expected = []corev1.EnvVar{
6536
{
6637
Name: "K6_CLOUD_API_VERSION",
6738
Value: "2",
@@ -85,16 +56,10 @@ func Test_DecodeAggregationConfig(t *testing.T) {
8556
}
8657
)
8758

88-
envVars, err := DecodeAggregationConfig(v1Encoded)
59+
envVars, err := DecodeAggregationConfig(encoded)
8960
assert.Equal(t, nil, err)
9061

91-
for i, expectedEnvVar := range v1EnvVars {
92-
assert.Equal(t, expectedEnvVar, envVars[i])
93-
}
94-
95-
envVars, err = DecodeAggregationConfig(v2Encoded)
96-
assert.Equal(t, nil, err)
97-
for i, expectedEnvVar := range v2EnvVars {
62+
for i, expectedEnvVar := range expected {
9863
assert.Equal(t, expectedEnvVar, envVars[i])
9964
}
10065
}

pkg/resources/jobs/runner_test.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,20 @@ import (
1717

1818
// these are default values hard-coded in k6
1919
var aggregationEnvVars = []corev1.EnvVar{
20-
corev1.EnvVar{
21-
Name: "K6_CLOUD_AGGREGATION_MIN_SAMPLES",
22-
Value: "50",
23-
}, corev1.EnvVar{
20+
{
21+
Name: "K6_CLOUD_API_VERSION",
22+
Value: "2",
23+
}, {
2424
Name: "K6_CLOUD_AGGREGATION_PERIOD",
25-
Value: "3s",
26-
}, corev1.EnvVar{
25+
Value: "5s",
26+
}, {
2727
Name: "K6_CLOUD_AGGREGATION_WAIT_PERIOD",
28-
Value: "8s",
29-
}, corev1.EnvVar{
28+
Value: "3s",
29+
}, {
3030
Name: "K6_CLOUD_METRIC_PUSH_INTERVAL",
31-
Value: "6s",
32-
}, corev1.EnvVar{
33-
Name: "K6_CLOUD_MAX_METRIC_SAMPLES_PER_PACKAGE",
34-
Value: "10000",
35-
}, corev1.EnvVar{
36-
Name: "K6_CLOUD_MAX_METRIC_PUSH_CONCURRENCY",
31+
Value: "10s",
32+
}, {
33+
Name: "K6_CLOUD_METRIC_PUSH_CONCURRENCY",
3734
Value: "10",
3835
},
3936
}
@@ -1114,7 +1111,7 @@ func TestNewRunnerJobCloud(t *testing.T) {
11141111
// testrunid has to be set hard-coded here.
11151112
Status: v1alpha1.TestRunStatus{
11161113
TestRunID: "testrunid",
1117-
AggregationVars: "50|3s|8s|6s|10000|10",
1114+
AggregationVars: "2|5s|3s|10s|10",
11181115
},
11191116
}
11201117

0 commit comments

Comments
 (0)