Debian Codegraph @

featuregate/README.md

raw
1 # Collector Feature Gates
2
3 This package provides a mechanism that allows operators to enable and disable
4 experimental or transitional features at deployment time. These flags should
5 be able to govern the behavior of the application starting as early as possible
6 and should be available to every component such that decisions may be made
7 based on flags at the component level.
8
9 ## Usage
10
11 Feature gates must be defined and registered with the global registry in
12 an `init()` function. This makes the `Gate` available to be configured and
13 queried with the defined [`Stage`](#feature-lifecycle) default value.
14 A `Gate` can have a list of associated issues that allow users to refer to
15 the issue and report any additional problems or understand the context of the `Gate`.
16 Once a `Gate` has been marked as `Stable`, it must have a `RemovalVersion` set.
17
18 ```go
19 var myFeatureGate = featuregate.GlobalRegistry().MustRegister(
20 "namespaced.uniqueIdentifier",
21 featuregate.Stable,
22 featuregate.WithRegisterFromVersion("v0.65.0")
23 featuregate.WithRegisterDescription("A brief description of what the gate controls"),
24 featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector/issues/6167"),
25 featuregate.WithRegisterToVersion("v0.70.0"))
26 ```
27
28 The status of the gate may later be checked by interrogating the global
29 feature gate registry:
30
31 ```go
32 if myFeatureGate.IsEnabled() {
33 setupNewFeature()
34 }
35 ```
36
37 Note that querying the registry takes a read lock and accesses a map, so it
38 should be done once and the result cached for local use if repeated checks
39 are required. Avoid querying the registry in a loop.
40
41 ## Controlling Gates
42
43 Feature gates can be enabled or disabled via the CLI, with the
44 `--feature-gates` flag. When using the CLI flag, gate
45 identifiers must be presented as a comma-delimited list. Gate identifiers
46 prefixed with `-` will disable the gate and prefixing with `+` or with no
47 prefix will enable the gate.
48
49 ```shell
50 otelcol --config=config.yaml --feature-gates=gate1,-gate2,+gate3
51 ```
52
53 This will enable `gate1` and `gate3` and disable `gate2`.
54
55 ## Feature Lifecycle
56
57 Features controlled by a `Gate` should follow a three-stage lifecycle,
58 modeled after the [system used by Kubernetes](https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates/#feature-stages):
59
60 1. An `alpha` stage where the feature is disabled by default and must be enabled
61 through a `Gate`.
62 2. A `beta` stage where the feature has been well tested and is enabled by
63 default but can be disabled through a `Gate`.
64 3. A generally available or `stable` stage where the feature is permanently enabled. At this stage
65 the gate should no longer be explicitly used. Disabling the gate will produce an error and
66 explicitly enabling will produce a warning log.
67 4. A `stable` feature gate will be removed in the version specified by its `ToVersion` value.
68
69 Features that prove unworkable in the `alpha` stage may be discontinued
70 without proceeding to the `beta` stage. Instead, they will proceed to the
71 `deprecated` stage, which will feature is permanently disabled. A feature gate will
72 be removed once it has been `deprecated` for at least 2 releases of the collector.
73
74 Features that make it to the `beta` stage are intended to reach general availability but may still be discontinued.
75 If, after wider use, it is determined that the gate should be discontinued it will be reverted to the `alpha` stage
76 for 2 releases and then proceed to the `deprecated` stage. If instead it is ready for general availability it will
77 proceed to the `stable` stage.