forked from open-telemetry/opentelemetry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unifyEnvVarExpansion workaround for Prometheus receiver (open-…
…telemetry#3174) * Remove unifyEnvVarExpansion workaround for Prometheus receiver Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Remove flag Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Remove flag Signed-off-by: Pavol Loffay <p.loffay@gmail.com> * Fix Signed-off-by: Pavol Loffay <p.loffay@gmail.com> --------- Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
- Loading branch information
1 parent
c0c0c79
commit 2f322f0
Showing
9 changed files
with
281 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: bug_fix | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: collector | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Remove workaround for 0.104.0 that enabled feature-gate `confmap.unifyEnvVarExpansion` when Prometheus receiver was enabled. | ||
|
||
# One or more tracking issues related to the change | ||
issues: [3142] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
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
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,65 @@ | ||
// 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 ( | ||
"slices" | ||
"strings" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" | ||
) | ||
|
||
func upgrade0_105_0(_ VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) { | ||
var enable bool | ||
for receiver := range otelcol.Spec.Config.Receivers.Object { | ||
if strings.Contains(receiver, "prometheus") { | ||
enable = true | ||
break | ||
} | ||
} | ||
if !enable { | ||
return otelcol, nil | ||
} | ||
|
||
envVarExpansionFeatureFlag := "-confmap.unifyEnvVarExpansion" | ||
otelcol.Spec.Args = RemoveFeatureGate(otelcol.Spec.Args, envVarExpansionFeatureFlag) | ||
|
||
return otelcol, nil | ||
} | ||
|
||
const featureGateFlag = "feature-gates" | ||
|
||
// RemoveFeatureGate removes a feature gate from args. | ||
func RemoveFeatureGate(args map[string]string, feature string) map[string]string { | ||
featureGates, ok := args[featureGateFlag] | ||
if !ok { | ||
return args | ||
} | ||
if !strings.Contains(featureGates, feature) { | ||
return args | ||
} | ||
|
||
features := strings.Split(featureGates, ",") | ||
features = slices.DeleteFunc(features, func(s string) bool { | ||
return s == feature | ||
}) | ||
if len(features) == 0 { | ||
delete(args, featureGateFlag) | ||
} else { | ||
featureGates = strings.Join(features, ",") | ||
args[featureGateFlag] = featureGates | ||
} | ||
return args | ||
} |
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,125 @@ | ||
// 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/v1beta1" | ||
"github.com/open-telemetry/opentelemetry-operator/internal/version" | ||
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" | ||
) | ||
|
||
func Test0_105_0Upgrade(t *testing.T) { | ||
collectorInstance := v1beta1.OpenTelemetryCollector{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "OpenTelemetryCollector", | ||
APIVersion: "v1beta1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "otel-my-instance", | ||
Namespace: "somewhere", | ||
}, | ||
Status: v1beta1.OpenTelemetryCollectorStatus{ | ||
Version: "0.104.0", | ||
}, | ||
Spec: v1beta1.OpenTelemetryCollectorSpec{ | ||
OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ | ||
Args: map[string]string{ | ||
"foo": "bar", | ||
"feature-gates": "+baz,-confmap.unifyEnvVarExpansion", | ||
}, | ||
}, | ||
Config: v1beta1.Config{ | ||
Receivers: v1beta1.AnyConfig{ | ||
Object: map[string]interface{}{ | ||
"prometheus": []interface{}{}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
versionUpgrade := &upgrade.VersionUpgrade{ | ||
Log: logger, | ||
Version: version.Get(), | ||
Client: k8sClient, | ||
Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), | ||
} | ||
|
||
col, err := versionUpgrade.ManagedInstance(context.Background(), collectorInstance) | ||
if err != nil { | ||
t.Errorf("expect err: nil but got: %v", err) | ||
} | ||
assert.EqualValues(t, | ||
map[string]string{"foo": "bar", "feature-gates": "+baz"}, col.Spec.Args) | ||
} | ||
|
||
func TestRemoveFeatureGate(t *testing.T) { | ||
tests := []struct { | ||
test string | ||
args map[string]string | ||
feature string | ||
expected map[string]string | ||
}{ | ||
{ | ||
test: "empty", | ||
args: map[string]string{}, | ||
expected: map[string]string{}, | ||
}, | ||
{ | ||
test: "no feature gates", | ||
args: map[string]string{"foo": "bar"}, | ||
feature: "foo", | ||
expected: map[string]string{"foo": "bar"}, | ||
}, | ||
{ | ||
test: "remove enabled feature gate", | ||
args: map[string]string{"foo": "bar", "feature-gates": "+foo"}, | ||
feature: "-foo", | ||
expected: map[string]string{"foo": "bar", "feature-gates": "+foo"}, | ||
}, | ||
{ | ||
test: "remove disabled feature gate", | ||
args: map[string]string{"foo": "bar", "feature-gates": "-foo"}, | ||
feature: "-foo", | ||
expected: map[string]string{"foo": "bar"}, | ||
}, | ||
{ | ||
test: "remove disabled feature gate, start", | ||
args: map[string]string{"foo": "bar", "feature-gates": "-foo,bar"}, | ||
feature: "-foo", | ||
expected: map[string]string{"foo": "bar", "feature-gates": "bar"}, | ||
}, | ||
{ | ||
test: "remove disabled feature gate, end", | ||
args: map[string]string{"foo": "bar", "feature-gates": "bar,-foo"}, | ||
feature: "-foo", | ||
expected: map[string]string{"foo": "bar", "feature-gates": "bar"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.test, func(t *testing.T) { | ||
args := upgrade.RemoveFeatureGate(test.args, test.feature) | ||
assert.Equal(t, test.expected, args) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.