-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Release v0.57.2 Signed-off-by: Yuri Sa <[email protected]> * Release v0.57.2 Signed-off-by: Yuri Sa <[email protected]> * Added otel upgrade Signed-off-by: Yuri Sa <[email protected]> * Fixed linters Signed-off-by: Yuri Sa <[email protected]> * Fixed unit tests for 0.57.2 Signed-off-by: Yuri Sa <[email protected]> * Fixed requested topics Signed-off-by: Yuri Sa <[email protected]> * Fixed requested topics Signed-off-by: Yuri Sa <[email protected]> * Fixed version number Signed-off-by: Yuri Sa <[email protected]> * Fixed version number Signed-off-by: Yuri Sa <[email protected]> Signed-off-by: Yuri Sa <[email protected]> Co-authored-by: Vineeth Pothulapati <[email protected]>
- Loading branch information
1 parent
24ac119
commit a3644ad
Showing
7 changed files
with
191 additions
and
9 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,69 @@ | ||
// 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" | ||
"strings" | ||
|
||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters" | ||
) | ||
|
||
func upgrade0_57_2(u VersionUpgrade, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) { | ||
|
||
if len(otelcol.Spec.Config) == 0 { | ||
return otelcol, nil | ||
} | ||
|
||
otelCfg, err := adapters.ConfigFromString(otelcol.Spec.Config) | ||
if err != nil { | ||
return otelcol, fmt.Errorf("couldn't upgrade to v0.57.2, failed to parse configuration: %w", err) | ||
} | ||
|
||
//Remove deprecated port field from config. (https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/10853) | ||
extensionsConfig, ok := otelCfg["extensions"].(map[interface{}]interface{}) | ||
if !ok { | ||
// In case there is no extensions config. | ||
return otelcol, nil | ||
} | ||
|
||
for keyExt, valExt := range extensionsConfig { | ||
if strings.HasPrefix(keyExt.(string), "health_check") { | ||
switch extensions := valExt.(type) { | ||
case map[interface{}]interface{}: | ||
if port, ok := extensions["port"]; ok { | ||
endpointV := extensions["endpoint"] | ||
extensions["endpoint"] = fmt.Sprintf("%s:%s", endpointV, port) | ||
delete(extensions, "port") | ||
|
||
otelCfg["extensions"] = extensionsConfig | ||
res, err := yaml.Marshal(otelCfg) | ||
if err != nil { | ||
return otelcol, fmt.Errorf("couldn't upgrade to v0.57.2, failed to marshall back configuration: %w", err) | ||
} | ||
|
||
otelcol.Spec.Config = string(res) | ||
u.Recorder.Event(otelcol, "Normal", "Upgrade", fmt.Sprintf("upgrade to v0.57.2 has deprecated port for healthcheck extension %q", keyExt)) | ||
} | ||
default: | ||
return otelcol, fmt.Errorf("couldn't upgrade to v0.57.2, the extension %q is invalid (expected string or map but was %t)", keyExt, valExt) | ||
} | ||
} | ||
} | ||
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,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_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/record" | ||
|
||
"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_57_0Upgrade(t *testing.T) { | ||
collectorInstance := v1alpha1.OpenTelemetryCollector{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "OpenTelemetryCollector", | ||
APIVersion: "v1alpha1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "otel-my-instance", | ||
Namespace: "somewhere", | ||
}, | ||
Spec: v1alpha1.OpenTelemetryCollectorSpec{ | ||
Config: `receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: mysite.local:55690 | ||
extensions: | ||
health_check: | ||
endpoint: "localhost" | ||
port: "4444" | ||
check_collector_pipeline: | ||
enabled: false | ||
exporter_failure_threshold: 5 | ||
interval: 5m | ||
service: | ||
extensions: [health_check] | ||
pipelines: | ||
metrics: | ||
receivers: [otlp] | ||
exporters: [nop] | ||
`, | ||
}, | ||
} | ||
|
||
collectorInstance.Status.Version = "0.56.0" | ||
//Test to remove port and change endpoint value. | ||
versionUpgrade := &upgrade.VersionUpgrade{ | ||
Log: logger, | ||
Version: version.Get(), | ||
Client: k8sClient, | ||
Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), | ||
} | ||
|
||
upgradedInstance, err := versionUpgrade.ManagedInstance(context.Background(), collectorInstance) | ||
assert.NoError(t, err) | ||
assert.Equal(t, `extensions: | ||
health_check: | ||
check_collector_pipeline: | ||
enabled: false | ||
exporter_failure_threshold: 5 | ||
interval: 5m | ||
endpoint: localhost:4444 | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
endpoint: mysite.local:55690 | ||
service: | ||
extensions: | ||
- health_check | ||
pipelines: | ||
metrics: | ||
exporters: | ||
- nop | ||
receivers: | ||
- otlp | ||
`, upgradedInstance.Spec.Config) | ||
} |
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