opentelemetry-collector icon indicating copy to clipboard operation
opentelemetry-collector copied to clipboard

New Defaulter interface for components configuration

Open yann-soubeyrand opened this issue 1 month ago • 9 comments

Component(s)

No response

Is your feature request related to a problem? Please describe.

When integrating a new OpenTelemetry Collector component to Grafana Alloy, one need to convert the Alloy configuration for this component to its OpenTelemetry Collector component counterpart (for example https://github.com/camptocamp/alloy/blob/01cb0c8a058dd7de961d72819848f91174dd57cb/internal/component/otelcol/connector/count/connector.go#L82-L176). It’s frustrating to have to reimplement the logic to set some defaults in the configuration which is done in the Unmarshal() method of the OpenTelemetry Collector component configuration type (for example https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/88441c5b3f16fb5d3a08d1ce6f3df94129f27872/connector/countconnector/config.go#L150-L177).

Describe the solution you'd like

Instead of setting the defaults in the Unmarshal() method, could we define an additional interface (let’s call it Defaulter for example) that the configuration type could implement, and which would be called after the unmarshaling of the configuration? This way, one could reuse the method of this interface (let’s call it SetDefaults() for example) in the conversion logic of the Alloy code.

Describe alternatives you've considered

Currently, one has to duplicate the logic to set the defaults and keep it in sync.

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

yann-soubeyrand avatar Oct 14 '25 13:10 yann-soubeyrand