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

PHD: convert to async #633

Merged
merged 21 commits into from
Feb 7, 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
4 changes: 4 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ num_enum = "0.5.11"
owo-colors = "4"
pin-project-lite = "0.2.13"
proc-macro2 = "1.0"
proc-macro-error = "1"
progenitor = { git = "https://github.com/oxidecomputer/progenitor", ref = "v0.5.0" }
quote = "1.0"
rand = "0.8"
Expand Down
47 changes: 24 additions & 23 deletions phd-tests/framework/src/artifacts/buildomat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,50 @@ impl Repo {
Self(Cow::Borrowed(s))
}

pub(super) fn artifact_for_commit(
pub(super) async fn artifact_for_commit(
self,
series: Series,
commit: Commit,
filename: impl AsRef<Utf8Path>,
downloader: &DownloadConfig,
) -> anyhow::Result<BuildomatArtifact> {
let filename = filename.as_ref();
let sha256 = self.get_sha256(&series, &commit, filename, downloader)?;
let sha256 =
self.get_sha256(&series, &commit, filename, downloader).await?;

Ok(BuildomatArtifact { repo: self, series, commit, sha256 })
}

pub(super) fn get_branch_head(
pub(super) async fn get_branch_head(
&self,
branch: &str,
) -> anyhow::Result<Commit> {
(|| {
async {
let uri = format!("{BASE_URI}/branch/{self}/{branch}");
let client = reqwest::blocking::ClientBuilder::new()
let client = reqwest::ClientBuilder::new()
.timeout(Duration::from_secs(5))
.build()?;
let req = client.get(uri).build()?;
let rsp = client.execute(req)?;
let rsp = client.execute(req).await?;
let status = rsp.status();
anyhow::ensure!(status.is_success(), "HTTP status: {status}");
let bytes = rsp.bytes()?;
let bytes = rsp.bytes().await?;
str_from_bytes(&bytes)?.parse::<Commit>()
})()
}
.await
.with_context(|| {
format!("Failed to determine HEAD commit for {self}@{branch}")
})
}

fn get_sha256(
async fn get_sha256(
&self,
series: &Series,
commit: &Commit,
filename: &Utf8Path,
downloader: &DownloadConfig,
) -> anyhow::Result<String> {
(|| {
async {
let filename = filename
.file_name()
.ok_or_else(|| {
Expand Down Expand Up @@ -105,9 +107,9 @@ impl Repo {
)
})?;
let uri = format!("{BASE_URI}/file/{self}/{series}/{commit}/{filename}.sha256.txt");
let bytes = downloader.download_buildomat_uri(&uri)?;
let bytes = downloader.download_buildomat_uri(&uri).await?;
str_from_bytes(&bytes).map(String::from)
})().with_context(|| {
}.await.with_context(|| {
format!("Failed to get SHA256 for {self}@{commit}, series: {series}, file: {filename})")
})
}
Expand Down Expand Up @@ -206,7 +208,7 @@ impl super::DownloadConfig {
/// retry duration. This retry logic serves as a mechanism for PHD to wait
/// for an artifact we expect to exist to be published, when the build that
/// publishes that artifact is still in progress.
pub(super) fn download_buildomat_uri(
pub(super) async fn download_buildomat_uri(
&self,
uri: &str,
) -> anyhow::Result<bytes::Bytes> {
Expand All @@ -215,10 +217,9 @@ impl super::DownloadConfig {
%uri,
"Downloading file from Buildomat...",
);
let client = reqwest::blocking::ClientBuilder::new()
.timeout(self.timeout)
.build()?;
let try_download = || {
let client =
reqwest::ClientBuilder::new().timeout(self.timeout).build()?;
let try_download = || async {
let request = client
.get(uri)
.build()
Expand All @@ -229,7 +230,9 @@ impl super::DownloadConfig {

let response = client
.execute(request)
.await
.map_err(|e| backoff::Error::transient(e.into()))?;

if !response.status().is_success() {
// when downloading a file from buildomat, we currently retry
// all errors, since buildomat returns 500s when an artifact
Expand All @@ -252,17 +255,15 @@ impl super::DownloadConfig {
);
};

let bytes = backoff::retry_notify(
let bytes = backoff::future::retry_notify(
self.buildomat_backoff.clone(),
try_download,
log_retry,
)
.map_err(|e| match e {
backoff::Error::Permanent(e) => e,
backoff::Error::Transient { err, .. } => err,
})
.await
.with_context(|| format!("Failed to download '{uri}' from Buildomat"))?
.bytes()?;
.bytes()
.await?;

Ok(bytes)
}
Expand Down
Loading