Skip to content

Commit bea14d5

Browse files
committed
checkpoint
Signed-off-by: Brian L. Troutwine <[email protected]>
1 parent ca1be5f commit bea14d5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

lading/src/generator/splunk_hec.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ use http::{
2424
header::{AUTHORIZATION, CONTENT_LENGTH},
2525
Method, Request, Uri,
2626
};
27-
use hyper_util::client::legacy::{Client, ClientBuilder, HttpConnector};
27+
use http_body_util::BodyExt;
28+
use hyper::body::Body;
29+
use hyper_util::{
30+
client::legacy::{connect::HttpConnector, Client},
31+
rt::TokioExecutor,
32+
};
2833
use lading_throttle::Throttle;
2934
use metrics::{counter, gauge};
3035
use once_cell::sync::OnceCell;
@@ -248,7 +253,7 @@ impl SplunkHec {
248253
/// Function will panic if it is unable to create HTTP requests for the
249254
/// target.
250255
pub async fn spin(mut self) -> Result<(), Error> {
251-
let client: Client<HttpConnector, Body> = Client::builder()
256+
let client = Client::builder(TokioExecutor::new())
252257
.pool_max_idle_per_host(self.parallel_connections as usize)
253258
.retry_canceled_requests(false)
254259
.build_http();
@@ -283,10 +288,10 @@ impl SplunkHec {
283288
let uri = uri.clone();
284289

285290
let blk = rcv.next().await.expect("failed to advance through blocks"); // actually advance through the blocks
286-
let body = Body::from(blk.bytes.clone());
291+
let body = crate::full(blk.bytes.clone());
287292
let block_length = blk.bytes.len();
288293

289-
let request: Request<Body> = Request::builder()
294+
let request = Request::builder()
290295
.method(Method::POST)
291296
.uri(uri)
292297
.header(AUTHORIZATION, format!("Splunk {}", self.token))
@@ -317,15 +322,20 @@ impl SplunkHec {
317322
}
318323
}
319324

320-
async fn send_hec_request(
325+
async fn send_hec_request<B>(
321326
permit: SemaphorePermit<'_>,
322327
block_length: usize,
323328
labels: Vec<(String, String)>,
324329
channel: Channel,
325-
client: Client<HttpConnector>,
326-
request: Request<Body>,
330+
client: Client<HttpConnector, B>,
331+
request: Request<B>,
327332
shutdown: lading_signal::Watcher,
328-
) -> Result<(), Error> {
333+
) -> Result<(), Error>
334+
where
335+
B: Body + Send + 'static + Unpin,
336+
B::Data: Send,
337+
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
338+
{
329339
counter!("requests_sent", &labels).increment(1);
330340
let work = client.request(request);
331341

@@ -340,7 +350,7 @@ async fn send_hec_request(
340350
let mut status_labels = labels.clone();
341351
status_labels.push(("status_code".to_string(), status.as_u16().to_string()));
342352
counter!("request_ok", &status_labels).increment(1);
343-
let body_bytes = body.collect().await?.to_bytes();
353+
let body_bytes = body.boxed().collect().await?.to_bytes();
344354
let hec_ack_response =
345355
serde_json::from_slice::<HecAckResponse>(&body_bytes).expect("unable to parse response body");
346356
channel.send(ready(hec_ack_response.ack_id)).await?;

0 commit comments

Comments
 (0)