Skip to content

Commit 1b08122

Browse files
committed
refactor(app/integration): forward-compatible test code
see linkerd/linkerd2#8733 for more information. see #3559 and #3614 for more information on the `ForwardCompatibleBody<B>` wrapper. `telemetry::log_stream::collect_logs` is a function responsible for digesting a streaming body, and deserializing each chunk into a `serde_json::Value`, until either (a) a shutdown signal is received, or (b) the end of the body is reached. this commit updates test code in `linkerd-app-integration` so that it interacts with request and response bodies via an adapter that polls for frames in a manner consistent with the 1.0 api of `http_body`. this allows us to limit the diff in #3504, which will only need to remove this adapter once using hyper 1.0. * linkerd/linkerd2#8733 * #3671 * #3672 * #3673 * #3676 Signed-off-by: katelyn martin <[email protected]>
1 parent 4e3119c commit 1b08122

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

linkerd/app/integration/src/tests/telemetry/log_stream.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,26 @@ async fn query_log_stream(
210210

211211
/// Spawns a task to collect all the logs in a streaming body and parse them as
212212
/// JSON.
213-
fn collect_logs(
214-
mut body: hyper::Body,
215-
) -> (JoinHandle<Vec<serde_json::Value>>, oneshot::Sender<()>) {
213+
fn collect_logs<B>(body: B) -> (JoinHandle<Vec<serde_json::Value>>, oneshot::Sender<()>)
214+
where
215+
B: Body<Data = Bytes> + Send + Unpin + 'static,
216+
B::Error: std::error::Error,
217+
{
218+
let mut body = linkerd_http_body_compat::ForwardCompatibleBody::new(body);
216219
let (done_tx, done_rx) = oneshot::channel();
217220
let result = tokio::spawn(async move {
218221
let mut result = Vec::new();
219222
let logs = &mut result;
220223
let fut = async move {
221-
while let Some(res) = body.data().await {
224+
while let Some(res) = body.frame().await {
222225
let chunk = match res {
223-
Ok(chunk) => chunk,
226+
Ok(frame) => {
227+
if let Ok(data) = frame.into_data() {
228+
data
229+
} else {
230+
break;
231+
}
232+
}
224233
Err(e) => {
225234
println!("body failed: {}", e);
226235
break;

0 commit comments

Comments
 (0)