Skip to content

feat(stdlib): add http_request function #1360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

benjamin-awd
Copy link

@benjamin-awd benjamin-awd commented Mar 27, 2025

Summary

This PR adds a HTTP request function, allowing users to fetch data from external sources.

Change Type

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

Is this a breaking change?

  • Yes
  • No

How did you test this PR?

Added tests, otherwise currently running this in a Kubernetes environment via Helm.

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. (not sure if we want to document this or not, if we follow the example of dns_lookup)

Checklist

  • Our CONTRIBUTING.md is a good starting place.
  • If this PR introduces changes to LICENSE-3rdparty.csv, please
    run dd-rust-license-tool write and commit the changes. More details here.
  • For new VRL functions, please also create a sibling PR in Vector to document the new function.

References

Closes #1359

Comment on lines +688 to +699
bench_function! {
http_request => vrl::stdlib::HttpRequest;

http_request {
args: func_args![
url: value!("https://httpbin.org/bearer"),
headers: value!({"accept": "application/json", "Authorization": "Bearer my_token"})
],
want: Ok(r#"{"authenticated": true, "token": "my_token"}"#),
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this benchmark since making network calls like this isn't very reliable, running this specific benchmark gives back:

Benchmarking vrl_stdlib/functions/http_request/http_request: Warming up for 3.0000 s
Warning: Unable to complete 100 samples in 5.0s. You may wish to increase target time to 154.0s, or reduce sample count to 10.
Benchmarking vrl_stdlib/functions/http_request/http_request: Collecting 100 samples in estimated 154.03 s (100 iterations)

vrl_stdlib/functions/http_request/http_request
                        time:   [1.4146 s 1.5196 s 1.6320 s]
                        thrpt:  [0.6128  elem/s 0.6581  elem/s 0.7069  elem/s]
Found 9 outliers among 100 measurements (9.00%)
  8 (8.00%) high mild
  1 (1.00%) high severe

Maybe something with warp would be more useful

Comment on lines +166 to +168
// Create a new Tokio runtime as a fallback
let runtime = Runtime::new().expect("Failed to create Tokio runtime");
runtime.block_on(async { http_request(&url, &method, headers).await })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to allow the bench function to run -- AFAICT it isn't needed apart from that since the Vector runtime can be accessed with Handle::current()

@pront pront self-assigned this Mar 28, 2025
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.

Add http_get function to VRL
2 participants