Skip to content

Commit 30bd0f9

Browse files
authored
Merge pull request #46 from arielb1/no-aws-defaults
feat: support not enabling aws default features
2 parents 39db0e5 + a1f9f91 commit 30bd0f9

File tree

10 files changed

+96
-56
lines changed

10 files changed

+96
-56
lines changed

.github/actions/rust-build/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ runs:
2020
if [ "${{ inputs.toolchain }}" != stable ]; then
2121
rm -fv Cargo.lock
2222
fi
23-
cargo build --all-features --verbose
23+
cargo build --verbose ${{ inputs.flags }}
2424
- name: Run tests
2525
shell: bash
26-
run: cargo test --all-features --verbose
26+
run: |
27+
cargo test --verbose ${{ inputs.flags }}

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ jobs:
1010
toolchain:
1111
- "1.85" # Current MSRV due to Cargo MSRV feature
1212
- stable
13+
flags:
14+
- "--all-features"
15+
- "--no-default-features"
16+
- "--no-default-features --features=s3-no-defaults"
17+
- "--no-default-features --features=aws-metadata-no-defaults"
1318
env:
1419
RUST_BACKTRACE: 1
1520
steps:
@@ -18,6 +23,7 @@ jobs:
1823
uses: ./.github/actions/rust-build
1924
with:
2025
toolchain: ${{ matrix.toolchain }}
26+
flags: ${{ matrix.flags }}
2127
build-for-testing:
2228
name: Build for testing
2329
runs-on: ubuntu-latest

Cargo.lock

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

Cargo.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ edition = "2021"
99

1010
[dependencies]
1111
async-trait = "0.1"
12+
# not really an AWS crate so no need to disable default features
1213
aws-arn = { version = "0.3", optional = true }
13-
aws-config = { version = "1", optional = true }
14-
aws-sdk-s3 = { version = "1", optional = true }
14+
aws-config = { version = "1", optional = true, default-features = false }
15+
aws-sdk-s3 = { version = "1", optional = true, default-features = false }
1516
chrono = "0.4"
16-
futures = { version = "0.3", default-features = false }
17+
futures = { version = "0.3", default-features = false, features = ["alloc"] }
1718
libloading = "0.8"
18-
reqwest = { version = "0.12", default-features = false, optional = true, features = ["charset", "http2", "rustls-tls"] }
19+
reqwest = { version = "0.12", default-features = false, optional = true, features = ["charset", "http2"] }
1920
serde_json = "1"
2021
serde = { version = "1", features = ["derive"] }
2122
tempfile = "3"
2223
thiserror = "2"
23-
tokio = { version = "1", features = ["macros"], optional = true }
24+
tokio = { version = "1", features = ["fs", "macros", "rt", "sync", "time"] }
2425
tracing = "0.1"
2526
zip = { version = "3", default-features = false, features = ["deflate"] }
2627

@@ -38,5 +39,9 @@ name = 'simple'
3839

3940
[features]
4041
default = ["s3", "aws-metadata"]
41-
s3 = ["dep:aws-config", "dep:aws-sdk-s3", "dep:tokio"]
42-
aws-metadata = ["dep:reqwest", "dep:aws-config", "dep:aws-arn"]
42+
s3 = ["s3-no-defaults", "aws-config/default", "aws-sdk-s3/default"]
43+
# A version of the s3 feature that does not enable AWS default features
44+
s3-no-defaults = ["dep:aws-config", "dep:aws-sdk-s3"]
45+
aws-metadata = ["aws-metadata-no-defaults", "aws-config/default", "reqwest/rustls-tls"]
46+
# A version of the aws-metadata feature that does not enable AWS default features
47+
aws-metadata-no-defaults = ["dep:reqwest", "dep:aws-config", "dep:aws-arn"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ emit `tokio.PollCatchV1` events this way:
8989
}
9090
```
9191

92+
### Not enabling the AWS SDK / Reqwest default features
93+
94+
The `aws-metadata-no-defaults` and `s3-no-defaults` feature flags do not enable feature flags for the AWS SDK and `reqwest`.
95+
96+
If you want things to work, you'll need to enable features for these crates to allow at least a TLS provider. This can be used to use a TLS provider other than the default Rustls
97+
9298
## Decoder
9399

94100
The `decoder` directory in the Git repository contains a decoder that can be used to view JFR files, especially with PollCatch information.

examples/simple/main.rs

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
#[cfg(feature = "s3-no-defaults")]
5+
use async_profiler_agent::reporter::s3::{S3Reporter, S3ReporterConfig};
46
use async_profiler_agent::{
57
metadata::AgentMetadata,
68
profiler::{ProfilerBuilder, ProfilerOptionsBuilder},
7-
reporter::{
8-
local::LocalReporter,
9-
s3::{S3Reporter, S3ReporterConfig},
10-
},
9+
reporter::local::LocalReporter,
1110
};
1211
use std::time::Duration;
1312

13+
#[cfg(feature = "s3-no-defaults")]
1414
use aws_config::BehaviorVersion;
1515
use clap::{ArgGroup, Parser};
1616

@@ -29,20 +29,27 @@ pub fn set_up_tracing() {
2929
.init();
3030
}
3131

32+
#[derive(Clone, Debug, Default, Parser)]
33+
struct S3BucketArgs {
34+
#[arg(long, requires = "bucket_owner", requires = "profiling_group")]
35+
bucket: Option<String>,
36+
#[arg(long)]
37+
bucket_owner: Option<String>,
38+
#[arg(long)]
39+
profiling_group: Option<String>,
40+
}
41+
3242
/// Simple program to test the profiler agent
33-
#[derive(Parser, Debug)]
43+
#[derive(Debug, Parser)]
3444
#[command(group(
3545
ArgGroup::new("options")
3646
.required(true)
3747
.args(["local", "bucket"]),
3848
))]
3949
struct Args {
40-
#[arg(long)]
41-
profiling_group: Option<String>,
42-
#[arg(long)]
43-
bucket_owner: Option<String>,
44-
#[arg(long, requires = "bucket_owner", requires = "profiling_group")]
45-
bucket: Option<String>,
50+
#[cfg(feature = "s3-no-defaults")]
51+
#[command(flatten)]
52+
bucket_args: S3BucketArgs,
4653
#[arg(long)]
4754
local: Option<String>,
4855
#[arg(long)]
@@ -57,6 +64,18 @@ struct Args {
5764
native_mem: Option<String>,
5865
}
5966

67+
impl Args {
68+
#[cfg(feature = "s3-no-defaults")]
69+
fn s3_bucket_args(&self) -> S3BucketArgs {
70+
self.bucket_args.clone()
71+
}
72+
73+
#[cfg(not(feature = "s3-no-defaults"))]
74+
fn s3_bucket_args(&self) -> S3BucketArgs {
75+
S3BucketArgs::default()
76+
}
77+
}
78+
6079
#[allow(unexpected_cfgs)]
6180
pub fn main() -> anyhow::Result<()> {
6281
let args = Args::parse();
@@ -82,23 +101,24 @@ async fn main_internal(args: Args) -> Result<(), anyhow::Error> {
82101

83102
let profiler = ProfilerBuilder::default();
84103

85-
let profiler = match (
86-
args.local,
87-
args.bucket,
88-
args.bucket_owner,
89-
args.profiling_group,
90-
) {
91-
(Some(local), _, _, _) => profiler
104+
let profiler = match (&args.local, args.s3_bucket_args()) {
105+
(Some(local), S3BucketArgs { .. }) => profiler
92106
.with_reporter(LocalReporter::new(local))
93107
.with_custom_agent_metadata(AgentMetadata::Other),
94-
(_, Some(bucket), Some(bucket_owner), Some(profiling_group)) => {
95-
profiler.with_reporter(S3Reporter::new(S3ReporterConfig {
96-
sdk_config: &aws_config::defaults(BehaviorVersion::latest()).load().await,
97-
bucket_owner: bucket_owner,
98-
bucket_name: bucket,
99-
profiling_group_name: profiling_group,
100-
}))
101-
}
108+
#[cfg(feature = "s3-no-defaults")]
109+
(
110+
_,
111+
S3BucketArgs {
112+
bucket: Some(bucket_name),
113+
bucket_owner: Some(bucket_owner),
114+
profiling_group: Some(profiling_group_name),
115+
},
116+
) => profiler.with_reporter(S3Reporter::new(S3ReporterConfig {
117+
sdk_config: &aws_config::defaults(BehaviorVersion::latest()).load().await,
118+
bucket_owner,
119+
bucket_name,
120+
profiling_group_name,
121+
})),
102122
_ => unreachable!(),
103123
};
104124

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
//!
2626
//! You can use the [`S3Reporter`], which uploads the reports to an S3 bucket, as follows:
2727
//!
28-
//! ```no_run
28+
#![cfg_attr(feature = "s3-no-defaults", doc = "```no_run")]
29+
#![cfg_attr(not(feature = "s3-no-defaults"), doc = "```compile_fail")]
2930
//! # use async_profiler_agent::profiler::{ProfilerBuilder, SpawnError};
3031
//! # use async_profiler_agent::reporter::s3::{S3Reporter, S3ReporterConfig};
3132
//! # use aws_config::BehaviorVersion;

src/metadata/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct ReportMetadata<'a> {
6060
pub reporting_interval: Duration,
6161
}
6262

63-
#[cfg(feature = "aws-metadata")]
63+
#[cfg(feature = "aws-metadata-no-defaults")]
6464
pub mod aws;
6565

6666
/// [private] dummy metadata to make testing easier

src/profiler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use crate::{
77
asprof::{self, AsProfError},
8-
metadata::{aws::AwsProfilerMetadataError, AgentMetadata, ReportMetadata},
8+
metadata::{AgentMetadata, ReportMetadata},
99
reporter::Reporter,
1010
};
1111
use std::{
@@ -311,7 +311,8 @@ enum TickError {
311311
#[error(transparent)]
312312
AsProf(#[from] AsProfError),
313313
#[error(transparent)]
314-
Metadata(#[from] AwsProfilerMetadataError),
314+
#[cfg(feature = "aws-metadata-no-defaults")]
315+
Metadata(#[from] crate::metadata::aws::AwsProfilerMetadataError),
315316
#[error("reporter: {0}")]
316317
Reporter(Box<dyn std::error::Error + Send>),
317318
#[error("broken clock: {0}")]

src/reporter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::metadata::ReportMetadata;
1616

1717
pub mod local;
1818
pub mod multi;
19-
#[cfg(feature = "s3")]
19+
#[cfg(feature = "s3-no-defaults")]
2020
pub mod s3;
2121

2222
/// Abstraction around reporting profiler data.

0 commit comments

Comments
 (0)