diff --git a/.chloggen/mdatagen-toversion-only-stable-deprecated.yaml b/.chloggen/mdatagen-toversion-only-stable-deprecated.yaml new file mode 100644 index 00000000000..817e9352a10 --- /dev/null +++ b/.chloggen/mdatagen-toversion-only-stable-deprecated.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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. receiver/otlp) +component: cmd/mdatagen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Only allow the `ToVersion` feature flag attribute to be set for the `Stable` and `Deprecated` stages. + +# One or more tracking issues or pull requests related to the change +issues: [15040] + +# (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: | + To better match the feature flag README + (https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md#feature-lifecycle). + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/cmd/mdatagen/internal/metadata.go b/cmd/mdatagen/internal/metadata.go index a4b9aa42527..938654dc996 100644 --- a/cmd/mdatagen/internal/metadata.go +++ b/cmd/mdatagen/internal/metadata.go @@ -441,6 +441,10 @@ func (md *Metadata) validateFeatureGates() error { if (gate.Stage == FeatureGateStageStable || gate.Stage == FeatureGateStageDeprecated) && gate.ToVersion == "" { errs = errors.Join(errs, fmt.Errorf(`feature gate "%v": to_version is required for %v stage gates`, gate.ID, gate.Stage)) } + // Any gate other than stable/deprecated shouldn't have to_version + if gate.Stage != FeatureGateStageStable && gate.Stage != FeatureGateStageDeprecated && gate.ToVersion != "" { + errs = errors.Join(errs, fmt.Errorf(`feature gate "%v": to_version is not supported for the %v stage`, gate.ID, gate.Stage)) + } } return errs } diff --git a/cmd/mdatagen/internal/metadata_test.go b/cmd/mdatagen/internal/metadata_test.go index 1afe0be981a..0a19a8bf420 100644 --- a/cmd/mdatagen/internal/metadata_test.go +++ b/cmd/mdatagen/internal/metadata_test.go @@ -478,6 +478,17 @@ func TestValidateFeatureGates(t *testing.T) { }, wantErr: `to_version is required for deprecated stage gates`, }, + { + name: "non-stable or deprecated gate with a to_version", + featureGate: FeatureGate{ + ID: "component.feature", + Description: "Test feature", + Stage: FeatureGateStageBeta, + FromVersion: "v0.90.0", + ToVersion: "v0.91.0", + }, + wantErr: `to_version is not supported for the beta stage`, + }, { name: "missing reference_url", featureGate: FeatureGate{