Skip to content

Commit

Permalink
feat: if HTTP get the BackendError of the response, return BackendErr…
Browse files Browse the repository at this point in the history
…or to proxy (#624)

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Jul 24, 2024
1 parent 1640bac commit d97c017
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 165 deletions.
2 changes: 1 addition & 1 deletion dragonfly-client-config/src/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn default_download_rate_limit() -> ByteSize {
// default_download_piece_timeout is the default timeout for downloading a piece from source.
#[inline]
fn default_download_piece_timeout() -> Duration {
Duration::from_secs(180)
Duration::from_secs(60)
}

// default_download_concurrent_piece_count is the default number of concurrent pieces to download.
Expand Down
67 changes: 61 additions & 6 deletions dragonfly-client/src/grpc/dfdaemon_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
json.into(),
));
}
Err(e) => {
error!("serialize error: {}", e);
return Err(Status::internal(e.to_string()));
Err(err) => {
error!("serialize error: {}", err);
return Err(Status::internal(err.to_string()));
}
}
}
Expand Down Expand Up @@ -405,13 +405,57 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
};
}
}
Err(e) => {
// Download task failed.
Err(ClientError::BackendError(err)) => {
// Collect download task failure metrics.
collect_download_task_failure_metrics(
download_clone.r#type,
download_clone.tag.clone().unwrap_or_default().as_str(),
download_clone
.application
.clone()
.unwrap_or_default()
.as_str(),
download_clone.priority.to_string().as_str(),
);

task_manager_clone
.download_failed(task_clone.id.as_str())
.await
.unwrap_or_else(|err| error!("download task failed: {}", err));

match serde_json::to_vec::<Backend>(&Backend {
message: err.message.clone(),
header: reqwest_headermap_to_hashmap(
&err.header.clone().unwrap_or_default(),
),
status_code: err.status_code.map(|code| code.as_u16() as i32),
}) {
Ok(json) => {
out_stream_tx
.send(Err(Status::with_details(
Code::Internal,
err.to_string(),
json.into(),
)))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
}
Err(err) => {
out_stream_tx
.send(Err(Status::internal(err.to_string())))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
error!("serialize error: {}", err);
}
}
}
Err(err) => {
error!("download failed: {}", err);

// Collect download task failure metrics.
collect_download_task_failure_metrics(
download_clone.r#type,
Expand All @@ -424,7 +468,18 @@ impl DfdaemonDownload for DfdaemonDownloadServerHandler {
download_clone.priority.to_string().as_str(),
);

error!("download failed: {}", e);
// Download task failed.
task_manager_clone
.download_failed(task_clone.id.as_str())
.await
.unwrap_or_else(|err| error!("download task failed: {}", err));

out_stream_tx
.send(Err(Status::internal(err.to_string())))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
}
}

Expand Down
63 changes: 60 additions & 3 deletions dragonfly-client/src/grpc/dfdaemon_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,59 @@ impl DfdaemonUpload for DfdaemonUploadServerHandler {
};
}
}
Err(err) => {
// Download task failed.
Err(ClientError::BackendError(err)) => {
error!("download failed by error: {}", err);

// Collect download task failure metrics.
collect_download_task_failure_metrics(
download_clone.r#type,
download_clone.tag.clone().unwrap_or_default().as_str(),
download_clone
.application
.clone()
.unwrap_or_default()
.as_str(),
download_clone.priority.to_string().as_str(),
);

task_manager_clone
.download_failed(task_clone.id.as_str())
.await
.unwrap_or_else(|err| error!("download task failed: {}", err));

match serde_json::to_vec::<Backend>(&Backend {
message: err.message.clone(),
header: reqwest_headermap_to_hashmap(
&err.header.clone().unwrap_or_default(),
),
status_code: err.status_code.map(|code| code.as_u16() as i32),
}) {
Ok(json) => {
out_stream_tx
.send(Err(Status::with_details(
Code::Internal,
err.to_string(),
json.into(),
)))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
}
Err(err) => {
out_stream_tx
.send(Err(Status::internal(err.to_string())))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
error!("serialize error: {}", err);
}
}
}
Err(err) => {
error!("download failed: {}", err);

// Collect download task failure metrics.
collect_download_task_failure_metrics(
download_clone.r#type,
Expand All @@ -409,7 +455,18 @@ impl DfdaemonUpload for DfdaemonUploadServerHandler {
download_clone.priority.to_string().as_str(),
);

error!("download failed: {}", err);
// Download task failed.
task_manager_clone
.download_failed(task_clone.id.as_str())
.await
.unwrap_or_else(|err| error!("download task failed: {}", err));

out_stream_tx
.send(Err(Status::internal(err.to_string())))
.await
.unwrap_or_else(|err| {
error!("send download progress error: {:?}", err)
});
}
}

Expand Down
Loading

0 comments on commit d97c017

Please sign in to comment.