Skip to content

Commit 5281b5a

Browse files
authored
Bumped OpenTelemetry Collector to v0.19.0 (#179)
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
1 parent b70d1e7 commit 5281b5a

File tree

6 files changed

+276
-4
lines changed

6 files changed

+276
-4
lines changed

CHANGELOG.md

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

4+
0.19.0 (2021-01-27)
5+
-------------------
6+
* Bumped OpenTelemetry Collector to v0.19.0
7+
8+
49
0.18.1 (2021-01-25)
510
-------------------
611
* Fixed testing image from being used in non-test artifacts (fixes #170) ([#171](https://github.com/open-telemetry/opentelemetry-operator/pull/171), [@gramidt](https://github.com/gramidt))

pkg/collector/upgrade/v0_19_0.go

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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_19_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.19.0, failed to parse configuration: %w", err)
36+
}
37+
38+
processors, ok := cfg["processors"].(map[interface{}]interface{})
39+
if !ok {
40+
// no processors? no need to fail because of that
41+
return otelcol, nil
42+
}
43+
44+
for k, v := range processors {
45+
// from the changelog https://github.com/open-telemetry/opentelemetry-collector/releases/tag/v0.19.0
46+
47+
// Remove deprecated queued_retry processor
48+
if strings.HasPrefix(k.(string), "queued_retry") {
49+
delete(processors, k)
50+
otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.19.0 removed the processor %q", k))
51+
continue
52+
}
53+
54+
// Remove deprecated configs from resource processor: type (set "opencensus.type" key in "attributes.upsert" map instead) and labels (use "attributes.upsert" instead).
55+
if strings.HasPrefix(k.(string), "resource") {
56+
switch processor := v.(type) {
57+
case map[interface{}]interface{}:
58+
// type becomes an attribute.upsert with key opencensus.type
59+
if typ, found := processor["type"]; found {
60+
var attributes []map[string]string
61+
if attrs, found := processor["attributes"]; found {
62+
if attributes, ok = attrs.([]map[string]string); !ok {
63+
return otelcol, fmt.Errorf("couldn't upgrade to v0.19.0, the attributes list for processors %q couldn't be parsed based on the previous value. Type: %t, value: %v", k, attrs, attrs)
64+
}
65+
}
66+
attr := map[string]string{}
67+
attr["key"] = "opencensus.type"
68+
attr["value"] = typ.(string)
69+
attr["action"] = "upsert"
70+
attributes = append(attributes, attr)
71+
72+
processor["attributes"] = attributes
73+
delete(processor, "type")
74+
otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.19.0 migrated the property 'type' for processor %q", k))
75+
}
76+
77+
// handle labels
78+
if labels, found := processor["labels"]; found {
79+
var attributes []map[string]string
80+
if attrs, found := processor["attributes"]; found {
81+
if attributes, ok = attrs.([]map[string]string); !ok {
82+
return otelcol, fmt.Errorf("couldn't upgrade to v0.19.0, the attributes list for processors %q couldn't be parsed based on the previous value. Type: %t, value: %v", k, attrs, attrs)
83+
}
84+
}
85+
86+
if ls, ok := labels.(map[interface{}]interface{}); ok {
87+
for labelK, labelV := range ls {
88+
attr := map[string]string{}
89+
attr["key"] = labelK.(string)
90+
attr["value"] = labelV.(string)
91+
attr["action"] = "upsert"
92+
attributes = append(attributes, attr)
93+
}
94+
}
95+
96+
processor["attributes"] = attributes
97+
delete(processor, "labels")
98+
otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.19.0 migrated the property 'labels' for processor %q", k))
99+
}
100+
101+
processors[k] = processor
102+
case string:
103+
if len(processor) == 0 {
104+
// this processor is using the default configuration
105+
continue
106+
}
107+
default:
108+
return otelcol, fmt.Errorf("couldn't upgrade to v0.19.0, the processor %q is invalid (neither a string nor map)", k)
109+
}
110+
}
111+
}
112+
113+
cfg["processors"] = processors
114+
res, err := yaml.Marshal(cfg)
115+
if err != nil {
116+
return otelcol, fmt.Errorf("couldn't upgrade to v0.19.0, failed to marshall back configuration: %w", err)
117+
}
118+
119+
otelcol.Spec.Config = string(res)
120+
return otelcol, nil
121+
}

pkg/collector/upgrade/v0_19_0_test.go

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
"github.com/stretchr/testify/require"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/types"
25+
26+
"github.com/open-telemetry/opentelemetry-operator/api/v1alpha1"
27+
"github.com/open-telemetry/opentelemetry-operator/internal/version"
28+
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters"
29+
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade"
30+
)
31+
32+
func TestRemoveQueuedRetryProcessor(t *testing.T) {
33+
// prepare
34+
nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"}
35+
existing := v1alpha1.OpenTelemetryCollector{
36+
ObjectMeta: metav1.ObjectMeta{
37+
Name: nsn.Name,
38+
Namespace: nsn.Namespace,
39+
Labels: map[string]string{
40+
"app.kubernetes.io/managed-by": "opentelemetry-operator",
41+
},
42+
},
43+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
44+
Config: `processors:
45+
queued_retry:
46+
otherprocessor:
47+
queued_retry/second:
48+
compression: "on"
49+
reconnection_delay: 15
50+
num_workers: 123`,
51+
},
52+
}
53+
existing.Status.Version = "0.18.0"
54+
55+
// sanity check
56+
require.Contains(t, existing.Spec.Config, "queued_retry")
57+
require.Contains(t, existing.Spec.Config, "queued_retry/second")
58+
require.Contains(t, existing.Spec.Config, "num_workers: 123") // checking one property is sufficient
59+
60+
// test
61+
res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing)
62+
assert.NoError(t, err)
63+
64+
// verify
65+
assert.NotContains(t, res.Spec.Config, "queued_retry:")
66+
assert.Contains(t, res.Spec.Config, "otherprocessor:")
67+
assert.NotContains(t, res.Spec.Config, "queued_retry/second:")
68+
assert.NotContains(t, res.Spec.Config, "num_workers: 123") // checking one property is sufficient
69+
assert.Contains(t, res.Status.Messages[0], "upgrade to v0.19.0 removed the processor")
70+
}
71+
72+
func TestMigrateResourceType(t *testing.T) {
73+
// prepare
74+
nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"}
75+
existing := v1alpha1.OpenTelemetryCollector{
76+
ObjectMeta: metav1.ObjectMeta{
77+
Name: nsn.Name,
78+
Namespace: nsn.Namespace,
79+
Labels: map[string]string{
80+
"app.kubernetes.io/managed-by": "opentelemetry-operator",
81+
},
82+
},
83+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
84+
Config: `processors:
85+
resource:
86+
type: some-type
87+
`,
88+
},
89+
}
90+
existing.Status.Version = "0.18.0"
91+
92+
// test
93+
res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing)
94+
assert.NoError(t, err)
95+
96+
// verify
97+
assert.Equal(t, `processors:
98+
resource:
99+
attributes:
100+
- action: upsert
101+
key: opencensus.type
102+
value: some-type
103+
`, res.Spec.Config)
104+
assert.Contains(t, res.Status.Messages[0], "upgrade to v0.19.0 migrated the property 'type' for processor")
105+
}
106+
107+
func TestMigrateLabels(t *testing.T) {
108+
// prepare
109+
nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"}
110+
existing := v1alpha1.OpenTelemetryCollector{
111+
ObjectMeta: metav1.ObjectMeta{
112+
Name: nsn.Name,
113+
Namespace: nsn.Namespace,
114+
Labels: map[string]string{
115+
"app.kubernetes.io/managed-by": "opentelemetry-operator",
116+
},
117+
},
118+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
119+
Config: `processors:
120+
resource:
121+
labels:
122+
cloud.zone: zone-1
123+
host.name: k8s-node
124+
`,
125+
},
126+
}
127+
existing.Status.Version = "0.18.0"
128+
129+
// test
130+
res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing)
131+
assert.NoError(t, err)
132+
133+
actual, err := adapters.ConfigFromString(res.Spec.Config)
134+
require.NoError(t, err)
135+
actualProcessors := actual["processors"].(map[interface{}]interface{})
136+
actualProcessor := actualProcessors["resource"].(map[interface{}]interface{})
137+
actualAttrs := actualProcessor["attributes"].([]interface{})
138+
139+
// verify
140+
assert.Len(t, actualAttrs, 2)
141+
assert.Nil(t, actualProcessor["labels"])
142+
assert.Contains(t, res.Status.Messages[0], "upgrade to v0.19.0 migrated the property 'labels' for processor")
143+
}

pkg/collector/upgrade/versions.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ var (
4242
Version: *semver.MustParse("0.15.0"),
4343
upgrade: upgrade0_15_0,
4444
},
45+
{
46+
Version: *semver.MustParse("0.19.0"),
47+
upgrade: upgrade0_19_0,
48+
},
4549
}
4650

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

tests/e2e/smoke-simplest/00-install.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ spec:
99
protocols:
1010
grpc:
1111
processors:
12-
queued_retry:
1312
1413
exporters:
1514
logging:
@@ -18,5 +17,5 @@ spec:
1817
pipelines:
1918
traces:
2019
receivers: [jaeger]
21-
processors: [queued_retry]
20+
processors: []
2221
exporters: [logging]

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.18.0
5+
opentelemetry-collector=0.19.0
66

77
# Represents the next release of the OpenTelemetry Operator.
8-
operator=0.18.1
8+
operator=0.19.0

0 commit comments

Comments
 (0)