Skip to content
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

Featuregates don't work until late in initialization #4967

Closed
aabmass opened this issue Mar 7, 2022 · 0 comments · Fixed by #8478
Closed

Featuregates don't work until late in initialization #4967

aabmass opened this issue Mar 7, 2022 · 0 comments · Fixed by #8478
Assignees
Labels
area:featuregate bug Something isn't working priority:p2 Medium

Comments

@aabmass
Copy link
Member

aabmass commented Mar 7, 2022

Describe the bug

The --feature-gates CLI flag is not applied until this line:

if err := cmd.Execute(); err != nil {

As a result any featuregate.IsEnabled(myFeatureGateID) checks during component factory creation (L16 in the same file) will return the default value regardless of the CLI flag. This also effects the contrib repo, for example in the googlecloud exporter this check always returns false.

Steps to reproduce

Perform a featuregate.IsEnabled() check in a NewFactory() method, for example here

return component.NewExporterFactory(

What did you expect to see?
featuregate checks should work early during factory creation. They may be used to enable/disable features early on during initialization. They shouldn't have different result depending on the time they are called.

What did you see instead?
the --feature-gates CLI flag has no effect if checked during factory creation.

What version did you use?
main

What config did you use?
N/A

Environment
Linux/go1.18

cc @dashpole

@aabmass aabmass added the bug Something isn't working label Mar 7, 2022
codeboten pushed a commit that referenced this issue Nov 3, 2023
The factories for the components are created before the CLI flags are
evaluated. Therefore, featuregate flags are ignored during the early
startup phase.
~This PR simply shifts the time of creation of the factory map after the
CLI flag evaluation.~

Closes #4967

**Testing:**
Short manual testing via cli. Adding the following line in
`cobra.Command.RunE`.
```golang
featuregate.GlobalRegistry().VisitAll(func(fg *featuregate.Gate) { fmt.Println(fg.ID(), fg.IsEnabled()) })
```
Changing `+` & `-`:
```bash
./bin/otelcorecol_linux_amd64 --config=config.yaml --feature-gates=+telemetry.disableHighCardinalityMetrics
```

---------

Signed-off-by: Benedikt Bongartz <[email protected]>
Signed-off-by: Alex Boten <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:featuregate bug Something isn't working priority:p2 Medium
Projects
None yet
3 participants