Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/http_client_redirect_following.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added HTTP redirect following support to `prometheus_scrape` and `http_client` sources with configurable `follow_redirects` and `max_redirects` options. Prometheus defaults to following redirects; http_client defaults to not following. The timeout applies to the entire redirect chain, and 301/302/303 redirects automatically change non-HEAD requests to GET (per HTTP spec).

authors: XYenon
14 changes: 14 additions & 0 deletions src/sources/http_client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ pub struct HttpClientConfig {
#[serde(default)]
pub body: Option<ParameterValue>,

/// Whether to follow HTTP redirects.
#[serde(default)]
#[configurable(metadata(docs::advanced))]
pub follow_redirects: bool,

/// Maximum number of redirects to follow when enabled.
#[serde(default = "http_client::default_max_redirects")]
#[configurable(metadata(docs::advanced))]
pub max_redirects: usize,

/// TLS configuration.
#[configurable(derived)]
pub tls: Option<TlsConfig>,
Expand Down Expand Up @@ -224,6 +234,8 @@ impl Default for HttpClientConfig {
headers: HashMap::new(),
method: default_http_method(),
body: None,
follow_redirects: false,
max_redirects: http_client::default_max_redirects(),
tls: None,
auth: None,
log_namespace: None,
Expand Down Expand Up @@ -376,6 +388,8 @@ impl SourceConfig for HttpClientConfig {
interval: self.interval,
timeout: self.timeout,
headers: self.headers.clone(),
follow_redirects: self.follow_redirects,
max_redirects: self.max_redirects,
content_type,
auth: self.auth.clone(),
tls,
Expand Down
22 changes: 22 additions & 0 deletions src/sources/http_client/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ async fn invalid_endpoint() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -79,6 +81,8 @@ async fn collected_logs_bytes() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -105,6 +109,8 @@ async fn collected_logs_json() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -131,6 +137,8 @@ async fn collected_metrics_native_json() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -162,6 +170,8 @@ async fn collected_trace_native_json() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -188,6 +198,8 @@ async fn unauthorized_no_auth() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -211,6 +223,8 @@ async fn unauthorized_wrong_auth() {
user: "white_rabbit".to_string(),
password: "morpheus".to_string().into(),
}),
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -234,6 +248,8 @@ async fn authorized() {
user: "user".to_string(),
password: "pass".to_string().into(),
}),
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -257,6 +273,8 @@ async fn tls_invalid_ca() {
..Default::default()
}),
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -280,6 +298,8 @@ async fn tls_valid() {
..Default::default()
}),
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand All @@ -301,6 +321,8 @@ async fn shutdown() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
};

Expand Down
28 changes: 28 additions & 0 deletions src/sources/http_client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ async fn bytes_decoding() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -132,6 +134,8 @@ async fn json_decoding_newline_delimited() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -167,6 +171,8 @@ async fn json_decoding_character_delimited() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -208,6 +214,8 @@ async fn request_query_applied() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -320,6 +328,8 @@ async fn request_query_vrl_applied() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -402,6 +412,8 @@ async fn request_query_vrl_dynamic_updates() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -470,6 +482,8 @@ async fn headers_applied() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -500,6 +514,8 @@ async fn accept_header_override() {
body: None,
auth: None,
tls: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -537,6 +553,8 @@ async fn post_with_body() {
body: Some(ParameterValue::String(test_json.to_string())),
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -578,6 +596,8 @@ async fn post_without_body() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -608,6 +628,8 @@ async fn post_with_custom_content_type() {
body: Some(ParameterValue::String("plain text body".to_string())),
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -645,6 +667,8 @@ async fn post_with_vrl_body() {
}),
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
})
.await;
Expand Down Expand Up @@ -686,6 +710,8 @@ async fn query_vrl_compilation_error() {
body: None,
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
};

Expand Down Expand Up @@ -729,6 +755,8 @@ async fn body_vrl_compilation_error() {
}),
tls: None,
auth: None,
follow_redirects: false,
max_redirects: 5,
log_namespace: None,
};

Expand Down
Loading
Loading