Repository navigation
[otel] Share OTLP exporter config between metrics surfacer and tracing - #1496
Merged
Merged
Conversation
The OTLP exporter messages were defined twice, field for field: once in internal/surfacers/otel/proto and once in internal/tracing/proto (added by #1358). Move Compression, HTTPExporter and GRPCExporter to a new shared internal/otel/proto, and have both configs import them. Existing textproto configs are unaffected: textproto doesn't encode nested message type names, only field names. Go callers building configs programmatically are unaffected too. internal/surfacers/otel/proto keeps compatibility aliases under the old names, so the generated pkg/protos/surfacers facade still exports OtelHTTPExporter, OtelGRPCExporter, OtelCompression and the Compression constants exactly as before. Keeping OtelCompression needed a genprotofacade fix: under gotypesalias=1 an alias to an enum is a *types.Alias, not a *types.Named, so isEnum() skipped it and the symbol silently dropped out of the facade. Unwrap with types.Unalias. The getExporter option plumbing was duplicated as well, and the copies had drifted. The signal-specific SDK option types can't be shared, but the config interpretation can, so validation and tls.Config construction now live in internal/otel. That closes three divergences: - The surfacer hand-parsed endpoint_url; it now uses WithEndpointURL, like tracing. WithEndpointURL only logs a parse failure and falls back to the default endpoint, so the surfacer's invalid-URL error is preserved in the shared helper -- and tracing gains it. - insecure + tls_config is now rejected by the surfacer, not just by tracing. - Both use tlsconfig.FromProto instead of allocating a tls.Config and calling UpdateTLSConfig on it.
The endpoint_url check only looked at url.Parse's error, but url.Parse is scheme-blind and accepts the most likely misconfiguration: a schemeless "otel.example.com:4318" -- the shape otlp_grpc_exporter's endpoint takes -- parses as scheme "otel.example.com" with an empty host. WithEndpointURL would then derive Endpoint="" and Insecure=true from it, so the exporter built fine and every export failed against an empty host. That's the silent misdirection the check was meant to prevent, so require an http or https scheme and a non-empty host.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The OTLP exporter messages were defined twice, field for field: once in
internal/surfacers/otel/protoand once ininternal/tracing/proto(added by #1358). Both definedCompression,HTTPExporterandGRPCExporteridentically. This moves them to a sharedinternal/otel/proto, which both configs now import.SurfacerConfandTracingConfigstay where they are.Compatibility
Textproto configs are unaffected — textproto doesn't encode nested message type names, only field names. Verified by parsing a config with both an
otel_surfacerand atracingblock against the new protos.Go callers building configs programmatically are unaffected.
internal/surfacers/otel/protokeeps compatibility aliases under the old names, so the generatedpkg/protos/surfacersfacade still exportsOtelHTTPExporter,OtelGRPCExporter,OtelCompressionand theCompressionconstants exactly as before. The only facade diff in this PR isPrometheusDefault_SurfacerConf_StaleMetricsExpirationSec, which the regeneration picked up — the checked-in facade was stale.Keeping
OtelCompressionneeded agenprotofacadefix: undergotypesalias=1an alias to an enum is a*types.Alias, not a*types.Named, soisEnum()skipped it and the symbol silently dropped out of the facade. Unwrapped withtypes.Unalias, with a regression test covering a package of aliases.Go side
The
getExporteroption plumbing was duplicated too, and the copies had drifted. The signal-specific SDK option types (otlpmetrichttp.Optionvsotlptracehttp.Option) can't be shared, but the config interpretation can, so validation andtls.Configconstruction now live ininternal/otel. EachgetExporterkeeps its own explicit option list. This closes three divergences:endpoint_urlinto host/port/path; it now usesWithEndpointURL, like tracing.WithEndpointURLonly logs a parse failure and then falls back to the default endpoint, so the surfacer's invalid-URL startup error is preserved in the shared helper — and tracing gains it.insecure+tls_configtogether is now rejected by the surfacer, not just by tracing. See the behavior-change note below.tlsconfig.FromProtoinstead of allocating atls.Configand callingUpdateTLSConfigon it.Net: ~560 lines of duplicated generated code removed. Tests added on both sides for the endpoint-URL and insecure/TLS paths.
Rejecting
insecure+tls_configis a startup-breaking change for existing metrics-surfacer configs. Before this PR:started fine —
WithInsecure()setInsecure=trueandWithTLSCredentialssetGRPCCredentials, andoconf.NewGRPCConfigprioritizes credentials over insecure ("passing both is an error", per the SDK's own comment), so TLS silently won. After this PR the same config makes cloudprober fail to boot.The old behavior was ambiguous and the SDK itself calls it an error, so failing loudly seems right — and it matches what tracing already does since #1358. But it turns a working deployment into a boot failure on upgrade, so it should be called out in the release notes. Happy to make the surfacer lenient instead (warn and let TLS win) if we'd rather not break anyone.
Second commit
c768e2btightens theendpoint_urlvalidation.url.Parseis scheme-blind, so a schemelessotel.example.com:4318— the shapeotlp_grpc_exporter'sendpointtakes, an easy mix-up — parsed as schemeotel.example.comwith an empty host and passed the check.WithEndpointURLthen derivedEndpoint=""andInsecure=true, so the exporter built successfully and every export failed against an empty host. Now anhttp/httpsscheme and a non-empty host are required.