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

chore: make s3 and API gateway cloud linting optional #330

Merged
merged 2 commits into from
Aug 5, 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
14 changes: 12 additions & 2 deletions momento-cli-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,24 @@ to help find opportunities for optimizations with Momento.
region: String,
#[arg(
long = "enable-ddb-ttl-check",
help = "Opt in to check whether ddb tables have ttl enabled. If there are lots of tables, could slow down data collection"
help = "Opt in to check whether ddb tables have ttl enabled. If there are lots of tables, this could slow down data collection"
)]
enable_ddb_ttl_check: bool,
#[arg(
long = "enable-gsi",
help = "Opt in to check metrics on dynamodb gsi's. If there are lots of tables with gsi's, could slow down data collection"
help = "Opt in to check metrics on dynamodb gsi's. If there are lots of tables with gsi's, this could slow down data collection"
)]
enable_gsi: bool,
#[arg(
long = "enable-s3",
help = "Opt in to check metrics on s3. If there are lots of s3 buckets, this could slow down data collection"
)]
enable_s3: bool,
#[arg(
long = "enable-apt-gateway",
help = "Opt in to check metrics on API Gateway"
)]
enable_api_gateway: bool,
#[arg(
value_enum,
long = "resource",
Expand Down
39 changes: 25 additions & 14 deletions momento/src/commands/cloud_linter/linter_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub async fn run_cloud_linter(
region: String,
enable_ddb_ttl_check: bool,
enable_gsi: bool,
enable_s3: bool,
enable_api_gateway: bool,
only_collect_for_resource: Option<CloudLinterResources>,
metric_collection_rate: u32,
) -> Result<(), CliError> {
Expand All @@ -49,6 +51,8 @@ pub async fn run_cloud_linter(
tx,
enable_ddb_ttl_check,
enable_gsi,
enable_s3,
enable_api_gateway,
only_collect_for_resource,
metric_collection_rate,
)
Expand Down Expand Up @@ -80,11 +84,14 @@ pub async fn run_cloud_linter(
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn process_data(
region: String,
sender: Sender<Resource>,
enable_ddb_ttl_check: bool,
enable_gsi: bool,
enable_s3: bool,
enable_api_gateway: bool,
only_collect_for_resource: Option<CloudLinterResources>,
metric_collection_rate: u32,
) -> Result<(), CliError> {
Expand Down Expand Up @@ -170,21 +177,25 @@ async fn process_data(
};
};

process_s3_resources(
&config,
Arc::clone(&control_plane_limiter),
Arc::clone(&metrics_limiter),
sender.clone(),
)
.await?;
if enable_s3 {
process_s3_resources(
&config,
Arc::clone(&control_plane_limiter),
Arc::clone(&metrics_limiter),
sender.clone(),
)
.await?;
}

process_api_gateway_resources(
&config,
Arc::clone(&control_plane_limiter),
Arc::clone(&metrics_limiter),
sender.clone(),
)
.await?;
if enable_api_gateway {
process_api_gateway_resources(
&config,
Arc::clone(&control_plane_limiter),
Arc::clone(&metrics_limiter),
sender.clone(),
)
.await?;
}

process_ddb_resources(
&config,
Expand Down
21 changes: 0 additions & 21 deletions momento/src/commands/configure/configure_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,6 @@ async fn set_file_read_write(path: &str) -> Result<(), CliError> {
}
}

#[cfg(target_os = "ubuntu")]
async fn set_file_read_write(path: &str) -> Result<(), CliError> {
use std::os::unix::fs::PermissionsExt;
let mut perms = match fs::metadata(path).await {
Ok(p) => p,
Err(e) => {
return Err(CliError {
msg: format!("failed to get file permissions {e}"),
})
}
}
.permissions();
perms.set_mode(0o600);
match fs::set_permissions(path, perms).await {
Ok(_) => Ok(()),
Err(e) => Err(CliError {
msg: format!("failed to set file permissions {e}"),
}),
}
}

#[cfg(target_os = "windows")]
async fn set_file_read_write(path: &str) -> Result<(), CliError> {
let mut perms = match fs::metadata(path).await {
Expand Down
4 changes: 4 additions & 0 deletions momento/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,15 @@ async fn run_momento_command(args: momento_cli_opts::Momento) -> Result<(), CliE
resource,
metric_collection_rate,
enable_gsi,
enable_s3,
enable_api_gateway,
} => {
commands::cloud_linter::linter_cli::run_cloud_linter(
region,
enable_ddb_ttl_check,
enable_gsi,
enable_s3,
enable_api_gateway,
resource,
metric_collection_rate,
)
Expand Down