-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Otel Operator release 0.43.0 * Fixing typo * Upgrade script to version 0.43.0 * Including versions reference * Fixing Lint tests * Adding metrics changes into CHANGELOG * Removed comment and fixed changelog * Added new PR on Changelog and added lint fixes * Added missing header * Fixing upgrade routine * Adding missing operator-sdk PR * Change method of sorting args and fixing test * fixing test logic * Change method of sorting args and fixing test * Fixed Changelog links * Fixed Changelog links * Change lint format on version tests * Fixed typos on test * Fixed typos on test * Fixed Changelog and added description in test file * Removed empty lines
- Loading branch information
Showing
15 changed files
with
257 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// 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" | ||
"sort" | ||
|
||
"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 | ||
} | ||
|
||
//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" { | ||
foundMetricsArgs[argKey] = argValue | ||
delete(otelcol.Spec.Args, argKey) | ||
} | ||
} | ||
|
||
// 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 { | ||
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 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 | ||
} | ||
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 := 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// 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 ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
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 Test0_43_0Upgrade(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", | ||
"--test-upgrade43": "true", | ||
"--test-arg1": "otel", | ||
}, | ||
Config: ` | ||
receivers: | ||
otlp/mtls: | ||
protocols: | ||
http: | ||
endpoint: mysite.local:55690 | ||
exporters: | ||
otlp: | ||
endpoint: "example.com" | ||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp/mtls] | ||
exporters: [otlp] | ||
`, | ||
}, | ||
} | ||
existing.Status.Version = "0.42.0" | ||
|
||
// test | ||
res, err := upgrade.ManagedInstance(context.Background(), logger, version.Get(), nil, existing) | ||
assert.NoError(t, err) | ||
|
||
// verify | ||
assert.Equal(t, map[string]string{ | ||
"--test-upgrade43": "true", | ||
"--test-arg1": "otel", | ||
}, res.Spec.Args) | ||
|
||
// 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 | ||
`, 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 := `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", | ||
} | ||
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{ | ||
"--test-upgrade43": "true", | ||
"--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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ metadata: | |
name: sidecar | ||
spec: | ||
mode: sidecar | ||
args: | ||
metrics-level: detailed | ||
config: | | ||
receivers: | ||
otlp: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ metadata: | |
name: sidecar | ||
spec: | ||
mode: sidecar | ||
args: | ||
metrics-level: detailed | ||
config: | | ||
receivers: | ||
otlp: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ metadata: | |
name: sidecar | ||
spec: | ||
mode: sidecar | ||
args: | ||
metrics-level: detailed | ||
config: | | ||
receivers: | ||
otlp: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,3 @@ spec: | |
receivers: [jaeger] | ||
processors: [] | ||
exporters: [logging] | ||
args: | ||
metrics-level: detailed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,3 @@ spec: | |
receivers: [jaeger] | ||
processors: [] | ||
exporters: [logging] | ||
args: | ||
metrics-level: detailed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,4 @@ spec: | |
receivers: [jaeger, otlp] | ||
processors: [] | ||
exporters: [logging] | ||
args: | ||
metrics-level: detailed | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters