Skip to content

Commit 10fef82

Browse files
committed
Touch ups
1 parent 5dc4921 commit 10fef82

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

src/sinks/http/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(super) struct HttpEncoder {
1818
}
1919

2020
impl HttpEncoder {
21+
/// Creates a new `HttpEncoder`.
2122
pub(super) const fn new(encoder: Encoder<Framer>, transformer: Transformer) -> Self {
2223
Self {
2324
encoder,

src/sinks/http/request_builder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! `RequestBuilder` implementation for the `http` sink.
22
3-
use std::io;
4-
53
use bytes::Bytes;
4+
use std::io;
65

76
use crate::sinks::{prelude::*, util::http_service::HttpRequest};
87

src/sinks/util/http_service/request.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct HttpRequest {
1414
}
1515

1616
impl HttpRequest {
17+
/// Creates a new `HttpRequest`.
1718
pub fn new(
1819
payload: Bytes,
1920
finalizers: EventFinalizers,

src/sinks/util/http_service/retry.rs

+36
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,39 @@ impl RetryLogic for HttpRetryLogic {
3636
}
3737
}
3838
}
39+
40+
#[cfg(test)]
41+
mod tests {
42+
use bytes::Bytes;
43+
use hyper::Response;
44+
use vector_common::request_metadata::GroupedCountByteSize;
45+
46+
use super::{HttpResponse, HttpRetryLogic};
47+
use crate::sinks::util::retries::RetryLogic;
48+
49+
#[test]
50+
fn validate_retry_logic() {
51+
let logic = HttpRetryLogic;
52+
53+
fn generate_response(code: u16) -> HttpResponse {
54+
HttpResponse {
55+
http_response: Response::builder().status(code).body(Bytes::new()).unwrap(),
56+
events_byte_size: GroupedCountByteSize::new_untagged(),
57+
raw_byte_size: 0,
58+
}
59+
}
60+
61+
assert!(logic
62+
.should_retry_response(&generate_response(429))
63+
.is_retryable());
64+
assert!(logic
65+
.should_retry_response(&generate_response(500))
66+
.is_retryable());
67+
assert!(logic
68+
.should_retry_response(&generate_response(400))
69+
.is_not_retryable());
70+
assert!(logic
71+
.should_retry_response(&generate_response(501))
72+
.is_not_retryable());
73+
}
74+
}

src/sinks/util/http_service/service.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use super::request::HttpRequest;
1212
/// Response type for use in the `Service` implementation of HTTP stream sinks.
1313
pub struct HttpResponse {
1414
pub(super) http_response: Response<Bytes>,
15-
events_byte_size: GroupedCountByteSize,
16-
raw_byte_size: usize,
15+
pub(super) events_byte_size: GroupedCountByteSize,
16+
pub(super) raw_byte_size: usize,
1717
}
1818

1919
impl DriverResponse for HttpResponse {
@@ -34,14 +34,18 @@ impl DriverResponse for HttpResponse {
3434
}
3535
}
3636

37+
/// Build HTTP requests for the `HttpService`.
3738
///
39+
/// This trait exists to allow HTTP based stream sinks to utilize the common `HttpService`
40+
/// while being able to define sink-specific HTTP requests.
3841
pub trait HttpServiceRequestBuilder {
39-
/// B
4042
fn build(&self, body: BytesMut) -> Request<Bytes>;
4143
}
4244

4345
/// `Service` implementation of HTTP stream sinks.
4446
///
47+
/// `http_request_builder` <R> must implement the `HttpServiceRequestBuilder` trait, which is
48+
/// used in the `Service::call()` function to handle sink-specific HTTP request building.
4549
#[derive(Debug, Clone)]
4650
pub struct HttpService<R> {
4751
http_request_builder: R,
@@ -50,6 +54,7 @@ pub struct HttpService<R> {
5054
}
5155

5256
impl<R> HttpService<R> {
57+
/// Creates a new `HttpService`.
5358
pub const fn new(http_request_builder: R, client: HttpClient, protocol: String) -> Self {
5459
Self {
5560
http_request_builder,

0 commit comments

Comments
 (0)