Commit Graph

7 Commits

Author SHA1 Message Date
Olivier G 16ab931966
Make sure flagValue.String() can be called even when flagValue is created by reflect.New (#11651)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Make sure `flagValue.String()` can be called even when flagValue is
created by `reflect.New`

```go
import (
	"flag"
	"log"

	"go.opentelemetry.io/collector/featuregate"
)

func main() {
	fs := new(flag.FlagSet)

	featuregate.GlobalRegistry().RegisterFlags(fs)
	if err := fs.Parse([]string{"--help"}); err != nil {
		log.Fatalf("failed to parse flags: %v", err)
	}
}
```

Before this PR
```
Usage:
  -feature-gates value
        Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature.

panic calling String method on zero featuregate.flagValue for flag feature-gates: runtime error: invalid memory address or nil pointer dereference
failed to parse flags: flag: help requested
```
Note that there is a panic in the message.

After this PR 
```
Usage:
  -feature-gates value
        Comma-delimited list of feature gate identifiers. Prefix with '-' to disable the feature. '+' or no prefix will enable the feature.
failed to parse flags: flag: help requested
```

---------

Co-authored-by: Yang Song <songy23@users.noreply.github.com>
2024-11-19 09:33:10 -08:00
Pablo Baeyens 1dd5ac3a5f
[featuregate] Deprecate NewFlag in favor of RegisterFlags (#8727)
**Description:** 

Deprecate `featuregate.NewFlag` in favor of `Registry.RegisterFlags`,
which registers flags into a provided flagset.

The intent is to unblock future development of new features such as
#7991 without incurring into deprecations or breaking changes to
implement these.
This will allow us to do a 1.0 release.

**Link to tracking Issue:** Relates to #8220
2023-11-06 12:21:58 -08:00
Alex Boten 80d704deb4
[chore] use license shortform (#7694)
* [chore] use license shortform

To remain consistent w/ contrib repo, see https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/22052

Signed-off-by: Alex Boten <aboten@lightstep.com>

* make goporto

Signed-off-by: Alex Boten <aboten@lightstep.com>

---------

Signed-off-by: Alex Boten <aboten@lightstep.com>
2023-05-18 13:11:17 -07:00
Tyler Helmuth 9b978f74f3
[featuregate] Fix issue where StageDeprecated cause an error on register (#7586)
* Update Deprecated to work like Stable but false

* Add changelog

* Fix lint

* Update README
2023-05-09 17:06:42 -07:00
Tyler Helmuth 9ef6429bd0
[featuregate] Finalizing purpose of ToVersion. (#7626)
Finalizes the purpose of `toVersion`.  `toVersion` will represent the version where the feature gate is completely removed.  Setting a `stable` gate to `true` will result in a warning log.  Setting a `stable` gate to `false` will result in an error.

Closes https://github.com/open-telemetry/opentelemetry-collector/issues/7621
2023-05-04 15:33:03 -07:00
Bogdan Drutu 884cdc5b1d
featuregate: Add deprecated Stage and to/from versions (#7484)
Fixes 2 out of the 3 tasks in https://github.com/open-telemetry/opentelemetry-collector/issues/7043

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-04-04 08:43:34 -07:00
Bogdan Drutu a70c017046
Replace existing featuregate.FlagValue with a direct apply version (#7356)
Fixes https://github.com/open-telemetry/opentelemetry-collector/issues/7042

Uses direct values to/from a given registry. Simplifies usage, defers the "set" logic to the Registry.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
2023-03-13 07:51:37 -07:00