Skip to content

Commit 41e5738

Browse files
Update to collector v0.24.0 (#251)
Fixes #238
1 parent 720400e commit 41e5738

File tree

5 files changed

+152
-2
lines changed

5 files changed

+152
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changes by Version
22
==================
33

4+
0.24.0 (2021-04-20)
5+
-------------------
6+
* Bumped OpenTelemetry Collector to v0.24.0
7+
48
0.23.0 (2021-04-04)
59
-------------------
610
* Bumped OpenTelemetry Collector to v0.23.0

pkg/collector/upgrade/v0_24_0.go

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package upgrade
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"gopkg.in/yaml.v2"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
23+
24+
"github.com/open-telemetry/opentelemetry-operator/api/v1alpha1"
25+
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters"
26+
)
27+
28+
func upgrade0_24_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) {
29+
if len(otelcol.Spec.Config) == 0 {
30+
return otelcol, nil
31+
}
32+
33+
cfg, err := adapters.ConfigFromString(otelcol.Spec.Config)
34+
if err != nil {
35+
return otelcol, fmt.Errorf("couldn't upgrade to v0.24.0, failed to parse configuration: %w", err)
36+
}
37+
38+
extensions, ok := cfg["extensions"].(map[interface{}]interface{})
39+
if !ok {
40+
// We do not need an upgrade if there are no extensions.
41+
return otelcol, nil
42+
}
43+
44+
for k, v := range extensions {
45+
if strings.HasPrefix(k.(string), "health_check") {
46+
switch extension := v.(type) {
47+
case map[interface{}]interface{}:
48+
if port, ok := extension["port"]; ok {
49+
delete(extension, "port")
50+
extension["endpoint"] = fmt.Sprintf("0.0.0.0:%d", port)
51+
otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.24.0 migrated the property 'port' to 'endpoint' for extension %q", k))
52+
}
53+
case string:
54+
if len(extension) == 0 {
55+
// This extension is using the default configuration.
56+
continue
57+
}
58+
case nil:
59+
// This extension is using the default configuration.
60+
continue
61+
default:
62+
return otelcol, fmt.Errorf("couldn't upgrade to v0.24.0, the extension %q is invalid (expected string or map but was %t)", k, v)
63+
}
64+
}
65+
}
66+
67+
res, err := yaml.Marshal(cfg)
68+
if err != nil {
69+
return otelcol, fmt.Errorf("couldn't upgrade to v0.24.0, failed to marshall back configuration: %w", err)
70+
}
71+
72+
otelcol.Spec.Config = string(res)
73+
return otelcol, nil
74+
}

pkg/collector/upgrade/v0_24_0_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package upgrade_test
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/types"
24+
25+
"github.com/open-telemetry/opentelemetry-operator/api/v1alpha1"
26+
"github.com/open-telemetry/opentelemetry-operator/internal/version"
27+
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade"
28+
)
29+
30+
func TestHealthCheckEndpointMigration(t *testing.T) {
31+
// prepare
32+
nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"}
33+
existing := v1alpha1.OpenTelemetryCollector{
34+
ObjectMeta: metav1.ObjectMeta{
35+
Name: nsn.Name,
36+
Namespace: nsn.Namespace,
37+
Labels: map[string]string{
38+
"app.kubernetes.io/managed-by": "opentelemetry-operator",
39+
},
40+
},
41+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
42+
Config: `extensions:
43+
health_check:
44+
health_check/1: ""
45+
health_check/2:
46+
endpoint: "localhost:13133"
47+
health_check/3:
48+
port: 13133
49+
`,
50+
},
51+
}
52+
existing.Status.Version = "0.23.0"
53+
54+
// test
55+
res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing)
56+
assert.NoError(t, err)
57+
58+
// verify
59+
assert.Equal(t, `extensions:
60+
health_check: null
61+
health_check/1: ""
62+
health_check/2:
63+
endpoint: localhost:13133
64+
health_check/3:
65+
endpoint: 0.0.0.0:13133
66+
`, res.Spec.Config)
67+
assert.Equal(t, "upgrade to v0.24.0 migrated the property 'port' to 'endpoint' for extension \"health_check/3\"", res.Status.Messages[0])
68+
}

pkg/collector/upgrade/versions.go

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var (
4646
Version: *semver.MustParse("0.19.0"),
4747
upgrade: upgrade0_19_0,
4848
},
49+
{
50+
Version: *semver.MustParse("0.24.0"),
51+
upgrade: upgrade0_24_0,
52+
},
4953
}
5054

5155
// Latest represents the latest version that we need to upgrade. This is not necessarily the latest known version.

versions.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# by default with the OpenTelemetry Operator. This would usually be the latest
33
# stable OpenTelemetry version. When you update this file, make sure to update the
44
# the docs as well.
5-
opentelemetry-collector=0.23.0
5+
opentelemetry-collector=0.24.0
66

77
# Represents the next release of the OpenTelemetry Operator.
8-
operator=0.23.0
8+
operator=0.24.0

0 commit comments

Comments
 (0)