diff --git a/.github/actions/rust-build/action.yml b/.github/actions/rust-build/action.yml index 3c959c8..ed17e72 100644 --- a/.github/actions/rust-build/action.yml +++ b/.github/actions/rust-build/action.yml @@ -20,7 +20,8 @@ runs: if [ "${{ inputs.toolchain }}" != stable ]; then rm -fv Cargo.lock fi - cargo build --all-features --verbose + cargo build --verbose ${{ inputs.flags }} - name: Run tests shell: bash - run: cargo test --all-features --verbose + run: | + cargo test --verbose ${{ inputs.flags }} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5ecab62..0767fbe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,11 @@ jobs: toolchain: - "1.85" # Current MSRV due to Cargo MSRV feature - stable + flags: + - "--all-features" + - "--no-default-features" + - "--no-default-features --features=s3-no-defaults" + - "--no-default-features --features=aws-metadata-no-defaults" env: RUST_BACKTRACE: 1 steps: @@ -18,6 +23,7 @@ jobs: uses: ./.github/actions/rust-build with: toolchain: ${{ matrix.toolchain }} + flags: ${{ matrix.flags }} build-for-testing: name: Build for testing runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index b802ee7..41a234b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -405,9 +405,9 @@ dependencies = [ [[package]] name = "aws-smithy-checksums" -version = "0.63.2" +version = "0.63.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4e5a89d8103b8090a3f04259fb851ebd3f33abf4fb3ac13326fefaa827618b" +checksum = "d2f77a921dbd2c78ebe70726799787c1d110a2245dd65e39b20923dfdfb2deee" dependencies = [ "aws-smithy-http", "aws-smithy-types", @@ -1463,9 +1463,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" +checksum = "cf9f1e950e0d9d1d3c47184416723cf29c0d1f93bd8cccf37e4beb6b44f31710" dependencies = [ "bytes", "futures-channel", @@ -1554,9 +1554,9 @@ checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" [[package]] name = "icu_properties" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2549ca8c7241c82f59c80ba2a6f415d931c5b58d24fb8412caa1a1f02c49139a" +checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" dependencies = [ "displaydoc", "icu_collections", @@ -1570,9 +1570,9 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8197e866e47b68f8f7d95249e172903bec06004b18b2937f1095d40a0c57de04" +checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" [[package]] name = "icu_provider" @@ -2046,7 +2046,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -3195,15 +3195,15 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.61.1" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46ec44dc15085cea82cf9c78f85a9114c463a369786585ad2882d1ff0b0acf40" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ "windows-implement", "windows-interface", "windows-link", "windows-result", - "windows-strings 0.4.1", + "windows-strings 0.4.2", ] [[package]] @@ -3247,9 +3247,9 @@ dependencies = [ [[package]] name = "windows-result" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b895b5356fc36103d0f64dd1e94dfa7ac5633f1c9dd6e80fe9ec4adef69e09d" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" dependencies = [ "windows-link", ] @@ -3265,9 +3265,9 @@ dependencies = [ [[package]] name = "windows-strings" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a7ab927b2637c19b3dbe0965e75d8f2d30bdd697a1516191cad2ec4df8fb28a" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ "windows-link", ] diff --git a/Cargo.toml b/Cargo.toml index 4a7c3ae..976c8f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,18 +9,19 @@ edition = "2021" [dependencies] async-trait = "0.1" +# not really an AWS crate so no need to disable default features aws-arn = { version = "0.3", optional = true } -aws-config = { version = "1", optional = true } -aws-sdk-s3 = { version = "1", optional = true } +aws-config = { version = "1", optional = true, default-features = false } +aws-sdk-s3 = { version = "1", optional = true, default-features = false } chrono = "0.4" -futures = { version = "0.3", default-features = false } +futures = { version = "0.3", default-features = false, features = ["alloc"] } libloading = "0.8" -reqwest = { version = "0.12", default-features = false, optional = true, features = ["charset", "http2", "rustls-tls"] } +reqwest = { version = "0.12", default-features = false, optional = true, features = ["charset", "http2"] } serde_json = "1" serde = { version = "1", features = ["derive"] } tempfile = "3" thiserror = "2" -tokio = { version = "1", features = ["macros"], optional = true } +tokio = { version = "1", features = ["fs", "macros", "rt", "sync", "time"] } tracing = "0.1" zip = { version = "3", default-features = false, features = ["deflate"] } @@ -38,5 +39,9 @@ name = 'simple' [features] default = ["s3", "aws-metadata"] -s3 = ["dep:aws-config", "dep:aws-sdk-s3", "dep:tokio"] -aws-metadata = ["dep:reqwest", "dep:aws-config", "dep:aws-arn"] +s3 = ["s3-no-defaults", "aws-config/default", "aws-sdk-s3/default"] +# A version of the s3 feature that does not enable AWS default features +s3-no-defaults = ["dep:aws-config", "dep:aws-sdk-s3"] +aws-metadata = ["aws-metadata-no-defaults", "aws-config/default", "reqwest/rustls-tls"] +# A version of the aws-metadata feature that does not enable AWS default features +aws-metadata-no-defaults = ["dep:reqwest", "dep:aws-config", "dep:aws-arn"] diff --git a/README.md b/README.md index 72e68c9..bfafded 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,12 @@ emit `tokio.PollCatchV1` events this way: } ``` +### Not enabling the AWS SDK / Reqwest default features + +The `aws-metadata-no-defaults` and `s3-no-defaults` feature flags do not enable feature flags for the AWS SDK and `reqwest`. + +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 + ## Decoder The `decoder` directory in the Git repository contains a decoder that can be used to view JFR files, especially with PollCatch information. diff --git a/examples/simple/main.rs b/examples/simple/main.rs index 06c6318..6511529 100644 --- a/examples/simple/main.rs +++ b/examples/simple/main.rs @@ -1,16 +1,16 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +#[cfg(feature = "s3-no-defaults")] +use async_profiler_agent::reporter::s3::{S3Reporter, S3ReporterConfig}; use async_profiler_agent::{ metadata::AgentMetadata, profiler::{ProfilerBuilder, ProfilerOptionsBuilder}, - reporter::{ - local::LocalReporter, - s3::{S3Reporter, S3ReporterConfig}, - }, + reporter::local::LocalReporter, }; use std::time::Duration; +#[cfg(feature = "s3-no-defaults")] use aws_config::BehaviorVersion; use clap::{ArgGroup, Parser}; @@ -29,20 +29,27 @@ pub fn set_up_tracing() { .init(); } +#[derive(Clone, Debug, Default, Parser)] +struct S3BucketArgs { + #[arg(long, requires = "bucket_owner", requires = "profiling_group")] + bucket: Option, + #[arg(long)] + bucket_owner: Option, + #[arg(long)] + profiling_group: Option, +} + /// Simple program to test the profiler agent -#[derive(Parser, Debug)] +#[derive(Debug, Parser)] #[command(group( ArgGroup::new("options") .required(true) .args(["local", "bucket"]), ))] struct Args { - #[arg(long)] - profiling_group: Option, - #[arg(long)] - bucket_owner: Option, - #[arg(long, requires = "bucket_owner", requires = "profiling_group")] - bucket: Option, + #[cfg(feature = "s3-no-defaults")] + #[command(flatten)] + bucket_args: S3BucketArgs, #[arg(long)] local: Option, #[arg(long)] @@ -57,6 +64,18 @@ struct Args { native_mem: Option, } +impl Args { + #[cfg(feature = "s3-no-defaults")] + fn s3_bucket_args(&self) -> S3BucketArgs { + self.bucket_args.clone() + } + + #[cfg(not(feature = "s3-no-defaults"))] + fn s3_bucket_args(&self) -> S3BucketArgs { + S3BucketArgs::default() + } +} + #[allow(unexpected_cfgs)] pub fn main() -> anyhow::Result<()> { let args = Args::parse(); @@ -82,23 +101,24 @@ async fn main_internal(args: Args) -> Result<(), anyhow::Error> { let profiler = ProfilerBuilder::default(); - let profiler = match ( - args.local, - args.bucket, - args.bucket_owner, - args.profiling_group, - ) { - (Some(local), _, _, _) => profiler + let profiler = match (&args.local, args.s3_bucket_args()) { + (Some(local), S3BucketArgs { .. }) => profiler .with_reporter(LocalReporter::new(local)) .with_custom_agent_metadata(AgentMetadata::Other), - (_, Some(bucket), Some(bucket_owner), Some(profiling_group)) => { - profiler.with_reporter(S3Reporter::new(S3ReporterConfig { - sdk_config: &aws_config::defaults(BehaviorVersion::latest()).load().await, - bucket_owner: bucket_owner, - bucket_name: bucket, - profiling_group_name: profiling_group, - })) - } + #[cfg(feature = "s3-no-defaults")] + ( + _, + S3BucketArgs { + bucket: Some(bucket_name), + bucket_owner: Some(bucket_owner), + profiling_group: Some(profiling_group_name), + }, + ) => profiler.with_reporter(S3Reporter::new(S3ReporterConfig { + sdk_config: &aws_config::defaults(BehaviorVersion::latest()).load().await, + bucket_owner, + bucket_name, + profiling_group_name, + })), _ => unreachable!(), }; diff --git a/src/lib.rs b/src/lib.rs index 58a1e4d..05d1095 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,8 @@ //! //! You can use the [`S3Reporter`], which uploads the reports to an S3 bucket, as follows: //! -//! ```no_run +#![cfg_attr(feature = "s3-no-defaults", doc = "```no_run")] +#![cfg_attr(not(feature = "s3-no-defaults"), doc = "```compile_fail")] //! # use async_profiler_agent::profiler::{ProfilerBuilder, SpawnError}; //! # use async_profiler_agent::reporter::s3::{S3Reporter, S3ReporterConfig}; //! # use aws_config::BehaviorVersion; diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index c2f517a..a2e0692 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -60,7 +60,7 @@ pub struct ReportMetadata<'a> { pub reporting_interval: Duration, } -#[cfg(feature = "aws-metadata")] +#[cfg(feature = "aws-metadata-no-defaults")] pub mod aws; /// [private] dummy metadata to make testing easier diff --git a/src/profiler.rs b/src/profiler.rs index 8f813d4..dd2ff93 100644 --- a/src/profiler.rs +++ b/src/profiler.rs @@ -5,7 +5,7 @@ use crate::{ asprof::{self, AsProfError}, - metadata::{aws::AwsProfilerMetadataError, AgentMetadata, ReportMetadata}, + metadata::{AgentMetadata, ReportMetadata}, reporter::Reporter, }; use std::{ @@ -311,7 +311,8 @@ enum TickError { #[error(transparent)] AsProf(#[from] AsProfError), #[error(transparent)] - Metadata(#[from] AwsProfilerMetadataError), + #[cfg(feature = "aws-metadata-no-defaults")] + Metadata(#[from] crate::metadata::aws::AwsProfilerMetadataError), #[error("reporter: {0}")] Reporter(Box), #[error("broken clock: {0}")] diff --git a/src/reporter/mod.rs b/src/reporter/mod.rs index c54b063..482d2ce 100644 --- a/src/reporter/mod.rs +++ b/src/reporter/mod.rs @@ -16,7 +16,7 @@ use crate::metadata::ReportMetadata; pub mod local; pub mod multi; -#[cfg(feature = "s3")] +#[cfg(feature = "s3-no-defaults")] pub mod s3; /// Abstraction around reporting profiler data.