Skip to content

Commit 7a5c420

Browse files
Update to latest SDKs & make body-writing &[u8]
1 parent 434a549 commit 7a5c420

File tree

8 files changed

+369
-149
lines changed

8 files changed

+369
-149
lines changed

Cargo.lock

Lines changed: 334 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ prometheus = "0.13.3"
5656
cargo_metadata = "0.18.1"
5757
indexmap = { version = "2.0.2", features = ["serde"] }
5858
tokio = "1.24"
59-
aws-types = "0.56.1"
60-
aws-credential-types = "0.56.1"
61-
aws-smithy-async = "0.56.1"
62-
aws-sdk-s3 = "0.34"
59+
aws-sdk-s3 = "1.7"
60+
aws-config = { version = "1", features = ["behavior-version-latest"] }
6361
thiserror = "1.0.38"
6462

6563
[dev-dependencies]

src/report/archives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn write_all_archive<DB: ReadResults, W: ReportWriter>(
111111
let len = data.len();
112112
match dest.write_bytes(
113113
"logs-archives/all.tar.gz",
114-
data,
114+
&data,
115115
&"application/gzip".parse().unwrap(),
116116
EncodingType::Plain,
117117
) {
@@ -164,7 +164,7 @@ pub fn write_logs_archives<DB: ReadResults, W: ReportWriter>(
164164
let data = archive.into_inner()?.finish()?;
165165
dest.write_bytes(
166166
format!("logs-archives/{comparison}.tar.gz"),
167-
data,
167+
&data,
168168
&"application/gzip".parse().unwrap(),
169169
EncodingType::Plain,
170170
)?;

src/report/html.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ pub fn write_html_report<W: ReportWriter>(
298298
info!("copying static assets");
299299
dest.write_bytes(
300300
"report.js",
301-
js_in.content()?.into_owned(),
301+
&js_in.content()?,
302302
js_in.mime(),
303303
EncodingType::Plain,
304304
)?;
305305
dest.write_bytes(
306306
"report.css",
307-
css_in.content()?.into_owned(),
307+
&css_in.content()?,
308308
css_in.mime(),
309309
EncodingType::Plain,
310310
)?;

src/report/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ fn write_logs<DB: ReadResults, W: ReportWriter>(
293293
s.spawn(move || {
294294
while let Ok((log_path, data, encoding)) = rx.recv() {
295295
if let Err(e) =
296-
dest.write_bytes(log_path, data, &mime::TEXT_PLAIN_UTF_8, encoding)
296+
dest.write_bytes(log_path, &data, &mime::TEXT_PLAIN_UTF_8, encoding)
297297
{
298298
errors.lock().unwrap().push(e);
299299
}
@@ -548,7 +548,7 @@ pub trait ReportWriter: Send + Sync {
548548
fn write_bytes<P: AsRef<Path>>(
549549
&self,
550550
path: P,
551-
b: Vec<u8>,
551+
b: &[u8],
552552
mime: &Mime,
553553
encoding_type: EncodingType,
554554
) -> Fallible<()>;
@@ -574,7 +574,7 @@ impl ReportWriter for FileWriter {
574574
fn write_bytes<P: AsRef<Path>>(
575575
&self,
576576
path: P,
577-
b: Vec<u8>,
577+
b: &[u8],
578578
_: &Mime,
579579
_: EncodingType,
580580
) -> Fallible<()> {
@@ -619,7 +619,7 @@ impl ReportWriter for DummyWriter {
619619
fn write_bytes<P: AsRef<Path>>(
620620
&self,
621621
path: P,
622-
b: Vec<u8>,
622+
b: &[u8],
623623
mime: &Mime,
624624
_: EncodingType,
625625
) -> Fallible<()> {

src/report/s3.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ impl ReportWriter for S3Writer {
7777
fn write_bytes<P: AsRef<Path>>(
7878
&self,
7979
path: P,
80-
s: Vec<u8>,
80+
body: &[u8],
8181
mime: &Mime,
8282
encoding_type: EncodingType,
8383
) -> Fallible<()> {
8484
// At least 50 MB, then use a multipart upload...
85-
if s.len() >= 50 * 1024 * 1024 {
85+
if body.len() >= 50 * 1024 * 1024 {
8686
let mut request = self
8787
.client
8888
.create_multipart_upload()
@@ -108,12 +108,12 @@ impl ReportWriter for S3Writer {
108108
};
109109

110110
let chunk_size = 20 * 1024 * 1024;
111-
let bytes = bytes::Bytes::from(s);
112111
let mut part = 1;
113112
let mut start = 0;
114113
let mut parts = aws_sdk_s3::types::CompletedMultipartUpload::builder();
115-
while start < bytes.len() {
116-
let chunk = bytes.slice(start..std::cmp::min(start + chunk_size, bytes.len()));
114+
while start < body.len() {
115+
let chunk = &body[start..std::cmp::min(start + chunk_size, body.len())];
116+
let chunk = bytes::Bytes::copy_from_slice(chunk);
117117

118118
let request = self
119119
.client
@@ -160,7 +160,9 @@ impl ReportWriter for S3Writer {
160160
let mut request = self
161161
.client
162162
.put_object()
163-
.body(aws_sdk_s3::primitives::ByteStream::from(s))
163+
.body(aws_sdk_s3::primitives::ByteStream::from(
164+
bytes::Bytes::copy_from_slice(body),
165+
))
164166
.acl(aws_sdk_s3::types::ObjectCannedAcl::PublicRead)
165167
.key(format!(
166168
"{}/{}",
@@ -185,7 +187,7 @@ impl ReportWriter for S3Writer {
185187
}
186188

187189
fn write_string<P: AsRef<Path>>(&self, path: P, s: Cow<str>, mime: &Mime) -> Fallible<()> {
188-
self.write_bytes(path, s.into_owned().into_bytes(), mime, EncodingType::Plain)
190+
self.write_bytes(path, s.as_bytes(), mime, EncodingType::Plain)
189191
}
190192
}
191193

src/server/reports.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use aws_sdk_s3::config::retry::RetryConfig;
2-
31
use crate::experiments::{Experiment, Status};
42
use crate::prelude::*;
53
use crate::report::{self, Comparison, TestResults};
@@ -17,24 +15,21 @@ use super::tokens::BucketRegion;
1715
const AUTOMATIC_THREAD_WAKEUP: u64 = 600;
1816

1917
fn generate_report(data: &Data, ex: &Experiment, results: &DatabaseDB) -> Fallible<TestResults> {
20-
let mut config = aws_types::SdkConfig::builder();
18+
let mut config = aws_config::from_env();
2119
match &data.tokens.reports_bucket.region {
2220
BucketRegion::S3 { region } => {
23-
config.set_region(Some(aws_types::region::Region::new(region.to_owned())));
21+
config = config.region(aws_sdk_s3::config::Region::new(region.to_owned()));
2422
}
2523
BucketRegion::Custom { url } => {
26-
config.set_region(Some(aws_types::region::Region::from_static("us-east-1")));
27-
config.set_endpoint_url(Some(url.clone()));
24+
config = config.region(aws_sdk_s3::config::Region::from_static("us-east-1"));
25+
config = config.endpoint_url(url.clone());
2826
}
2927
}
30-
config.set_credentials_provider(Some(data.tokens.reports_bucket.to_aws_credentials()));
31-
// https://github.com/awslabs/aws-sdk-rust/issues/586 -- without this, the
32-
// SDK will just completely not retry requests.
33-
config.set_sleep_impl(Some(aws_sdk_s3::config::SharedAsyncSleep::new(
34-
aws_smithy_async::rt::sleep::TokioSleep::new(),
35-
)));
36-
config.set_retry_config(Some(RetryConfig::standard()));
37-
let config = config.build();
28+
config = config.credentials_provider(data.tokens.reports_bucket.to_aws_credentials());
29+
let config = tokio::runtime::Builder::new_current_thread()
30+
.enable_all()
31+
.build()?
32+
.block_on(config.load());
3833
let client = aws_sdk_s3::Client::new(&config);
3934
let writer = report::S3Writer::create(
4035
client,

src/server/tokens.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ pub struct ReportsBucket {
3030
}
3131

3232
impl ReportsBucket {
33-
pub(crate) fn to_aws_credentials(
34-
&self,
35-
) -> aws_credential_types::provider::SharedCredentialsProvider {
36-
aws_credential_types::provider::SharedCredentialsProvider::new(
37-
aws_sdk_s3::config::Credentials::new(
38-
self.access_key.clone(),
39-
self.secret_key.clone(),
40-
None,
41-
None,
42-
"crater-credentials",
43-
),
33+
pub(crate) fn to_aws_credentials(&self) -> aws_sdk_s3::config::Credentials {
34+
aws_sdk_s3::config::Credentials::new(
35+
self.access_key.clone(),
36+
self.secret_key.clone(),
37+
None,
38+
None,
39+
"crater-credentials",
4440
)
4541
}
4642
}

0 commit comments

Comments
 (0)