diff --git a/.chloggen/47526.yaml b/.chloggen/47526.yaml new file mode 100644 index 0000000000000..cba89d3b16c84 --- /dev/null +++ b/.chloggen/47526.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/filelog) +component: extension/health_check + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Migrate extension.healthcheck.useComponentStatus feature gate registration from manual code to metadata.yaml for mdatagen code generation + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [46116] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# 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/.golangci.yml b/.golangci.yml index e23dc3b388976..6a046ae3c0136 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -179,9 +179,6 @@ linters: - linters: - forbidigo path: extension/encoding/awslogsencodingextension/ - - linters: - - forbidigo - path: extension/healthcheckextension/ - linters: - forbidigo path: extension/jaegerremotesampling/ diff --git a/extension/healthcheckextension/config.go b/extension/healthcheckextension/config.go index 14448ea7a4f29..9837309f70131 100644 --- a/extension/healthcheckextension/config.go +++ b/extension/healthcheckextension/config.go @@ -6,6 +6,7 @@ package healthcheckextension // import "github.com/open-telemetry/opentelemetry- import ( "errors" + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/healthcheck" ) @@ -16,7 +17,7 @@ type Config struct { // Validate checks if the extension configuration is valid, including feature gate checks. func (c *Config) Validate() error { - if !useComponentStatusGate.IsEnabled() && (c.HTTPConfig != nil || c.GRPCConfig != nil) { + if !metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.IsEnabled() && (c.HTTPConfig != nil || c.GRPCConfig != nil) { return errors.New( "v2 healthcheck configuration (http/grpc fields) detected but feature gate is disabled. " + "Either remove the v2 config fields or enable the feature gate with: " + diff --git a/extension/healthcheckextension/config_test.go b/extension/healthcheckextension/config_test.go index fd9e2a7d002d2..9b522bc88740e 100644 --- a/extension/healthcheckextension/config_test.go +++ b/extension/healthcheckextension/config_test.go @@ -122,10 +122,10 @@ func TestLoadConfigV2WithoutGate(t *testing.T) { } func TestLoadConfigV2WithGate(t *testing.T) { - prev := useComponentStatusGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), true)) + prev := metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), true)) t.Cleanup(func() { - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), prev)) + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), prev)) }) cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) diff --git a/extension/healthcheckextension/documentation.md b/extension/healthcheckextension/documentation.md new file mode 100644 index 0000000000000..44c63faca0545 --- /dev/null +++ b/extension/healthcheckextension/documentation.md @@ -0,0 +1,13 @@ +[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) + +# health_check + +## Feature Gates + +This component has the following feature gates: + +| Feature Gate | Stage | Description | From Version | To Version | Reference | +| ------------ | ----- | ----------- | ------------ | ---------- | --------- | +| `extension.healthcheck.useComponentStatus` | alpha | Switch to the shared healthcheck implementation powered by component status events | v0.142.0 | N/A | [Link](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42256) | + +For more information about feature gates, see the [Feature Gates](https://github.com/open-telemetry/opentelemetry-collector/blob/main/featuregate/README.md) documentation. diff --git a/extension/healthcheckextension/factory.go b/extension/healthcheckextension/factory.go index ab4d27e7dba63..99522814aabb2 100644 --- a/extension/healthcheckextension/factory.go +++ b/extension/healthcheckextension/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/extension" - "go.opentelemetry.io/collector/featuregate" "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" @@ -19,16 +18,6 @@ import ( const defaultPort = 13133 -// Feature gate that switches the extension to the shared healthcheck implementation -var useComponentStatusGate = featuregate.GlobalRegistry().MustRegister( - "extension.healthcheck.useComponentStatus", - featuregate.StageAlpha, - featuregate.WithRegisterDescription("Switch to the shared healthcheck implementation powered by component status events"), - featuregate.WithRegisterFromVersion("v0.142.0"), - featuregate.WithRegisterToVersion("v0.147.0"), - featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42256"), -) - // NewFactory creates a factory for HealthCheck extension. func NewFactory() extension.Factory { return extension.NewFactory( @@ -63,7 +52,7 @@ func createDefaultConfig() component.Config { func createExtension(ctx context.Context, set extension.Settings, cfg component.Config) (extension.Extension, error) { config := cfg.(*Config) - if useComponentStatusGate.IsEnabled() { + if metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.IsEnabled() { // When feature gate is enabled, use v2 implementation directly. // The feature gate controls behavior, not the presence of v2 config fields. config.UseV2 = true diff --git a/extension/healthcheckextension/factory_test.go b/extension/healthcheckextension/factory_test.go index b30dea4d8f365..7c0552f86e55d 100644 --- a/extension/healthcheckextension/factory_test.go +++ b/extension/healthcheckextension/factory_test.go @@ -17,6 +17,7 @@ import ( "go.opentelemetry.io/collector/extension/extensiontest" "go.opentelemetry.io/collector/featuregate" + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/healthcheck" ) @@ -93,10 +94,10 @@ func TestLegacyExtensionPortAlreadyInUse(t *testing.T) { } func TestFactory_CreateV2Extension(t *testing.T) { - prev := useComponentStatusGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), true)) + prev := metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), true)) t.Cleanup(func() { - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), prev)) + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), prev)) }) cfg := createDefaultConfig().(*Config) diff --git a/extension/healthcheckextension/integration_test.go b/extension/healthcheckextension/integration_test.go index e42e5ec7323da..f9beb77b43d73 100644 --- a/extension/healthcheckextension/integration_test.go +++ b/extension/healthcheckextension/integration_test.go @@ -19,6 +19,7 @@ import ( "go.opentelemetry.io/collector/extension/extensiontest" "go.opentelemetry.io/collector/featuregate" + "github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/healthcheck" ) @@ -95,10 +96,10 @@ func TestLegacyReadyNotReadyBehavior(t *testing.T) { } func TestV2ExtensionEnabledByGate(t *testing.T) { - prev := useComponentStatusGate.IsEnabled() - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), true)) + prev := metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.IsEnabled() + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), true)) t.Cleanup(func() { - require.NoError(t, featuregate.GlobalRegistry().Set(useComponentStatusGate.ID(), prev)) + require.NoError(t, featuregate.GlobalRegistry().Set(metadata.ExtensionHealthcheckUseComponentStatusFeatureGate.ID(), prev)) }) transport := &http.Transport{ diff --git a/extension/healthcheckextension/internal/metadata/generated_feature_gates.go b/extension/healthcheckextension/internal/metadata/generated_feature_gates.go new file mode 100644 index 0000000000000..16b2b6a341d37 --- /dev/null +++ b/extension/healthcheckextension/internal/metadata/generated_feature_gates.go @@ -0,0 +1,15 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package metadata + +import ( + "go.opentelemetry.io/collector/featuregate" +) + +var ExtensionHealthcheckUseComponentStatusFeatureGate = featuregate.GlobalRegistry().MustRegister( + "extension.healthcheck.useComponentStatus", + featuregate.StageAlpha, + featuregate.WithRegisterDescription("Switch to the shared healthcheck implementation powered by component status events"), + featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42256"), + featuregate.WithRegisterFromVersion("v0.142.0"), +) diff --git a/extension/healthcheckextension/metadata.yaml b/extension/healthcheckextension/metadata.yaml index 4fb02d3ac677d..e56246c92c54f 100644 --- a/extension/healthcheckextension/metadata.yaml +++ b/extension/healthcheckextension/metadata.yaml @@ -10,6 +10,13 @@ status: active: [evan-bradley] seeking_new: true +feature_gates: + - id: extension.healthcheck.useComponentStatus + description: >- + Switch to the shared healthcheck implementation powered by component status events + stage: alpha + from_version: "v0.142.0" + reference_url: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/42256 tests: config: endpoint: localhost:0