Skip to content

config: change NewOAuth2RoundTripper to accept variadic HTTPClientOption#898

Merged
roidelapluie merged 1 commit intoprometheus:mainfrom
alliasgher:fix/NewOAuth2RoundTripper-exported-options
Apr 15, 2026
Merged

config: change NewOAuth2RoundTripper to accept variadic HTTPClientOption#898
roidelapluie merged 1 commit intoprometheus:mainfrom
alliasgher:fix/NewOAuth2RoundTripper-exported-options

Conversation

@alliasgher
Copy link
Copy Markdown

Summary

NewOAuth2RoundTripper previously accepted *httpClientOptions as its fourth
parameter — an unexported type. This made the function effectively
uncallable with a non-nil options argument from any package outside
prometheus/common/config, forcing downstream users (e.g. Grafana Alloy) to
resort to reflection or unsafe pointer tricks.

Reported upstream in prometheus/prometheus#18329.

Change

Replace the unexported *httpClientOptions parameter with variadic
...HTTPClientOption — the exported interface already used by
NewRoundTripperFromConfigWithContext:

// Before (unusable externally with non-nil opts):
func NewOAuth2RoundTripper(cred SecretReader, cfg *OAuth2, next http.RoundTripper, opts *httpClientOptions) http.RoundTripper

// After (fully usable from any package):
func NewOAuth2RoundTripper(cred SecretReader, cfg *OAuth2, next http.RoundTripper, optFuncs ...HTTPClientOption) http.RoundTripper

Internally the function builds its own httpClientOptions copy from the supplied options starting from defaultHTTPClientOptions, so behaviour is identical to before when no options are passed.

Call sites updated

  • Internal call in NewRoundTripperFromConfigWithContext: passes optFuncs... instead of &opts
  • Three test call sites that passed &defaultHTTPClientOptions now pass no options (equivalent — defaults are unchanged)

Tests

go test ./config/...   # all pass

The fourth parameter was *httpClientOptions, an unexported type, making
NewOAuth2RoundTripper effectively uncallable with a non-nil options
argument from any package outside prometheus/common/config. Callers were
forced to resort to reflection or unsafe pointer tricks.

Change the signature to accept variadic ...HTTPClientOption — the
existing exported interface — matching the pattern already used by
NewRoundTripperFromConfigWithContext. The function builds its own
httpClientOptions copy from the supplied options, starting from
defaultHTTPClientOptions.

The single internal call site is updated to pass optFuncs... instead of
&opts; tests that passed &defaultHTTPClientOptions now pass no options
(equivalent behaviour, defaultHTTPClientOptions is the zero value).

Fixes prometheus/prometheus#18329

Signed-off-by: Ali <alliasgher123@gmail.com>
@roidelapluie
Copy link
Copy Markdown
Member

Thanks!

@roidelapluie roidelapluie merged commit 9e28363 into prometheus:main Apr 15, 2026
8 checks passed
korniltsev-grafanista-yolo-vibecoder239 added a commit to korniltsev-grafanista-yolo-vibecoder239/alloy that referenced this pull request Apr 15, 2026
…ripper

prometheus/common#898 changed NewOAuth2RoundTripper to accept variadic
HTTPClientOption instead of the unexported *httpClientOptions, making
the reflection+unsafe workaround unnecessary.

Bump prometheus/common to include the fix and call the upstream function
directly, converting local options via a new toUpstreamOpts helper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants