|
16 | 16 |
|
17 | 17 | mod acknowledgements;
|
18 | 18 |
|
19 |
| -use std::{num::NonZeroU32, thread, time::Duration}; |
| 19 | +use std::{future::ready, num::NonZeroU32, thread, time::Duration}; |
20 | 20 |
|
21 | 21 | use acknowledgements::Channels;
|
22 | 22 | use byte_unit::ByteError;
|
23 | 23 | use http::{
|
24 | 24 | header::{AUTHORIZATION, CONTENT_LENGTH},
|
25 | 25 | Method, Request, Uri,
|
26 | 26 | };
|
27 |
| -use hyper::{client::HttpConnector, Body, Client}; |
| 27 | +use hyper::{body::HttpBody, client::HttpConnector, Body, Client}; |
28 | 28 | use lading_throttle::Throttle;
|
29 | 29 | use metrics::{counter, gauge};
|
30 | 30 | use once_cell::sync::OnceCell;
|
@@ -120,6 +120,9 @@ pub enum Error {
|
120 | 120 | /// Wrapper around [`acknowledgements::Error`]
|
121 | 121 | #[error(transparent)]
|
122 | 122 | Acknowledge(#[from] acknowledgements::Error),
|
| 123 | + /// Wrapper around [`hyper::Error`]. |
| 124 | + #[error("HTTP error: {0}")] |
| 125 | + Hyper(#[from] hyper::Error), |
123 | 126 | }
|
124 | 127 |
|
125 | 128 | /// Defines a task that emits variant lines to a Splunk HEC server controlling
|
@@ -337,14 +340,10 @@ async fn send_hec_request(
|
337 | 340 | let mut status_labels = labels.clone();
|
338 | 341 | status_labels.push(("status_code".to_string(), status.as_u16().to_string()));
|
339 | 342 | counter!("request_ok", &status_labels).increment(1);
|
340 |
| - channel |
341 |
| - .send(async { |
342 |
| - let body_bytes = hyper::body::to_bytes(body).await.expect("unable to convert response body to bytes"); |
343 |
| - let hec_ack_response = |
344 |
| - serde_json::from_slice::<HecAckResponse>(&body_bytes).expect("unable to parse response body"); |
345 |
| - hec_ack_response.ack_id |
346 |
| - }) |
347 |
| - .await?; |
| 343 | + let body_bytes = body.collect().await?.to_bytes(); |
| 344 | + let hec_ack_response = |
| 345 | + serde_json::from_slice::<HecAckResponse>(&body_bytes).expect("unable to parse response body"); |
| 346 | + channel.send(ready(hec_ack_response.ack_id)).await?; |
348 | 347 | }
|
349 | 348 | Err(err) => {
|
350 | 349 | let mut error_labels = labels.clone();
|
|
0 commit comments