Skip to content

Commit 40cad26

Browse files
author
Ariel Ben-Yehuda
committed
address review comments
1 parent 0f62067 commit 40cad26

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ All notable changes to this project will be documented in this file.
1010

1111
- add support for stopping the profiler
1212
- make native memory profiling interval configurable
13-
- add Cargo features to allow not enabling AWS/reqwest default features
1413

1514
### Other
1615

examples/simple/main.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,28 @@ pub fn set_up_tracing() {
2929
.init();
3030
}
3131

32+
33+
#[derive(Clone, Debug, Parser)]
34+
struct S3BucketArgs {
35+
#[arg(long, requires = "bucket_owner", requires = "profiling_group")]
36+
bucket: Option<String>,
37+
#[arg(long)]
38+
bucket_owner: Option<String>,
39+
#[arg(long)]
40+
profiling_group: Option<String>,
41+
}
42+
3243
/// Simple program to test the profiler agent
33-
#[derive(Parser, Debug)]
44+
#[derive(Debug, Parser)]
3445
#[command(group(
3546
ArgGroup::new("options")
3647
.required(true)
3748
.args(["local", "bucket"]),
3849
))]
3950
struct Args {
4051
#[cfg(feature = "s3-no-defaults")]
41-
#[arg(long)]
42-
profiling_group: Option<String>,
43-
#[cfg(feature = "s3-no-defaults")]
44-
#[arg(long)]
45-
bucket_owner: Option<String>,
46-
#[cfg(feature = "s3-no-defaults")]
47-
#[arg(long, requires = "bucket_owner", requires = "profiling_group")]
48-
bucket: Option<String>,
52+
#[command(flatten)]
53+
bucket_args: S3BucketArgs,
4954
#[arg(long)]
5055
local: Option<String>,
5156
#[arg(long)]
@@ -60,6 +65,18 @@ struct Args {
6065
native_mem: Option<String>,
6166
}
6267

68+
impl Args {
69+
#[cfg(feature = "s3-no-defaults")]
70+
fn s3_bucket_args(&self) -> S3BucketArgs {
71+
self.bucket_args.clone()
72+
}
73+
74+
#[cfg(not(feature = "s3-no-defaults"))]
75+
fn s3_bucket_args(&self) -> S3BucketArgs {
76+
BucketArgs::default()
77+
}
78+
}
79+
6380
#[allow(unexpected_cfgs)]
6481
pub fn main() -> anyhow::Result<()> {
6582
let args = Args::parse();
@@ -85,25 +102,16 @@ async fn main_internal(args: Args) -> Result<(), anyhow::Error> {
85102

86103
let profiler = ProfilerBuilder::default();
87104

88-
#[cfg(feature = "s3-no-defaults")]
89-
let bucket_name = args.bucket;
90-
#[cfg(not(feature = "s3-no-defaults"))]
91-
let bucket_name: Option<String> = None;
92-
#[cfg(feature = "s3-no-defaults")]
93-
let bucket_owner = args.bucket_owner;
94-
#[cfg(not(feature = "s3-no-defaults"))]
95-
let bucket_owner: Option<String> = None;
96-
#[cfg(feature = "s3-no-defaults")]
97-
let profiling_group_name = args.profiling_group;
98-
#[cfg(not(feature = "s3-no-defaults"))]
99-
let profiling_group_name: Option<String> = None;
100-
101-
let profiler = match (args.local, bucket_name, bucket_owner, profiling_group_name) {
102-
(Some(local), _, _, _) => profiler
105+
let profiler = match (&args.local, args.s3_bucket_args()) {
106+
(Some(local), S3BucketArgs { .. }) => profiler
103107
.with_reporter(LocalReporter::new(local))
104108
.with_custom_agent_metadata(AgentMetadata::Other),
105109
#[cfg(feature = "s3-no-defaults")]
106-
(_, Some(bucket_name), Some(bucket_owner), Some(profiling_group_name)) => profiler
110+
(_, S3BucketArgs {
111+
bucket: Some(bucket_name),
112+
bucket_owner: Some(bucket_owner),
113+
profiling_group: Some(profiling_group_name)
114+
}) => profiler
107115
.with_reporter(S3Reporter::new(S3ReporterConfig {
108116
sdk_config: &aws_config::defaults(BehaviorVersion::latest()).load().await,
109117
bucket_owner,

0 commit comments

Comments
 (0)