Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed May 22, 2024
1 parent 9456284 commit 8661711
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
35 changes: 17 additions & 18 deletions momento/src/commands/cloud_linter/api_gateway.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::mpsc::Sender;
use crate::commands::cloud_linter::metrics::{
AppendMetrics, Metric, MetricTarget, ResourceWithMetrics,
};
use crate::commands::cloud_linter::resource::{ApiGatewayResource, Resource, ResourceType};
use crate::error::CliError;
use aws_config::SdkConfig;
use aws_sdk_apigateway::types::RestApi;
use governor::DefaultDirectRateLimiter;
use indicatif::{ProgressBar, ProgressStyle};
use phf::{phf_map, Map};
use serde::Serialize;
use crate::commands::cloud_linter::metrics::{AppendMetrics, Metric, MetricTarget, ResourceWithMetrics};
use crate::commands::cloud_linter::resource::{ApiGatewayResource, Resource, ResourceType};
use crate::error::CliError;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::mpsc::Sender;

const API_GATEWAY_METRICS: Map<&'static str, &'static [&'static str]> = phf_map! {
"Sum" => &[
Expand Down Expand Up @@ -43,15 +45,12 @@ pub(crate) struct ApiGatewayMetadata {

impl ResourceWithMetrics for ApiGatewayResource {
fn create_metric_targets(&self) -> Result<Vec<MetricTarget>, CliError> {
let mut targets = Vec::new();
targets.push(MetricTarget {
let targets = vec![MetricTarget {
namespace: "AWS/ApiGateway".to_string(),
expression: "".to_string(),
dimensions: HashMap::from([
("ApiName".to_string(), self.metadata.name.clone())
]),
dimensions: HashMap::from([("ApiName".to_string(), self.metadata.name.clone())]),
targets: API_GATEWAY_METRICS,
});
}];
match self.resource_type {
ResourceType::ApiGateway => Ok(targets),
_ => Err(CliError {
Expand All @@ -67,10 +66,8 @@ impl ResourceWithMetrics for ApiGatewayResource {
fn set_metric_period_seconds(&mut self, period: i32) {
self.metric_period_seconds = period;
}

}


pub(crate) async fn process_api_gateway_resources(
config: &SdkConfig,
metrics_limiter: Arc<DefaultDirectRateLimiter>,
Expand All @@ -79,7 +76,7 @@ pub(crate) async fn process_api_gateway_resources(
let region = config.region().map(|r| r.as_ref()).ok_or(CliError {
msg: "No region configured for client".to_string(),
})?;
let apig_client = aws_sdk_apigateway::Client::new(&config);
let apig_client = aws_sdk_apigateway::Client::new(config);
let metrics_client = aws_sdk_cloudwatch::Client::new(config);

let list_apis_bar = ProgressBar::new_spinner().with_message("Listing API Gateway resources");
Expand Down Expand Up @@ -110,7 +107,8 @@ async fn process_apis(
metrics_limiter: &Arc<DefaultDirectRateLimiter>,
) -> Result<(), CliError> {
let mut resources: Vec<Resource> = Vec::with_capacity(apis.len());
let get_apis_bar = ProgressBar::new((apis.len() * 2) as u64).with_message("Processing API Gateway resources");
let get_apis_bar =
ProgressBar::new((apis.len() * 2) as u64).with_message("Processing API Gateway resources");
get_apis_bar
.set_style(ProgressStyle::with_template(" {msg} {bar} {eta}").expect("invalid template"));
for api in apis {
Expand All @@ -130,7 +128,7 @@ async fn process_apis(
id: the_api.id.clone().unwrap_or_default(),
metrics: vec![],
metric_period_seconds: 0,
metadata
metadata,
};
resources.push(Resource::ApiGateway(apig_resource));
get_apis_bar.inc(1);
Expand All @@ -140,7 +138,8 @@ async fn process_apis(
match resource {
Resource::ApiGateway(mut apig_resource) => {
apig_resource
.append_metrics(&metrics_client, Arc::clone(&metrics_limiter)).await?;
.append_metrics(metrics_client, Arc::clone(metrics_limiter))
.await?;
sender
.send(Resource::ApiGateway(apig_resource))
.await
Expand Down
2 changes: 1 addition & 1 deletion momento/src/commands/cloud_linter/linter_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::io::{copy, BufReader};
use std::path::Path;
use std::sync::Arc;

use crate::commands::cloud_linter::api_gateway::process_api_gateway_resources;
use aws_config::{BehaviorVersion, Region};
use flate2::write::GzEncoder;
use flate2::Compression;
use governor::{Quota, RateLimiter};
use struson::writer::{JsonStreamWriter, JsonWriter};
use tokio::fs::{metadata, File};
use tokio::sync::mpsc::{self, Sender};
use crate::commands::cloud_linter::api_gateway::process_api_gateway_resources;

use crate::commands::cloud_linter::dynamodb::process_ddb_resources;
use crate::commands::cloud_linter::s3::process_s3_resources;
Expand Down
2 changes: 1 addition & 1 deletion momento/src/commands/cloud_linter/resource.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::Serialize;
use crate::commands::cloud_linter::api_gateway::ApiGatewayMetadata;
use serde::Serialize;

use crate::commands::cloud_linter::dynamodb::DynamoDbMetadata;
use crate::commands::cloud_linter::elasticache::ElastiCacheMetadata;
Expand Down

0 comments on commit 8661711

Please sign in to comment.