opentelemetry-collector/featuregate
Alex Boten 5a78d05ae3
[featuregate] remove deprecated func (#6594)
* [featuregate] remove deprecated func

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

* update changelog

Signed-off-by: Alex Boten <aboten@lightstep.com>
2022-11-21 14:53:49 -08:00
..
Makefile [featuregate] split into its own module (#6571) 2022-11-17 13:45:36 -08:00
README.md Adding updates to feature gates 2022-11-02 11:04:55 +10:30
flags.go Move featuregate package as top package (#6094) 2022-09-16 11:23:07 -07:00
flags_test.go Move featuregate package as top package (#6094) 2022-09-16 11:23:07 -07:00
gate.go [featuregate] remove deprecated func (#6594) 2022-11-21 14:53:49 -08:00
gate_test.go Deprecate Get prefix funcs for featuregate.Gate (#6528) 2022-11-11 14:21:48 -08:00
go.mod [featuregate] split into its own module (#6571) 2022-11-17 13:45:36 -08:00
go.sum [featuregate] split into its own module (#6571) 2022-11-17 13:45:36 -08:00
registry.go Make impossible to implement RegistryOption outside featuregate package (#6532) 2022-11-17 11:31:49 -08:00
registry_test.go Deprecate Get prefix funcs for featuregate.Gate (#6528) 2022-11-11 14:21:48 -08:00
stage.go Capitalize featuregate.Stage string values, remove Stage prefix (#6527) 2022-11-11 13:21:19 -08:00
stage_test.go Capitalize featuregate.Stage string values, remove Stage prefix (#6527) 2022-11-11 13:21:19 -08:00

README.md

Collector Feature Gates

This package provides a mechanism that allows operators to enable and disable experimental or transitional features at deployment time. These flags should be able to govern the behavior of the application starting as early as possible and should be available to every component such that decisions may be made based on flags at the component level.

Usage

Feature gates must be defined and registered with the global registry in an init() function. This makes the Gate available to be configured and queried with the defined Stage default value. A Gate can have a list of associated issues that allow users to refer to the issue and report any additional problems or understand the context of the Gate. Once a Gate has been marked as Stable, it must have a RemovalVersion set.

const (
	myFeatureGateID = "namespaced.uniqueIdentifier"
	myFeatureStage  = featuregate.Stable
)

func init() {
	featuregate.MustRegisterID(
		myFeatureGateID, 
		myFeatureStage, 
		featuregate.WithRegisterDescription("A brief description of what the gate controls"),
		featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector/issues/6167"),
		featuregate.WithRegisterRemovalVersion("v0.70.0"),
	)
}

The status of the gate may later be checked by interrogating the global feature gate registry:

if featuregate.IsEnabled(myFeatureGateID) {
	setupNewFeature()
}

Note that querying the registry takes a read lock and accesses a map, so it should be done once and the result cached for local use if repeated checks are required. Avoid querying the registry in a loop.

Controlling Gates

Feature gates can be enabled or disabled via the CLI, with the --feature-gates flag. When using the CLI flag, gate identifiers must be presented as a comma-delimited list. Gate identifiers prefixed with - will disable the gate and prefixing with + or with no prefix will enable the gate.

otelcol --config=config.yaml --feature-gates=gate1,-gate2,+gate3

This will enable gate1 and gate3 and disable gate2.

Feature Lifecycle

Features controlled by a Gate should follow a three-stage lifecycle, modeled after the system used by Kubernetes:

  1. An alpha stage where the feature is disabled by default and must be enabled through a Gate.
  2. A beta stage where the feature has been well tested and is enabled by default but can be disabled through a Gate.
  3. A generally available stage where the feature is permanently enabled and the Gate is no longer operative.

Features that prove unworkable in the alpha stage may be discontinued without proceeding to the beta stage. Features that make it to the beta stage will not be dropped and will eventually reach general availability where the Gate that allowed them to be disabled during the beta stage will be removed.