config: apply DialContextFunc to OAuth2 token-fetch transport (#911)

newOauth2TokenSource builds its own http.Transport to fetch tokens but
doesn't set DialContext on it. Any DialContextFunc passed via
WithDialContextFunc is applied to the main request transport but silently
skipped for the token endpoint.

Set DialContext on the token transport the same way it is set on the main
one. When dialContextFunc is nil the behaviour is unchanged since
http.Transport falls back to its default dialer.

Added TestOAuth2DialContextFunc to verify that WithDialContextFunc blocks
the token endpoint fetch, not only the final request.

Signed-off-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
2 files changed
tree: 9b6a1dc2720000fe322f205e0089944bf7d82a24
  1. .github/
  2. assets/
  3. config/
  4. expfmt/
  5. helpers/
  6. model/
  7. promslog/
  8. route/
  9. scripts/
  10. server/
  11. version/
  12. .gitignore
  13. .golangci.yml
  14. .yamllint
  15. CHANGELOG.md
  16. CODE_OF_CONDUCT.md
  17. CONTRIBUTING.md
  18. go.mod
  19. go.sum
  20. LICENSE
  21. MAINTAINERS.md
  22. Makefile
  23. Makefile.common
  24. NOTICE
  25. README.md
  26. RELEASE.md
  27. SECURITY.md
README.md

Common

circleci OpenSSF Scorecard

This repository contains Go libraries that are shared across Prometheus components and libraries. They are considered internal to Prometheus, without any stability guarantees for external usage.

  • assets: Embedding of static assets with gzip support
  • config: Common configuration structures
  • expfmt: Decoding and encoding for the exposition format
  • model: Shared data structures
  • promslog: A logging wrapper around log/slog
  • route: A routing wrapper around httprouter using context.Context
  • server: Common servers
  • version: Version information and metrics