Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for upload speed / remaining in the cache upload step #8081

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 57 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/turborepo-api-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ workspace = true

[dependencies]
anyhow = { workspace = true }
bytes.workspace = true
chrono = { workspace = true, features = ["serde"] }
lazy_static = { workspace = true }
regex = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
reqwest = { workspace = true, features = ["json", "stream"] }
rustc_version_runtime = "0.2.1"
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tokio-stream = "0.1.15"
tokio-util = { version = "0.7.10", features = ["codec"] }
tracing = { workspace = true }
turbopath = { workspace = true }
turborepo-ci = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/turborepo-api-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::CachingStatus;

#[derive(Debug, Error)]
pub enum Error {
#[error("Error reading from disk: {0}")]
ReadError(#[from] std::io::Error),
#[error("Error making HTTP request: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("skipping HTTP Request, too many failures have occurred.\nLast error: {0}")]
Expand Down
13 changes: 9 additions & 4 deletions crates/turborepo-api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{backtrace::Backtrace, env, future::Future, time::Duration};
use lazy_static::lazy_static;
use regex::Regex;
pub use reqwest::Response;
use reqwest::{Method, RequestBuilder, StatusCode};
use reqwest::{Body, Method, RequestBuilder, StatusCode};
use serde::Deserialize;
use turborepo_ci::{is_ci, Vendor};
use turborepo_vercel_api::{
Expand All @@ -26,6 +26,9 @@ mod retry;
pub mod spaces;
pub mod telemetry;

pub use bytes::Bytes;
pub use tokio_stream::Stream;

lazy_static! {
static ref AUTHORIZATION_REGEX: Regex =
Regex::new(r"(?i)(?:^|,) *authorization *(?:,|$)").unwrap();
Expand Down Expand Up @@ -74,7 +77,7 @@ pub trait CacheClient {
fn put_artifact(
&self,
hash: &str,
artifact_body: &[u8],
artifact_body: impl tokio_stream::Stream<Item = Result<bytes::Bytes>> + Send + Sync + 'static,
duration: u64,
tag: Option<&str>,
token: &str,
Expand Down Expand Up @@ -358,7 +361,7 @@ impl CacheClient for APIClient {
async fn put_artifact(
&self,
hash: &str,
artifact_body: &[u8],
artifact_body: impl tokio_stream::Stream<Item = Result<bytes::Bytes>> + Send + Sync + 'static,
duration: u64,
tag: Option<&str>,
token: &str,
Expand All @@ -382,13 +385,15 @@ impl CacheClient for APIClient {
request_url = preflight_response.location.clone();
}

let stream = Body::wrap_stream(artifact_body);

let mut request_builder = self
.cache_client
.put(request_url)
.header("Content-Type", "application/octet-stream")
.header("x-artifact-duration", duration.to_string())
.header("User-Agent", self.user_agent.clone())
.body(artifact_body.to_vec());
.body(stream);

if allow_auth {
request_builder = request_builder.header("Authorization", format!("Bearer {}", token));
Expand Down
6 changes: 5 additions & 1 deletion crates/turborepo-auth/src/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ mod tests {
async fn put_artifact(
&self,
_hash: &str,
_artifact_body: &[u8],
_artifact_body: impl turborepo_api_client::Stream<
Item = Result<turborepo_api_client::Bytes, turborepo_api_client::Error>,
> + Send
+ Sync
+ 'static,
_duration: u64,
_tag: Option<&str>,
_token: &str,
Expand Down
6 changes: 5 additions & 1 deletion crates/turborepo-auth/src/auth/sso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ mod tests {
async fn put_artifact(
&self,
_hash: &str,
_artifact_body: &[u8],
_artifact_body: impl turborepo_api_client::Stream<
Item = Result<turborepo_api_client::Bytes, turborepo_api_client::Error>,
> + Send
+ Sync
+ 'static,
_duration: u64,
_tag: Option<&str>,
_token: &str,
Expand Down
6 changes: 5 additions & 1 deletion crates/turborepo-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ mod tests {
async fn put_artifact(
&self,
_hash: &str,
_artifact_body: &[u8],
_artifact_body: impl turborepo_api_client::Stream<
Item = Result<turborepo_api_client::Bytes, turborepo_api_client::Error>,
> + Send
+ Sync
+ 'static,
_duration: u64,
_tag: Option<&str>,
_token: &str,
Expand Down
Loading
Loading