-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:jaronoff97/opentelemetry-operator i…
…nto fix-allocation-problems
- Loading branch information
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