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

Remove support for cloud output v1 #424

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
49 changes: 12 additions & 37 deletions pkg/cloud/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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],
}
}
Expand Down
43 changes: 4 additions & 39 deletions pkg/cloud/aggregation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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])
}
}
27 changes: 12 additions & 15 deletions pkg/resources/jobs/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
Expand Down Expand Up @@ -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",
},
}

Expand Down
Loading