Skip to content

Conversation

@XYenon
Copy link

@XYenon XYenon commented Jan 29, 2026

Summary

Add HTTP redirect following support to prometheus_scrape and http_client sources with configurable follow_redirects and max_redirects options.

  • prometheus_scrape: follow_redirects defaults to true (matches Prometheus behavior)
  • http_client: follow_redirects defaults to false (preserves original behavior)

Redirect behavior follows HTTP spec:

  • 301/302/303 redirects change non-HEAD requests to GET
  • 307/308 redirects preserve method and body
  • Timeout applies to entire redirect chain
  • Metrics use original request URL to avoid cardinality explosion

Vector configuration

[sources.prometheus]
type = "prometheus_scrape"
endpoints = ["http://localhost:9090/metrics"]
follow_redirects = true   # default
max_redirects = 5         # default

[sources.http]
type = "http_client"
endpoint = "http://localhost:8080/api"
follow_redirects = false  # default
max_redirects = 5         # default

How did you test this PR?

  • Added test_prometheus_follows_redirects unit test that verifies redirect following works and metrics use original URL
  • Updated all existing tests with new config fields

Change Type

  • Bug fix
  • New feature
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details here.

- Add follow_redirects (default: true) and max_redirects (default: 5) config options
- Timeout applies to entire redirect chain, not per-request
- 301/302/303 redirects switch to GET for non-HEAD requests (per HTTP spec)
- 307/308 redirects preserve method and body
- Use original request URL for metrics to avoid cardinality explosion
- Add PartialEq/Eq derives to HttpMethod for redirect handling
- Add test for redirect following behavior

Co-authored-by: Amp <amp@ampcode.com>
@github-actions github-actions bot added domain: sources Anything related to the Vector's sources domain: external docs Anything related to Vector's external, public documentation labels Jan 29, 2026
@github-actions
Copy link

github-actions bot commented Jan 29, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@XYenon
Copy link
Author

XYenon commented Jan 29, 2026

I have read the CLA Document and I hereby sign the CLA

@XYenon XYenon marked this pull request as ready for review January 29, 2026 12:17
@XYenon XYenon requested review from a team as code owners January 29, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: external docs Anything related to Vector's external, public documentation domain: sources Anything related to the Vector's sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prometheus_scrape cannot follow HTTP redirects

2 participants