Skip to content

Commit 60ee6e8

Browse files
authored
[fix]: Add update script for v0.130.0 (#4198)
* Add update script * changelog * fix test * fix lint
1 parent 4ab7a05 commit 60ee6e8

File tree

5 files changed

+283
-1
lines changed

5 files changed

+283
-1
lines changed

.chloggen/130-upgrade.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', '4198', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector upgrade
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Adds an upgrade script for version v0.130.0 of the collector to handle a bug with internal telemetry metric names.
9+
10+
# One or more tracking issues related to the change
11+
issues: [4198]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

pkg/collector/upgrade/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func TestEnvVarUpdates(t *testing.T) {
196196
require.Equal(t, collectorInstance.Status.Version, persisted.Status.Version)
197197

198198
currentV := version.Get()
199-
currentV.OpenTelemetryCollector = "0.122.0"
199+
currentV.OpenTelemetryCollector = "0.130.0"
200200
up := &upgrade.VersionUpgrade{
201201
Log: logger,
202202
Version: currentV,

pkg/collector/upgrade/v0_130_0.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package upgrade
5+
6+
import (
7+
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
8+
)
9+
10+
func upgrade0_130_0(u VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) { //nolint:unparam
11+
12+
tel := otelcol.Spec.Config.Service.GetTelemetry()
13+
14+
if tel == nil || len(tel.Metrics.Readers) == 0 {
15+
return otelcol, nil
16+
}
17+
18+
for i, reader := range tel.Metrics.Readers {
19+
if reader.Pull != nil && reader.Pull.Exporter.Prometheus.WithoutUnits == nil {
20+
t := true
21+
tel.Metrics.Readers[i].Pull.Exporter.Prometheus.WithoutUnits = &t
22+
}
23+
}
24+
25+
var err error
26+
otelcol.Spec.Config.Service.Telemetry, err = tel.ToAnyConfig()
27+
if err != nil {
28+
return otelcol, err
29+
}
30+
31+
return otelcol, nil
32+
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package upgrade
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
13+
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
14+
)
15+
16+
func TestUpgrade0_130_0(t *testing.T) {
17+
tests := []struct {
18+
name string
19+
initialConfig *v1beta1.OpenTelemetryCollector
20+
expectedConfig *v1beta1.OpenTelemetryCollector
21+
}{
22+
{
23+
name: "should set without_units if not set",
24+
initialConfig: &v1beta1.OpenTelemetryCollector{
25+
TypeMeta: metav1.TypeMeta{
26+
Kind: "OpenTelemetryCollector",
27+
APIVersion: "v1beta1",
28+
},
29+
ObjectMeta: metav1.ObjectMeta{
30+
Name: "test-collector",
31+
Namespace: "default",
32+
},
33+
Spec: v1beta1.OpenTelemetryCollectorSpec{
34+
Config: v1beta1.Config{
35+
Service: v1beta1.Service{
36+
Telemetry: &v1beta1.AnyConfig{
37+
Object: map[string]interface{}{
38+
"metrics": map[string]interface{}{
39+
"readers": []interface{}{
40+
map[string]interface{}{
41+
"pull": map[string]interface{}{
42+
"exporter": map[string]interface{}{
43+
"prometheus": map[string]interface{}{
44+
"host": "0.0.0.0",
45+
"port": int32(8888),
46+
},
47+
},
48+
},
49+
},
50+
},
51+
},
52+
},
53+
},
54+
},
55+
},
56+
},
57+
},
58+
expectedConfig: &v1beta1.OpenTelemetryCollector{
59+
TypeMeta: metav1.TypeMeta{
60+
Kind: "OpenTelemetryCollector",
61+
APIVersion: "v1beta1",
62+
},
63+
ObjectMeta: metav1.ObjectMeta{
64+
Name: "test-collector",
65+
Namespace: "default",
66+
},
67+
Spec: v1beta1.OpenTelemetryCollectorSpec{
68+
Config: v1beta1.Config{
69+
Service: v1beta1.Service{
70+
Telemetry: &v1beta1.AnyConfig{
71+
Object: map[string]interface{}{
72+
"metrics": map[string]interface{}{
73+
"readers": []interface{}{
74+
map[string]interface{}{
75+
"pull": map[string]interface{}{
76+
"exporter": map[string]interface{}{
77+
"prometheus": map[string]interface{}{
78+
"host": "0.0.0.0",
79+
"port": int32(8888),
80+
"without_units": true,
81+
},
82+
},
83+
},
84+
},
85+
},
86+
},
87+
},
88+
},
89+
},
90+
},
91+
},
92+
},
93+
},
94+
{
95+
name: "should not set without_units if false",
96+
initialConfig: &v1beta1.OpenTelemetryCollector{
97+
TypeMeta: metav1.TypeMeta{
98+
Kind: "OpenTelemetryCollector",
99+
APIVersion: "v1beta1",
100+
},
101+
ObjectMeta: metav1.ObjectMeta{
102+
Name: "test-collector",
103+
Namespace: "default",
104+
},
105+
Spec: v1beta1.OpenTelemetryCollectorSpec{
106+
Config: v1beta1.Config{
107+
Service: v1beta1.Service{
108+
Telemetry: &v1beta1.AnyConfig{
109+
Object: map[string]interface{}{
110+
"metrics": map[string]interface{}{
111+
"readers": []interface{}{
112+
map[string]interface{}{
113+
"pull": map[string]interface{}{
114+
"exporter": map[string]interface{}{
115+
"prometheus": map[string]interface{}{
116+
"host": "0.0.0.0",
117+
"port": int32(8888),
118+
"without_units": false,
119+
},
120+
},
121+
},
122+
},
123+
},
124+
},
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
131+
expectedConfig: &v1beta1.OpenTelemetryCollector{
132+
TypeMeta: metav1.TypeMeta{
133+
Kind: "OpenTelemetryCollector",
134+
APIVersion: "v1beta1",
135+
},
136+
ObjectMeta: metav1.ObjectMeta{
137+
Name: "test-collector",
138+
Namespace: "default",
139+
},
140+
Spec: v1beta1.OpenTelemetryCollectorSpec{
141+
Config: v1beta1.Config{
142+
Service: v1beta1.Service{
143+
Telemetry: &v1beta1.AnyConfig{
144+
Object: map[string]interface{}{
145+
"metrics": map[string]interface{}{
146+
"readers": []interface{}{
147+
map[string]interface{}{
148+
"pull": map[string]interface{}{
149+
"exporter": map[string]interface{}{
150+
"prometheus": map[string]interface{}{
151+
"host": "0.0.0.0",
152+
"port": int32(8888),
153+
"without_units": false,
154+
},
155+
},
156+
},
157+
},
158+
},
159+
},
160+
},
161+
},
162+
},
163+
},
164+
},
165+
},
166+
},
167+
{
168+
name: "should not set without_units if no prometheus exporter",
169+
initialConfig: &v1beta1.OpenTelemetryCollector{
170+
TypeMeta: metav1.TypeMeta{
171+
Kind: "OpenTelemetryCollector",
172+
APIVersion: "v1beta1",
173+
},
174+
ObjectMeta: metav1.ObjectMeta{
175+
Name: "test-collector",
176+
Namespace: "default",
177+
},
178+
Spec: v1beta1.OpenTelemetryCollectorSpec{
179+
Config: v1beta1.Config{
180+
Service: v1beta1.Service{
181+
Telemetry: &v1beta1.AnyConfig{
182+
Object: map[string]interface{}{
183+
"metrics": map[string]interface{}{
184+
"readers": []interface{}{},
185+
},
186+
},
187+
},
188+
},
189+
},
190+
},
191+
},
192+
expectedConfig: &v1beta1.OpenTelemetryCollector{
193+
TypeMeta: metav1.TypeMeta{
194+
Kind: "OpenTelemetryCollector",
195+
APIVersion: "v1beta1",
196+
},
197+
ObjectMeta: metav1.ObjectMeta{
198+
Name: "test-collector",
199+
Namespace: "default",
200+
},
201+
Spec: v1beta1.OpenTelemetryCollectorSpec{
202+
Config: v1beta1.Config{
203+
Service: v1beta1.Service{
204+
Telemetry: &v1beta1.AnyConfig{
205+
Object: map[string]interface{}{
206+
"metrics": map[string]interface{}{
207+
"readers": []interface{}{},
208+
},
209+
},
210+
},
211+
},
212+
},
213+
},
214+
},
215+
},
216+
}
217+
218+
for _, tt := range tests {
219+
t.Run(tt.name, func(t *testing.T) {
220+
up := VersionUpgrade{
221+
Log: logger,
222+
}
223+
224+
result, err := upgrade0_130_0(up, tt.initialConfig)
225+
require.NoError(t, err)
226+
require.NotNil(t, result)
227+
assert.Equal(t, tt.expectedConfig.Spec.Config.Service.Telemetry, result.Spec.Config.Service.Telemetry)
228+
})
229+
}
230+
}

pkg/collector/upgrade/versions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ var (
103103
Version: *semver.MustParse("0.122.0"),
104104
upgradeV1beta1: upgrade0_122_0,
105105
},
106+
{
107+
Version: *semver.MustParse("0.130.0"),
108+
upgradeV1beta1: upgrade0_130_0,
109+
},
106110
}
107111

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

0 commit comments

Comments
 (0)