harbor run -t wsauret/instance_flipt-io__flipt-2ca5dfb3513e4e786d2b037075617cccc286d5c3harbor download wsauret/instance_flipt-io__flipt-2ca5dfb3513e4e786d2b037075617cccc286d5c3A code repository is available in the /app directory. Your task is to implement the changes necessary to satisfy the following Pull Request (PR) description:
<pr_description>
Support multiple metrics exporters (Prometheus, OpenTelemetry)
Flipt currently exposes application metrics only through the Prometheus exporter provided by the OTel library. This creates a limitation for organizations that require flexibility to use other exporters with the OpenTelemetry stack (e.g., New Relic, Datadog). Depending solely on Prometheus can conflict with company policies that mandate vendor-free or multi-provider support.
metrics package eagerly creates a Prometheus exporter during package init(), which prevents a configurable exporter from being constructed later without duplicate-registration errors.metrics.exporter accepts prometheus (default) and otlp. When the key is absent from configuration, the loaded configuration must resolve to prometheus so existing deployments keep working unchanged.metrics configuration section is deserialized into a typed configuration structure exposing the enabled flag, the selected exporter, and an otlp sub-section holding the OTLP endpoint and headers.prometheus, it constructs the Prometheus exporter. Given otlp, it parses metrics.otlp.endpoint and builds an OTLP exporter, supporting endpoints written as http://..., https://..., grpc://..., or a plain host:port (no scheme), passing along the configured metrics.otlp.headers. Given any other exporter value, including an empty string, it returns the exact error unsupported metrics exporter: <value> (where <value> is the configured exporter value, which is empty when unset).sync.Once so the exporter is built only once per process; replacing that sync.Once with a fresh value allows a subsequent call to build a new exporter from a different configuration.The top-level configuration must expose a metrics section that deserializes from YAML into a dedicated metrics configuration structure.
The metrics configuration must support a boolean enabled key that enables or disables metrics export, deserializing correctly from YAML.
The metrics configuration must support a string exporter key whose valid values are prometheus and otlp, deserializing correctly from YAML.
The metrics configuration must support an otlp sub-section with a string endpoint key and an otlp.headers key (a string-to-string map of custom headers), both deserializing correctly from YAML.
The default configuration must set metrics enabled to true and exporter to prometheus. The Prometheus default for a missing metrics.exporter key is applied at the configuration-loading layer (the default configuration / the metrics config defaulter), which resolves the exporter value to Prometheus before the exporter-construction function is called, preserving backward compatibility.
An exported exporter-construction function must accept a context and a pointer to the metrics configuration and return the constructed metrics reader, a shutdown function of type func(context.Context) error, and an error. It must decide the exporter purely from the configuration's exporter value.
When the configured exporter is prometheus, the construction function must build and return a non-nil Prometheus reader and a non-nil shutdown function with no error.
When the configured exporter is otlp, the construction function must parse metrics.otlp.endpoint and build an OTLP exporter, returning a non-nil reader, a non-nil shutdown function, and no error for endpoints expressed as http://..., https://..., grpc://..., or a plain host:port with no scheme; the configured otlp.headers must be passed to the exporter.
When the configured exporter is any unrecognized value, including the empty string, the construction function must return an error whose message is exactly unsupported metrics exporter: <value>, where <value> is the configured exporter value (empty when unset, producing the message unsupported metrics exporter: with a trailing space and no value). The construction function itself must not treat an empty exporter value as Prometheus.
The construction function must guard its one-time initialization with a package-level variable named metricExpOnce of type sync.Once. Assigning a fresh sync.Once{} to metricExpOnce must allow a subsequent call to perform a new initialization with a different configuration.
The metrics package must not create a Prometheus exporter or register Prometheus collectors during init(), since doing so would cause the construction function to fail with duplicate-registration errors when called with a Prometheus configuration. If an initial meter provider is needed at package load time, a no-op provider must be used instead.
Path: internal/metrics/metrics.go
Name: GetExporter
Type: function
Input: ctx context.Context, cfg *config.MetricsConfig
Output: (sdkmetric.Reader, func(context.Context) error, error)
Description: Builds the metrics exporter once (guarded by the package-level metricExpOnce sync.Once) from the given metrics configuration, returning the reader and shutdown function for prometheus or otlp, or the error "unsupported metrics exporter: " for any other exporter value including empty.
Path: internal/config/metrics.go
Name: MetricsConfig
Type: struct
Input: deserialized metrics configuration with Enabled (bool), Exporter (MetricsExporter), and OTLP (OTLPMetricsConfig) fields
Output: a configuration value consumed by GetExporter and the config loader
Description: Configuration structure for the metrics section, holding the enabled flag, the selected exporter, and the nested OTLP configuration.
Path: internal/config/metrics.go
Name: OTLPMetricsConfig
Type: struct
Input: deserialized OTLP metrics settings with Endpoint (string) and Headers (map[string]string) fields
Output: the nested OTLP configuration carried by MetricsConfig
Description: Configuration structure for the metrics OTLP sub-section, holding the endpoint string and the custom headers map.
Path: internal/config/metrics.go
Name: MetricsExporter
Type: struct
Input: a string exporter identifier
Output: a typed exporter value exposing the MetricsPrometheus ("prometheus") and MetricsOTLP ("otlp") constants
Description: String-based type enumerating the supported metrics exporters. </pr_description>
Constraints: