-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to use feature-gates in the operator #1619
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) | ||
component: operator | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add ability to use feature gates in the operator | ||
|
||
# One or more tracking issues related to the change | ||
issues: [1619] | ||
|
||
# (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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 flags | ||
|
||
import ( | ||
"flag" | ||
|
||
"go.opentelemetry.io/collector/featuregate" | ||
) | ||
|
||
const ( | ||
featureGatesFlag = "feature-gates" | ||
) | ||
|
||
func Flags(reg *featuregate.Registry) *flag.FlagSet { | ||
flagSet := new(flag.FlagSet) | ||
flagSet.Var(featuregate.NewFlag(reg), featureGatesFlag, | ||
"Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature.") | ||
return flagSet | ||
} |
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,89 @@ | ||
// 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 flags | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.opentelemetry.io/collector/featuregate" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
basicGate = "basic" | ||
advancedGate = "advanced" | ||
falseGate = "false" | ||
) | ||
|
||
func TestSetFlag(t *testing.T) { | ||
featuregate.GlobalRegistry().MustRegister(basicGate, featuregate.StageAlpha) | ||
featuregate.GlobalRegistry().MustRegister(advancedGate, featuregate.StageBeta) | ||
featuregate.GlobalRegistry().MustRegister(falseGate, featuregate.StageStable, featuregate.WithRegisterRemovalVersion("v0.0.1")) | ||
tests := []struct { | ||
name string | ||
args []string | ||
expectedTrue []string | ||
expectedFalse []string | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "simple set", | ||
args: []string{"--feature-gates=basic"}, | ||
expectedTrue: []string{basicGate}, | ||
}, | ||
{ | ||
name: "two flags", | ||
args: []string{"--feature-gates=basic,advanced"}, | ||
expectedTrue: []string{basicGate, advancedGate}, | ||
}, | ||
{ | ||
name: "one true one false", | ||
args: []string{"--feature-gates=basic,-advanced"}, | ||
expectedTrue: []string{basicGate}, | ||
expectedFalse: []string{advancedGate}, | ||
}, | ||
{ | ||
name: "invalid set", | ||
args: []string{"--feature-gates=01"}, | ||
expectedErr: `no such feature gate -01`, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
flgs := Flags(featuregate.GlobalRegistry()) | ||
err := flgs.Parse(tt.args) | ||
if tt.expectedErr != "" { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
featuregate.GlobalRegistry().VisitAll(func(gate *featuregate.Gate) { | ||
for _, id := range tt.expectedTrue { | ||
if gate.ID() == id { | ||
assert.True(t, gate.IsEnabled()) | ||
} | ||
} | ||
for _, id := range tt.expectedFalse { | ||
if gate.ID() == id { | ||
assert.False(t, gate.IsEnabled()) | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same comments as in the original PR #1557
The package name should probably be changed or include all operator flags. There are as well missing docs.
How do consumers know which feature flags are supported by the operator - take a look at #1557 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pavolloffay It should be possible to include the list of registered featuregates during startup, I can add that.
Also, how to you feel about the addition of the
flag
/featuregate
package? Should we handle the feature gate flags like we do the rest of the flags inmain.go
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a package for it, but the current
flags
name is too generic and therefore I would expect it handles all operator flags.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have confirmed that the latest featuregate package includes the registered gates as default values: