From 5220d862e9e69c804cb71f59110efbe05cce0fe1 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Fri, 28 Jan 2022 10:14:02 +0100 Subject: [PATCH 01/21] Otel Operator release 0.43.0 --- CHANGELOG.md | 4 ++++ README.md | 1 + .../opentelemetry-operator.clusterserviceversion.yaml | 6 +++--- versions.txt | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a689ed081d..7d7cb53bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changes by Version ================== +0.43.0 +* Bumped OpenTelemetry Collector to v0.43.0 +* Fix collector config update ([#670] (https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) + 0.42.0 ------------------- * Bumped OpenTelemetry Collector to v0.42.0 diff --git a/README.md b/README.md index 6a10a962f3..ecdf1e7e1c 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,7 @@ The OpenTelemetry Operator *might* work on versions outside of the given range, | OpenTelemetry Operator | Kubernetes | Cert-Manager | |------------------------|----------------------|----------------------| +| v0.43.0 | v1.21 to v1.23 | 1.6.1 | | v0.42.0 | v1.21 to v1.23 | 1.6.1 | | v0.41.1 | v1.21 to v1.23 | 1.6.1 | | v0.41.0 | v1.20 to v1.22 | 1.6.1 | diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 2882f81592..0a4302dee7 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -37,7 +37,7 @@ metadata: operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: github.com/open-telemetry/opentelemetry-operator support: OpenTelemetry Community - name: opentelemetry-operator.v0.42.0 + name: opentelemetry-operator.v0.43.0 namespace: placeholder spec: apiservicedefinitions: {} @@ -265,7 +265,7 @@ spec: - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election - image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:v0.42.0 + image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:v0.43.0 livenessProbe: httpGet: path: /healthz @@ -369,7 +369,7 @@ spec: maturity: alpha provider: name: OpenTelemetry Community - version: 0.42.0 + version: 0.43.0 webhookdefinitions: - admissionReviewVersions: - v1 diff --git a/versions.txt b/versions.txt index 6e90ed47ce..b973f60265 100644 --- a/versions.txt +++ b/versions.txt @@ -2,10 +2,10 @@ # by default with the OpenTelemetry Operator. This would usually be the latest # stable OpenTelemetry version. When you update this file, make sure to update the # the docs as well. -opentelemetry-collector=0.42.0 +opentelemetry-collector=0.43.0 # Represents the current release of the OpenTelemetry Operator. -operator=0.42.0 +operator=0.43.0 # Represents the current release of the Target Allocator. targetallocator=0.1.0 From 5d8f4a260fa823773ecf6b3d8b5ae11e6d11fe17 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Fri, 28 Jan 2022 11:40:09 +0100 Subject: [PATCH 02/21] Fixing typo --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7cb53bad..a0ced0d107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Changes by Version ================== 0.43.0 +------------------- * Bumped OpenTelemetry Collector to v0.43.0 * Fix collector config update ([#670] (https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) From cd5074e4cb61f48372ff064b2ef91d9843721c73 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 8 Feb 2022 19:26:13 +0100 Subject: [PATCH 03/21] Upgrade script to version 0.43.0 --- pkg/collector/upgrade/v0_43_0.go | 97 +++++++++++++++++++ pkg/collector/upgrade/v0_43_0_test.go | 48 +++++++++ .../00-install-collector.yaml | 2 - .../00-install-collector.yaml | 2 - .../00-install-collector.yaml | 2 - .../e2e/smoke-pod-annotations/00-install.yaml | 2 - .../00-install.yaml | 2 - .../01-install-second-config.yaml | 3 +- tests/e2e/smoke-sidecar/00-install.yaml | 2 - tests/e2e/smoke-simplest/00-install.yaml | 4 +- 10 files changed, 147 insertions(+), 17 deletions(-) create mode 100644 pkg/collector/upgrade/v0_43_0.go create mode 100644 pkg/collector/upgrade/v0_43_0_test.go diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go new file mode 100644 index 0000000000..38ce7a56c9 --- /dev/null +++ b/pkg/collector/upgrade/v0_43_0.go @@ -0,0 +1,97 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package upgrade + +import ( + "fmt" + "reflect" + "sort" + "strings" + + "gopkg.in/yaml.v2" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" +) + +func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) { + // return if args exist + if len(otelcol.Spec.Args) == 0 { + return otelcol, nil + } + + foundMetricsArgs := make(map[string]string) + for argKey, argValue := range otelcol.Spec.Args { + if argKey == "--metrics-addr" || argKey == "--metrics-level" { + foundMetricsArgs[argKey] = argValue + delete(otelcol.Spec.Args, argKey) + } + } + + if len(foundMetricsArgs) > 0 { + cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) + } + + serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) + if !ok { + + cfg["service"] = make(map[interface{}]interface{}) + serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) + } + + telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) + if !ok { + serviceConfig["telemetry"] = make(map[interface{}]interface{}) + telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) + } + + metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) + if !ok { + telemetryConfig["metrics"] = make(map[interface{}]interface{}) + metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) + } + + if len(metricsConfig) == 0 { + if val, ok := foundMetricsArgs["--metrics-addr"]; ok { + metricsConfig["address"] = val + } + if val, ok := foundMetricsArgs["--metrics-level"]; ok { + metricsConfig["level"] = val + } + } + cfg["service"] = serviceConfig + res, err := yaml.Marshal(cfg) + + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) + } + + otelcol.Spec.Config = string(res) + + keys := reflect.ValueOf(foundMetricsArgs).MapKeys() + + sort.Slice(keys, func(i, j int) bool { + return strings.Compare(keys[i].String(), keys[j].String()) <= 0 + }) + + otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+ + "i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) + } + + return otelcol,nil +} diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go new file mode 100644 index 0000000000..ffb2b419ee --- /dev/null +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -0,0 +1,48 @@ +package upgrade_test + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/version" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" +) + +func TestRemoveMetricsArgs(t *testing.T) { + // prepare + nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} + existing := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: nsn.Name, + Namespace: nsn.Namespace, + Labels: map[string]string{ + "app.kubernetes.io/managed-by": "opentelemetry-operator", + }, + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + Args: map[string]string{ + // this would not happen in the real world, as it's either one or another, but we aren't going that far + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + }, + }, + } + existing.Status.Version = "0.42.0" + + require.Contains(t, existing.Spec.Args, "--metrics-addr") + require.Contains(t, existing.Spec.Args, "--metrics-level") + + // test + res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) + assert.NoError(t, err) + + // verify + assert.NotContains(t, res.Spec.Args, "--metrics-addr") + assert.NotContains(t, res.Spec.Args, "--metrics-level") +} \ No newline at end of file diff --git a/tests/e2e/instrumentation-java/00-install-collector.yaml b/tests/e2e/instrumentation-java/00-install-collector.yaml index b823086361..f8e1e98e07 100644 --- a/tests/e2e/instrumentation-java/00-install-collector.yaml +++ b/tests/e2e/instrumentation-java/00-install-collector.yaml @@ -4,8 +4,6 @@ metadata: name: sidecar spec: mode: sidecar - args: - metrics-level: detailed config: | receivers: otlp: diff --git a/tests/e2e/instrumentation-nodejs/00-install-collector.yaml b/tests/e2e/instrumentation-nodejs/00-install-collector.yaml index b823086361..f8e1e98e07 100644 --- a/tests/e2e/instrumentation-nodejs/00-install-collector.yaml +++ b/tests/e2e/instrumentation-nodejs/00-install-collector.yaml @@ -4,8 +4,6 @@ metadata: name: sidecar spec: mode: sidecar - args: - metrics-level: detailed config: | receivers: otlp: diff --git a/tests/e2e/instrumentation-python/00-install-collector.yaml b/tests/e2e/instrumentation-python/00-install-collector.yaml index b823086361..f8e1e98e07 100644 --- a/tests/e2e/instrumentation-python/00-install-collector.yaml +++ b/tests/e2e/instrumentation-python/00-install-collector.yaml @@ -4,8 +4,6 @@ metadata: name: sidecar spec: mode: sidecar - args: - metrics-level: detailed config: | receivers: otlp: diff --git a/tests/e2e/smoke-pod-annotations/00-install.yaml b/tests/e2e/smoke-pod-annotations/00-install.yaml index ee3dac5484..cce1909fa0 100644 --- a/tests/e2e/smoke-pod-annotations/00-install.yaml +++ b/tests/e2e/smoke-pod-annotations/00-install.yaml @@ -24,5 +24,3 @@ spec: receivers: [jaeger] processors: [] exporters: [logging] - args: - metrics-level: detailed diff --git a/tests/e2e/smoke-restarting-deployment/00-install.yaml b/tests/e2e/smoke-restarting-deployment/00-install.yaml index fbc93e109b..7ff13711ee 100644 --- a/tests/e2e/smoke-restarting-deployment/00-install.yaml +++ b/tests/e2e/smoke-restarting-deployment/00-install.yaml @@ -17,5 +17,3 @@ spec: receivers: [jaeger] processors: [] exporters: [logging] - args: - metrics-level: detailed diff --git a/tests/e2e/smoke-restarting-deployment/01-install-second-config.yaml b/tests/e2e/smoke-restarting-deployment/01-install-second-config.yaml index bc9362af97..78f90878bb 100644 --- a/tests/e2e/smoke-restarting-deployment/01-install-second-config.yaml +++ b/tests/e2e/smoke-restarting-deployment/01-install-second-config.yaml @@ -20,5 +20,4 @@ spec: receivers: [jaeger, otlp] processors: [] exporters: [logging] - args: - metrics-level: detailed + diff --git a/tests/e2e/smoke-sidecar/00-install.yaml b/tests/e2e/smoke-sidecar/00-install.yaml index 33d0805210..1d498c6268 100644 --- a/tests/e2e/smoke-sidecar/00-install.yaml +++ b/tests/e2e/smoke-sidecar/00-install.yaml @@ -4,8 +4,6 @@ metadata: name: sidecar-for-my-app spec: mode: sidecar - args: - metrics-level: detailed config: | receivers: jaeger: diff --git a/tests/e2e/smoke-simplest/00-install.yaml b/tests/e2e/smoke-simplest/00-install.yaml index 205c59226e..a1a6120f7c 100644 --- a/tests/e2e/smoke-simplest/00-install.yaml +++ b/tests/e2e/smoke-simplest/00-install.yaml @@ -18,6 +18,4 @@ spec: traces: receivers: [jaeger] processors: [] - exporters: [logging] - args: - metrics-level: detailed \ No newline at end of file + exporters: [logging] \ No newline at end of file From 0c58c80a0905db7c764e633a447a36612bf5ca76 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 8 Feb 2022 19:33:50 +0100 Subject: [PATCH 04/21] Including versions reference --- pkg/collector/upgrade/versions.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/collector/upgrade/versions.go b/pkg/collector/upgrade/versions.go index 067686330d..641b75510a 100644 --- a/pkg/collector/upgrade/versions.go +++ b/pkg/collector/upgrade/versions.go @@ -70,6 +70,10 @@ var ( Version: *semver.MustParse("0.41.0"), upgrade: upgrade0_41_0, }, + { + Version: *semver.MustParse("0.43.0"), + upgrade: upgrade0_43_0, + }, } // Latest represents the latest version that we need to upgrade. This is not necessarily the latest known version. From b9c3e5e487659092fca1c2d2f3b329d63f3dc244 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Tue, 8 Feb 2022 20:02:05 +0100 Subject: [PATCH 05/21] Fixing Lint tests --- pkg/collector/upgrade/v0_43_0.go | 147 +++++++++++++------------- pkg/collector/upgrade/v0_43_0_test.go | 70 ++++++------ 2 files changed, 108 insertions(+), 109 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index 38ce7a56c9..fe62f312f5 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -15,83 +15,82 @@ package upgrade import ( - "fmt" - "reflect" - "sort" - "strings" + "fmt" + "reflect" + "sort" + "strings" - "gopkg.in/yaml.v2" - "sigs.k8s.io/controller-runtime/pkg/client" + "gopkg.in/yaml.v2" + "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" ) func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) { - // return if args exist - if len(otelcol.Spec.Args) == 0 { - return otelcol, nil - } - - foundMetricsArgs := make(map[string]string) - for argKey, argValue := range otelcol.Spec.Args { - if argKey == "--metrics-addr" || argKey == "--metrics-level" { - foundMetricsArgs[argKey] = argValue - delete(otelcol.Spec.Args, argKey) - } - } - - if len(foundMetricsArgs) > 0 { - cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) - if err != nil { - return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) - } - - serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) - if !ok { - - cfg["service"] = make(map[interface{}]interface{}) - serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) - } - - telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) - if !ok { - serviceConfig["telemetry"] = make(map[interface{}]interface{}) - telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) - } - - metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) - if !ok { - telemetryConfig["metrics"] = make(map[interface{}]interface{}) - metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) - } - - if len(metricsConfig) == 0 { - if val, ok := foundMetricsArgs["--metrics-addr"]; ok { - metricsConfig["address"] = val - } - if val, ok := foundMetricsArgs["--metrics-level"]; ok { - metricsConfig["level"] = val - } - } - cfg["service"] = serviceConfig - res, err := yaml.Marshal(cfg) - - if err != nil { - return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) - } - - otelcol.Spec.Config = string(res) - - keys := reflect.ValueOf(foundMetricsArgs).MapKeys() - - sort.Slice(keys, func(i, j int) bool { - return strings.Compare(keys[i].String(), keys[j].String()) <= 0 - }) - - otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+ - "i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) - } - - return otelcol,nil + // return if args exist + if len(otelcol.Spec.Args) == 0 { + return otelcol, nil + } + + foundMetricsArgs := make(map[string]string) + for argKey, argValue := range otelcol.Spec.Args { + if argKey == "--metrics-addr" || argKey == "--metrics-level" { + foundMetricsArgs[argKey] = argValue + delete(otelcol.Spec.Args, argKey) + } + } + + if len(foundMetricsArgs) > 0 { + cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) + } + + serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) + if !ok { + + cfg["service"] = make(map[interface{}]interface{}) + serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) + } + + telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) + if !ok { + serviceConfig["telemetry"] = make(map[interface{}]interface{}) + telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) + } + + metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) + if !ok { + telemetryConfig["metrics"] = make(map[interface{}]interface{}) + metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) + } + + if len(metricsConfig) == 0 { + if val, ok := foundMetricsArgs["--metrics-addr"]; ok { + metricsConfig["address"] = val + } + if val, ok := foundMetricsArgs["--metrics-level"]; ok { + metricsConfig["level"] = val + } + } + cfg["service"] = serviceConfig + res, err := yaml.Marshal(cfg) + + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) + } + + otelcol.Spec.Config = string(res) + + keys := reflect.ValueOf(foundMetricsArgs).MapKeys() + + sort.Slice(keys, func(i, j int) bool { + return strings.Compare(keys[i].String(), keys[j].String()) <= 0 + }) + + otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments " + "i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) + } + + return otelcol, nil } diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index ffb2b419ee..0705a17965 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -1,48 +1,48 @@ package upgrade_test import ( - "context" - "testing" + "context" + "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" - "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" - "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/version" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) func TestRemoveMetricsArgs(t *testing.T) { - // prepare - nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} - existing := v1alpha1.OpenTelemetryCollector{ - ObjectMeta: metav1.ObjectMeta{ - Name: nsn.Name, - Namespace: nsn.Namespace, - Labels: map[string]string{ - "app.kubernetes.io/managed-by": "opentelemetry-operator", - }, - }, - Spec: v1alpha1.OpenTelemetryCollectorSpec{ - Args: map[string]string{ - // this would not happen in the real world, as it's either one or another, but we aren't going that far - "--metrics-addr": ":8988", - "--metrics-level": "detailed", - }, - }, - } - existing.Status.Version = "0.42.0" + // prepare + nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} + existing := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: nsn.Name, + Namespace: nsn.Namespace, + Labels: map[string]string{ + "app.kubernetes.io/managed-by": "opentelemetry-operator", + }, + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + Args: map[string]string{ + // this would not happen in the real world, as it's either one or another, but we aren't going that far + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + }, + }, + } + existing.Status.Version = "0.42.0" - require.Contains(t, existing.Spec.Args, "--metrics-addr") - require.Contains(t, existing.Spec.Args, "--metrics-level") + require.Contains(t, existing.Spec.Args, "--metrics-addr") + require.Contains(t, existing.Spec.Args, "--metrics-level") - // test - res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) - assert.NoError(t, err) + // test + res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) + assert.NoError(t, err) - // verify - assert.NotContains(t, res.Spec.Args, "--metrics-addr") - assert.NotContains(t, res.Spec.Args, "--metrics-level") + // verify + assert.NotContains(t, res.Spec.Args, "--metrics-addr") + assert.NotContains(t, res.Spec.Args, "--metrics-level") } \ No newline at end of file From 61e9e18f91b9a8d0c81e8314f6af6b64dad23704 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 10:54:54 +0100 Subject: [PATCH 06/21] Adding metrics changes into CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0ced0d107..d0a278c65d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Changes by Version ------------------- * Bumped OpenTelemetry Collector to v0.43.0 * Fix collector config update ([#670] (https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) +* Remove deprecate flags --metrics-level and --metrics-addr (#4695) + - Usages of `--metrics-level={VALUE}` can be replaced by `--set=service.telemetry.metrics.level={VALUE}`; + - Usages of `--metrics-addr={VALUE}` can be replaced by `--set=service.telemetry.metrics.address={VALUE}`; 0.42.0 ------------------- From 2d4e47e11a90fa1006a44a9521c3fde7ddeb7a0c Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 11:27:42 +0100 Subject: [PATCH 07/21] Removed comment and fixed changelog --- CHANGELOG.md | 4 +--- pkg/collector/upgrade/v0_43_0_test.go | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0a278c65d..916c5d4f40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,7 @@ Changes by Version ------------------- * Bumped OpenTelemetry Collector to v0.43.0 * Fix collector config update ([#670] (https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) -* Remove deprecate flags --metrics-level and --metrics-addr (#4695) - - Usages of `--metrics-level={VALUE}` can be replaced by `--set=service.telemetry.metrics.level={VALUE}`; - - Usages of `--metrics-addr={VALUE}` can be replaced by `--set=service.telemetry.metrics.address={VALUE}`; +* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#4695] (https://github.com/open-telemetry/opentelemetry-collector/pull/4695), [@codebote](https://github.com/codeboten)) 0.42.0 ------------------- diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 0705a17965..db0fa7b77a 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -27,7 +27,6 @@ func TestRemoveMetricsArgs(t *testing.T) { }, Spec: v1alpha1.OpenTelemetryCollectorSpec{ Args: map[string]string{ - // this would not happen in the real world, as it's either one or another, but we aren't going that far "--metrics-addr": ":8988", "--metrics-level": "detailed", }, From bd4475d3e2b1417d4bbe932349c64024a0a78098 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 12:00:16 +0100 Subject: [PATCH 08/21] Added new PR on Changelog and added lint fixes --- CHANGELOG.md | 12 ++- pkg/collector/upgrade/v0_43_0.go | 146 +++++++++++++------------- pkg/collector/upgrade/v0_43_0_test.go | 70 ++++++------ 3 files changed, 118 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916c5d4f40..8f1200b31e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,15 @@ Changes by Version 0.43.0 ------------------- * Bumped OpenTelemetry Collector to v0.43.0 -* Fix collector config update ([#670] (https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) -* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#4695] (https://github.com/open-telemetry/opentelemetry-collector/pull/4695), [@codebote](https://github.com/codeboten)) +* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#4695](https://github.com/open-telemetry/opentelemetry-collector/pull/4695), [@codebote](https://github.com/codeboten)) +* Add unique label and selector for operator objects ([#697](https://github.com/open-telemetry/opentelemetry-operator/pull/697), [@pavolloffay](https://github.com/pavolloffay)) +* Update java instrumentation to 1.10.1 ([#688](https://github.com/open-telemetry/opentelemetry-operator/pull/688), [@anuraaga](https://github.com/anuraaga)) +* Update nodejs instrumentation to 0.27.0 ([#687](https://github.com/open-telemetry/opentelemetry-operator/pull/687), [@anuraaga](https://github.com/anuraaga)) +* Update python instrumentation to 0.28b1 ([#686](https://github.com/open-telemetry/opentelemetry-operator/pull/686), [@anuraaga](https://github.com/anuraaga)) +* Add b3, jaeger, ottrace propagators to python instrumentation ([#684](https://github.com/open-telemetry/opentelemetry-operator/pull/684), [@anuraaga](https://github.com/anuraaga)) +* Add env support to instrumentation kind ([#674](https://github.com/open-telemetry/opentelemetry-operator/pull/674), [@Duncan-tree-zhou](https://github.com/Duncan-tree-zhou)) +* Fix collector config update ([#670](https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) + 0.42.0 ------------------- @@ -15,6 +22,7 @@ Changes by Version * Remove publishing operator image to quay.io ([#661](https://github.com/open-telemetry/opentelemetry-operator/pull/661), [@pavolloffay](https://github.com/pavolloffay)) * Use target allocator from GHCR ([#660](https://github.com/open-telemetry/opentelemetry-operator/pull/660), [@pavolloffay](https://github.com/pavolloffay)) + 0.41.1 ------------------- * Add support for nodejs and python image defaulting and upgrade ([#607](https://github.com/open-telemetry/opentelemetry-operator/pull/607), [@pavolloffay](https://github.com/pavolloffay)) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index fe62f312f5..8a6f03d53a 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -15,82 +15,82 @@ package upgrade import ( - "fmt" - "reflect" - "sort" - "strings" + "fmt" + "reflect" + "sort" + "strings" - "gopkg.in/yaml.v2" - "sigs.k8s.io/controller-runtime/pkg/client" + "gopkg.in/yaml.v2" + "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" ) func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) { - // return if args exist - if len(otelcol.Spec.Args) == 0 { - return otelcol, nil - } - - foundMetricsArgs := make(map[string]string) - for argKey, argValue := range otelcol.Spec.Args { - if argKey == "--metrics-addr" || argKey == "--metrics-level" { - foundMetricsArgs[argKey] = argValue - delete(otelcol.Spec.Args, argKey) - } - } - - if len(foundMetricsArgs) > 0 { - cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) - if err != nil { - return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) - } - - serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) - if !ok { - - cfg["service"] = make(map[interface{}]interface{}) - serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) - } - - telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) - if !ok { - serviceConfig["telemetry"] = make(map[interface{}]interface{}) - telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) - } - - metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) - if !ok { - telemetryConfig["metrics"] = make(map[interface{}]interface{}) - metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) - } - - if len(metricsConfig) == 0 { - if val, ok := foundMetricsArgs["--metrics-addr"]; ok { - metricsConfig["address"] = val - } - if val, ok := foundMetricsArgs["--metrics-level"]; ok { - metricsConfig["level"] = val - } - } - cfg["service"] = serviceConfig - res, err := yaml.Marshal(cfg) - - if err != nil { - return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) - } - - otelcol.Spec.Config = string(res) - - keys := reflect.ValueOf(foundMetricsArgs).MapKeys() - - sort.Slice(keys, func(i, j int) bool { - return strings.Compare(keys[i].String(), keys[j].String()) <= 0 - }) - - otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments " + "i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) - } - - return otelcol, nil + // return if args exist + if len(otelcol.Spec.Args) == 0 { + return otelcol, nil + } + + foundMetricsArgs := make(map[string]string) + for argKey, argValue := range otelcol.Spec.Args { + if argKey == "--metrics-addr" || argKey == "--metrics-level" { + foundMetricsArgs[argKey] = argValue + delete(otelcol.Spec.Args, argKey) + } + } + + if len(foundMetricsArgs) > 0 { + cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) + } + + serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) + if !ok { + + cfg["service"] = make(map[interface{}]interface{}) + serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) + } + + telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) + if !ok { + serviceConfig["telemetry"] = make(map[interface{}]interface{}) + telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) + } + + metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) + if !ok { + telemetryConfig["metrics"] = make(map[interface{}]interface{}) + metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) + } + + if len(metricsConfig) == 0 { + if val, ok := foundMetricsArgs["--metrics-addr"]; ok { + metricsConfig["address"] = val + } + if val, ok := foundMetricsArgs["--metrics-level"]; ok { + metricsConfig["level"] = val + } + } + cfg["service"] = serviceConfig + res, err := yaml.Marshal(cfg) + + if err != nil { + return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) + } + + otelcol.Spec.Config = string(res) + + keys := reflect.ValueOf(foundMetricsArgs).MapKeys() + + sort.Slice(keys, func(i, j int) bool { + return strings.Compare(keys[i].String(), keys[j].String()) <= 0 + }) + + otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) + } + + return otelcol, nil } diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index db0fa7b77a..52cea1c67a 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -1,47 +1,47 @@ package upgrade_test import ( - "context" - "testing" + "context" + "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" - "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" - "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" + "github.com/open-telemetry/opentelemetry-operator/internal/version" + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) func TestRemoveMetricsArgs(t *testing.T) { - // prepare - nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} - existing := v1alpha1.OpenTelemetryCollector{ - ObjectMeta: metav1.ObjectMeta{ - Name: nsn.Name, - Namespace: nsn.Namespace, - Labels: map[string]string{ - "app.kubernetes.io/managed-by": "opentelemetry-operator", - }, - }, - Spec: v1alpha1.OpenTelemetryCollectorSpec{ - Args: map[string]string{ - "--metrics-addr": ":8988", - "--metrics-level": "detailed", - }, - }, - } - existing.Status.Version = "0.42.0" + // prepare + nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} + existing := v1alpha1.OpenTelemetryCollector{ + ObjectMeta: metav1.ObjectMeta{ + Name: nsn.Name, + Namespace: nsn.Namespace, + Labels: map[string]string{ + "app.kubernetes.io/managed-by": "opentelemetry-operator", + }, + }, + Spec: v1alpha1.OpenTelemetryCollectorSpec{ + Args: map[string]string{ + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + }, + }, + } + existing.Status.Version = "0.42.0" - require.Contains(t, existing.Spec.Args, "--metrics-addr") - require.Contains(t, existing.Spec.Args, "--metrics-level") + require.Contains(t, existing.Spec.Args, "--metrics-addr") + require.Contains(t, existing.Spec.Args, "--metrics-level") - // test - res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) - assert.NoError(t, err) + // test + res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) + assert.NoError(t, err) - // verify - assert.NotContains(t, res.Spec.Args, "--metrics-addr") - assert.NotContains(t, res.Spec.Args, "--metrics-level") -} \ No newline at end of file + // verify + assert.NotContains(t, res.Spec.Args, "--metrics-addr") + assert.NotContains(t, res.Spec.Args, "--metrics-level") +} From 28c41c5f21b37e8f474820774e21a5950f9ec60c Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 12:34:04 +0100 Subject: [PATCH 09/21] Added missing header --- pkg/collector/upgrade/v0_43_0_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 52cea1c67a..5218ebda9d 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -1,3 +1,17 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package upgrade_test import ( From 7d6109b9e901bb244c6c0869bd204938f6b0ca67 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 14:03:28 +0100 Subject: [PATCH 10/21] Fixing upgrade routine --- pkg/collector/upgrade/v0_43_0_test.go | 88 +++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 6 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 5218ebda9d..1e6face922 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -19,7 +19,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -44,18 +43,95 @@ func TestRemoveMetricsArgs(t *testing.T) { "--metrics-addr": ":8988", "--metrics-level": "detailed", }, + Config: ` +receivers: + otlp: + protocols: + grpc: + +processors: + +exporters: + logging: + +service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [logging] +`, }, } existing.Status.Version = "0.42.0" - require.Contains(t, existing.Spec.Args, "--metrics-addr") - require.Contains(t, existing.Spec.Args, "--metrics-level") - // test res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) assert.NoError(t, err) // verify - assert.NotContains(t, res.Spec.Args, "--metrics-addr") - assert.NotContains(t, res.Spec.Args, "--metrics-level") + assert.Equal(t, `receivers: + otlp: + protocols: + grpc: + + processors: + + exporters: + logging: + + service: + telemetry: + metrics: + address: ":8988" + level: "detailed" + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [logging]`, res.Spec.Config) + + assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ + "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ + "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) + + configWithMetrics := `receivers: + otlp: + protocols: + grpc: + + processors: + + exporters: + logging: + + service: + telemetry: + metrics: + address: ":8988" + level: "detailed" + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [logging] +` + existing.Spec.Config = configWithMetrics + existing.Spec.Args = map[string]string{ + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + } + res, err = upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) + assert.NoError(t, err) + + // verify + assert.Equal(t, configWithMetrics, res.Spec.Config) + assert.Equal(t, map[string]string{ + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + }, res.Spec.Args) + + assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ + "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ + "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already..", res.Status.Messages[0]) } From 8a928679ef3ffa62526267901b9a7b251daf4b82 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 14:17:28 +0100 Subject: [PATCH 11/21] Adding missing operator-sdk PR --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f1200b31e..4c31044b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Changes by Version * Bumped OpenTelemetry Collector to v0.43.0 * Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#4695](https://github.com/open-telemetry/opentelemetry-collector/pull/4695), [@codebote](https://github.com/codeboten)) * Add unique label and selector for operator objects ([#697](https://github.com/open-telemetry/opentelemetry-operator/pull/697), [@pavolloffay](https://github.com/pavolloffay)) +* Bump operator-sdk to 1.17 ([#692](https://github.com/open-telemetry/opentelemetry-operator/pull/692), [@pavolloffay](https://github.com/pavolloffay)) * Update java instrumentation to 1.10.1 ([#688](https://github.com/open-telemetry/opentelemetry-operator/pull/688), [@anuraaga](https://github.com/anuraaga)) * Update nodejs instrumentation to 0.27.0 ([#687](https://github.com/open-telemetry/opentelemetry-operator/pull/687), [@anuraaga](https://github.com/anuraaga)) * Update python instrumentation to 0.28b1 ([#686](https://github.com/open-telemetry/opentelemetry-operator/pull/686), [@anuraaga](https://github.com/anuraaga)) From 212e8ef21b927bd719892921bbd610940ffe7049 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 19:23:06 +0100 Subject: [PATCH 12/21] Change method of sorting args and fixing test --- pkg/collector/upgrade/v0_43_0.go | 12 ++++++------ pkg/collector/upgrade/v0_43_0_test.go | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index 8a6f03d53a..a6d045f442 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -16,9 +16,7 @@ package upgrade import ( "fmt" - "reflect" "sort" - "strings" "gopkg.in/yaml.v2" "sigs.k8s.io/controller-runtime/pkg/client" @@ -83,11 +81,13 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( otelcol.Spec.Config = string(res) - keys := reflect.ValueOf(foundMetricsArgs).MapKeys() + keys := make([]string, 0, len(foundMetricsArgs)) - sort.Slice(keys, func(i, j int) bool { - return strings.Compare(keys[i].String(), keys[j].String()) <= 0 - }) + for k := range foundMetricsArgs { + keys = append(keys, k) + } + + sort.Strings(keys) otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) } diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 1e6face922..acb37391ac 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -69,6 +69,12 @@ service: res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) assert.NoError(t, err) + // verify + assert.Equal(t, map[string]string{ + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + }, res.Spec.Args) + // verify assert.Equal(t, `receivers: otlp: From a37a0e3e19a78f91dde77aa9670785fa090d6340 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 19:46:30 +0100 Subject: [PATCH 13/21] fixing test logic --- pkg/collector/upgrade/v0_43_0_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index acb37391ac..282381323f 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -27,7 +27,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) -func TestRemoveMetricsArgs(t *testing.T) { +func Test0_43_0Upgrade(t *testing.T) { // prepare nsn := types.NamespacedName{Name: "my-instance", Namespace: "default"} existing := v1alpha1.OpenTelemetryCollector{ @@ -42,6 +42,8 @@ func TestRemoveMetricsArgs(t *testing.T) { Args: map[string]string{ "--metrics-addr": ":8988", "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", }, Config: ` receivers: @@ -71,8 +73,8 @@ service: // verify assert.Equal(t, map[string]string{ - "--metrics-addr": ":8988", - "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", }, res.Spec.Args) // verify @@ -126,6 +128,8 @@ service: existing.Spec.Args = map[string]string{ "--metrics-addr": ":8988", "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", } res, err = upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) assert.NoError(t, err) @@ -133,8 +137,8 @@ service: // verify assert.Equal(t, configWithMetrics, res.Spec.Config) assert.Equal(t, map[string]string{ - "--metrics-addr": ":8988", - "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", }, res.Spec.Args) assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ From d6481bcc018284150d9ee258590fab6e71fd0f60 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Wed, 9 Feb 2022 20:12:28 +0100 Subject: [PATCH 14/21] Change method of sorting args and fixing test --- pkg/collector/upgrade/v0_43_0.go | 2 +- pkg/collector/upgrade/v0_43_0_test.go | 106 +++++++++++++------------- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index a6d045f442..b7925b369b 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -89,7 +89,7 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( sort.Strings(keys) - otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics., if no metrics settings are configured already.", keys)) + otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics settings are configured already.", keys)) } return otelcol, nil diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 282381323f..fdff5dc871 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -40,28 +40,27 @@ func Test0_43_0Upgrade(t *testing.T) { }, Spec: v1alpha1.OpenTelemetryCollectorSpec{ Args: map[string]string{ - "--metrics-addr": ":8988", - "--metrics-level": "detailed", - "--test-upgrade43": "true", - "--test-arg1": "otel", + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", }, Config: ` -receivers: - otlp: - protocols: - grpc: - -processors: + receivers: + otlp/mtls: + protocols: + http: + endpoint: mysite.local:55690 exporters: - logging: + otlp: + endpoint: "example.com" service: pipelines: traces: - receivers: [otlp] - processors: [] - exporters: [logging] + receivers: [otlp/mtls] + exporters: [otlp] `, }, } @@ -74,62 +73,61 @@ service: // verify assert.Equal(t, map[string]string{ "--test-upgrade43": "true", - "--test-arg1": "otel", + "--test-arg1": "otel", }, res.Spec.Args) // verify - assert.Equal(t, `receivers: + assert.Equal(t, `exporters: otlp: + endpoint: example.com + receivers: + otlp/mtls: protocols: - grpc: - - processors: - - exporters: - logging: - + http: + endpoint: mysite.local:55690 service: + pipelines: + traces: + exporters: + - otlp + receivers: + - otlp/mtls telemetry: metrics: address: ":8988" level: "detailed" - pipelines: - traces: - receivers: [otlp] - processors: [] - exporters: [logging]`, res.Spec.Config) +`, res.Spec.Config) assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) - configWithMetrics := `receivers: - otlp: - protocols: - grpc: - - processors: - - exporters: - logging: - - service: - telemetry: - metrics: - address: ":8988" - level: "detailed" - pipelines: - traces: - receivers: [otlp] - processors: [] - exporters: [logging] + configWithMetrics := `exporters: + otlp: + endpoint: example.com + receivers: + otlp/mtls: + protocols: + http: + endpoint: mysite.local:55690 + service: + pipelines: + traces: + exporters: + - otlp + receivers: + - otlp/mtls + telemetry: + metrics: + address: ":8988" + level: "detailed" ` existing.Spec.Config = configWithMetrics existing.Spec.Args = map[string]string{ - "--metrics-addr": ":8988", - "--metrics-level": "detailed", - "--test-upgrade43": "true", - "--test-arg1": "otel", + "--metrics-addr": ":8988", + "--metrics-level": "detailed", + "--test-upgrade43": "true", + "--test-arg1": "otel", } res, err = upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) assert.NoError(t, err) @@ -138,10 +136,10 @@ service: assert.Equal(t, configWithMetrics, res.Spec.Config) assert.Equal(t, map[string]string{ "--test-upgrade43": "true", - "--test-arg1": "otel", + "--test-arg1": "otel", }, res.Spec.Args) assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ - "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already..", res.Status.Messages[0]) + "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) } From 70b720e29726659d2a86a5dc5b3f2cd0808cc51e Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 09:16:22 +0100 Subject: [PATCH 15/21] Fixed Changelog links --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c31044b5a..ba8dcce0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changes by Version 0.43.0 ------------------- * Bumped OpenTelemetry Collector to v0.43.0 -* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#4695](https://github.com/open-telemetry/opentelemetry-collector/pull/4695), [@codebote](https://github.com/codeboten)) +* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#680](https://github.com/open-telemetry/opentelemetry-operator/pull/680), [@codebote](https://github.com/yuriolisa)) * Add unique label and selector for operator objects ([#697](https://github.com/open-telemetry/opentelemetry-operator/pull/697), [@pavolloffay](https://github.com/pavolloffay)) * Bump operator-sdk to 1.17 ([#692](https://github.com/open-telemetry/opentelemetry-operator/pull/692), [@pavolloffay](https://github.com/pavolloffay)) * Update java instrumentation to 1.10.1 ([#688](https://github.com/open-telemetry/opentelemetry-operator/pull/688), [@anuraaga](https://github.com/anuraaga)) From 89224f8c7cd0a6c3b986d1a42092da613eabca60 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 09:16:55 +0100 Subject: [PATCH 16/21] Fixed Changelog links --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8dcce0ff..3b6adf4fe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changes by Version 0.43.0 ------------------- * Bumped OpenTelemetry Collector to v0.43.0 -* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#680](https://github.com/open-telemetry/opentelemetry-operator/pull/680), [@codebote](https://github.com/yuriolisa)) +* Upgrade to 0.43.0 will move the metrics CLI arguments into the config, in response to ([#680](https://github.com/open-telemetry/opentelemetry-operator/pull/680), [@yuriolisa](https://github.com/yuriolisa)) * Add unique label and selector for operator objects ([#697](https://github.com/open-telemetry/opentelemetry-operator/pull/697), [@pavolloffay](https://github.com/pavolloffay)) * Bump operator-sdk to 1.17 ([#692](https://github.com/open-telemetry/opentelemetry-operator/pull/692), [@pavolloffay](https://github.com/pavolloffay)) * Update java instrumentation to 1.10.1 ([#688](https://github.com/open-telemetry/opentelemetry-operator/pull/688), [@anuraaga](https://github.com/anuraaga)) From bc9f20d1e7f871db165885cee83f75d3036b1bab Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 09:33:29 +0100 Subject: [PATCH 17/21] Change lint format on version tests --- pkg/collector/upgrade/v0_43_0_test.go | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index fdff5dc871..566b0fc9bc 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -46,11 +46,11 @@ func Test0_43_0Upgrade(t *testing.T) { "--test-arg1": "otel", }, Config: ` - receivers: - otlp/mtls: - protocols: - http: - endpoint: mysite.local:55690 +receivers: + otlp/mtls: + protocols: + http: + endpoint: mysite.local:55690 exporters: otlp: @@ -78,24 +78,24 @@ service: // verify assert.Equal(t, `exporters: - otlp: - endpoint: example.com - receivers: - otlp/mtls: - protocols: - http: - endpoint: mysite.local:55690 - service: - pipelines: - traces: - exporters: - - otlp - receivers: - - otlp/mtls - telemetry: - metrics: - address: ":8988" - level: "detailed" + otlp: + endpoint: example.com +receivers: + otlp/mtls: + protocols: + http: + endpoint: mysite.local:55690 +service: + pipelines: + traces: + exporters: + - otlp + receivers: + - otlp/mtls + telemetry: + metrics: + address: ":8988" + level: "detailed" `, res.Spec.Config) assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ @@ -103,24 +103,24 @@ service: "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) configWithMetrics := `exporters: - otlp: - endpoint: example.com - receivers: - otlp/mtls: - protocols: - http: - endpoint: mysite.local:55690 - service: - pipelines: - traces: - exporters: - - otlp - receivers: - - otlp/mtls - telemetry: - metrics: - address: ":8988" - level: "detailed" + otlp: + endpoint: example.com +receivers: + otlp/mtls: + protocols: + http: + endpoint: mysite.local:55690 +service: + pipelines: + traces: + exporters: + - otlp + receivers: + - otlp/mtls + telemetry: + metrics: + address: ":8988" + level: "detailed" ` existing.Spec.Config = configWithMetrics existing.Spec.Args = map[string]string{ From b16e89531fc68b3d60db5ef0080694260872c271 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 09:49:00 +0100 Subject: [PATCH 18/21] Fixed typos on test --- pkg/collector/upgrade/v0_43_0.go | 2 +- pkg/collector/upgrade/v0_43_0_test.go | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index b7925b369b..9ddd27506c 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -89,7 +89,7 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( sort.Strings(keys) - otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics settings are configured already.", keys)) + otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", keys)) } return otelcol, nil diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 566b0fc9bc..bc270c80d0 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -94,13 +94,11 @@ service: - otlp/mtls telemetry: metrics: - address: ":8988" - level: "detailed" + address: :8988 + level: detailed `, res.Spec.Config) - assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ - "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ - "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) + assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+"adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) configWithMetrics := `exporters: otlp: @@ -119,8 +117,8 @@ service: - otlp/mtls telemetry: metrics: - address: ":8988" - level: "detailed" + address: :8988 + level: detailed ` existing.Spec.Config = configWithMetrics existing.Spec.Args = map[string]string{ @@ -139,7 +137,5 @@ service: "--test-arg1": "otel", }, res.Spec.Args) - assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+ - "i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+ - "adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) + assert.Equal(t, "upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. [--metrics-addr --metrics-level] from otelcol custom resource otelcol.spec.args and "+"adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", res.Status.Messages[0]) } From fb69a6d9d3f77385b9af2eb9ab51ddcb5176e8f8 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 10:02:23 +0100 Subject: [PATCH 19/21] Fixed typos on test --- pkg/collector/upgrade/v0_43_0_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index bc270c80d0..e259261de5 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -113,8 +113,8 @@ service: traces: exporters: - otlp - receivers: - - otlp/mtls + receivers: + - otlp/mtls telemetry: metrics: address: :8988 From 7fae1056a85e0f91ce6c22cd62bc268b64a84bfd Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 10:49:12 +0100 Subject: [PATCH 20/21] Fixed Changelog and added description in test file --- CHANGELOG.md | 2 -- pkg/collector/upgrade/v0_43_0.go | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b6adf4fe0..11a912080d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ Changes by Version * Add env support to instrumentation kind ([#674](https://github.com/open-telemetry/opentelemetry-operator/pull/674), [@Duncan-tree-zhou](https://github.com/Duncan-tree-zhou)) * Fix collector config update ([#670](https://github.com/open-telemetry/opentelemetry-operator/pull/670), [@mcariapas](https://github.com/mcariapas)) - 0.42.0 ------------------- * Bumped OpenTelemetry Collector to v0.42.0 @@ -23,7 +22,6 @@ Changes by Version * Remove publishing operator image to quay.io ([#661](https://github.com/open-telemetry/opentelemetry-operator/pull/661), [@pavolloffay](https://github.com/pavolloffay)) * Use target allocator from GHCR ([#660](https://github.com/open-telemetry/opentelemetry-operator/pull/660), [@pavolloffay](https://github.com/pavolloffay)) - 0.41.1 ------------------- * Add support for nodejs and python image defaulting and upgrade ([#607](https://github.com/open-telemetry/opentelemetry-operator/pull/607), [@pavolloffay](https://github.com/pavolloffay)) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index 9ddd27506c..a54d108bd4 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -31,6 +31,9 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( return otelcol, nil } + //Removing deprecated Spec.Args (--metrics-addr and --metrics-level) based on + // https://github.com/open-telemetry/opentelemetry-collector/pull/4695 + //Both args can be used now on the Spec.Config foundMetricsArgs := make(map[string]string) for argKey, argValue := range otelcol.Spec.Args { if argKey == "--metrics-addr" || argKey == "--metrics-level" { @@ -39,6 +42,7 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( } } + // If we find metrics being used on Spec.Args we'll move to the syntax on Spec.Config if len(foundMetricsArgs) > 0 { cfg, err := adapters.ConfigFromString(otelcol.Spec.Config) if err != nil { @@ -64,6 +68,8 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( metricsConfig, _ = telemetryConfig["metrics"].(map[interface{}]interface{}) } + // if there are already those Args under Spec.Config + // then we won't override them. if len(metricsConfig) == 0 { if val, ok := foundMetricsArgs["--metrics-addr"]; ok { metricsConfig["address"] = val From 948c8ece74c9c377b927e8d070f185483268f702 Mon Sep 17 00:00:00 2001 From: Yuri Sa Date: Thu, 10 Feb 2022 13:08:22 +0100 Subject: [PATCH 21/21] Removed empty lines --- pkg/collector/upgrade/v0_43_0.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pkg/collector/upgrade/v0_43_0.go b/pkg/collector/upgrade/v0_43_0.go index a54d108bd4..5548d61476 100644 --- a/pkg/collector/upgrade/v0_43_0.go +++ b/pkg/collector/upgrade/v0_43_0.go @@ -48,20 +48,16 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( if err != nil { return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to parse configuration: %w", err) } - serviceConfig, ok := cfg["service"].(map[interface{}]interface{}) if !ok { - cfg["service"] = make(map[interface{}]interface{}) serviceConfig, _ = cfg["service"].(map[interface{}]interface{}) } - telemetryConfig, ok := serviceConfig["telemetry"].(map[interface{}]interface{}) if !ok { serviceConfig["telemetry"] = make(map[interface{}]interface{}) telemetryConfig, _ = serviceConfig["telemetry"].(map[interface{}]interface{}) } - metricsConfig, ok := telemetryConfig["metrics"].(map[interface{}]interface{}) if !ok { telemetryConfig["metrics"] = make(map[interface{}]interface{}) @@ -80,23 +76,16 @@ func upgrade0_43_0(cl client.Client, otelcol *v1alpha1.OpenTelemetryCollector) ( } cfg["service"] = serviceConfig res, err := yaml.Marshal(cfg) - if err != nil { return otelcol, fmt.Errorf("couldn't upgrade to v0.43.0, failed to marshall back configuration: %w", err) } - otelcol.Spec.Config = string(res) - keys := make([]string, 0, len(foundMetricsArgs)) - for k := range foundMetricsArgs { keys = append(keys, k) } - sort.Strings(keys) - otelcol.Status.Messages = append(otelcol.Status.Messages, fmt.Sprintf("upgrade to v0.43.0 dropped the deprecated metrics arguments "+"i.e. %v from otelcol custom resource otelcol.spec.args and adding them to otelcol.spec.config.service.telemetry.metrics, if no metrics arguments are configured already.", keys)) } - return otelcol, nil }