Skip to content
Open
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
10 changes: 5 additions & 5 deletions cloud-scanner-cli/src/aws_cloud_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ mod tests {
async fn get_cpu_usage_metrics_of_running_instance_should_return_right_number_of_data_points() {
let aws: AwsCloudProvider = AwsCloudProvider::new("eu-west-1").await.unwrap();
let res = aws
.get_average_cpu_usage_of_last_10_minutes(&RUNNING_INSTANCE_ID)
.get_average_cpu_usage_of_last_10_minutes(RUNNING_INSTANCE_ID)
.await
.unwrap();
let datapoints = res.datapoints.unwrap();
assert!(
0 < datapoints.len() && datapoints.len() < 3,
!datapoints.is_empty() && datapoints.len() < 3,
"Strange number of datapoint returned for instance {}, is it really up ?. I was expecting 1 or 2 but got {} .\n {:#?}",
&RUNNING_INSTANCE_ID,
datapoints.len(),
Expand Down Expand Up @@ -476,15 +476,15 @@ mod tests {
// This instance needs to be running for the test to pass
let aws: AwsCloudProvider = AwsCloudProvider::new("eu-west-1").await.unwrap();

let avg_cpu_load = aws.get_average_cpu(&RUNNING_INSTANCE_ID).await.unwrap();
let avg_cpu_load = aws.get_average_cpu(RUNNING_INSTANCE_ID).await.unwrap();
assert_ne!(
0 as f64, avg_cpu_load,
"CPU load of instance {} is zero, is it really running ?",
&RUNNING_INSTANCE_ID
);
println!("{:#?}", avg_cpu_load);
assert!((0 as f64) < avg_cpu_load);
assert!((100 as f64) > avg_cpu_load);
assert!(0_f64 < avg_cpu_load);
assert!(100_f64 > avg_cpu_load);
}

#[tokio::test]
Expand Down
23 changes: 9 additions & 14 deletions cloud-scanner-cli/src/boavizta_api_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ mod tests {
tags: Vec::new(),
};
let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
let one_hour = 1.0 as f32;
let one_hour = 1.0_f32;
let res = api
.get_raws_impacts(instance1, &one_hour, false)
.await
Expand All @@ -404,7 +404,7 @@ mod tests {
};

let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
let one_hour = 1.0 as f32;
let one_hour = 1.0_f32;
let res = api.get_raws_impacts(hdd, &one_hour, true).await.unwrap();

let expected: serde_json::Value = serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_HDD).unwrap();
Expand All @@ -429,7 +429,7 @@ mod tests {
};

let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
let one_hour = 1.0 as f32;
let one_hour = 1.0_f32;
let res = api.get_raws_impacts(ssd, &one_hour, true).await.unwrap();

let expected: serde_json::Value =
Expand Down Expand Up @@ -470,11 +470,9 @@ mod tests {
};

let api: BoaviztaApiV1 = BoaviztaApiV1::new(TEST_API_URL);
let one_hour = 1.0 as f32;
let one_hour = 1.0_f32;

let mut instances: Vec<CloudResource> = Vec::new();
instances.push(instance1);
instances.push(instance1_1percent);
let instances: Vec<CloudResource> = vec![instance1, instance1_1percent];

let inventory = Inventory {
metadata: InventoryMetadata {
Expand Down Expand Up @@ -538,11 +536,8 @@ mod tests {
tags: Vec::new(),
};

let mut instances: Vec<CloudResource> = Vec::new();
instances.push(instance1);
instances.push(instance2);
instances.push(instance3);
let one_hour = 1.0 as f32;
let instances: Vec<CloudResource> = vec![instance1, instance2, instance3];
let one_hour = 1.0_f32;

let inventory = Inventory {
metadata: InventoryMetadata {
Expand Down Expand Up @@ -590,7 +585,7 @@ mod tests {

let raw_impacts =
Some(serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_M6GXLARGE_1HRS_FR).unwrap());
let one_hour: f32 = 1 as f32;
let one_hour: f32 = 1_f32;
let cloud_resource_with_impacts: CloudResourceWithImpacts =
boa_impacts_to_cloud_resource_with_impacts(&instance1, &raw_impacts, &one_hour);
assert!(
Expand Down Expand Up @@ -636,7 +631,7 @@ mod tests {

let raw_impacts =
Some(serde_json::from_str(DEFAULT_RAW_IMPACTS_OF_M6GXLARGE_1HRS_FR_VERBOSE).unwrap());
let one_hour: f32 = 1 as f32;
let one_hour: f32 = 1_f32;
let cloud_resource_with_impacts: CloudResourceWithImpacts =
boa_impacts_to_cloud_resource_with_impacts(&instance1, &raw_impacts, &one_hour);
assert!(
Expand Down
50 changes: 23 additions & 27 deletions cloud-scanner-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Arguments {
aws_region: Option<String>,

#[arg(short, long)]
/// Optional Boavizta API URL if you want to use your own instance (URL without the trailing slash, e.g. https://api.boavizta.org)
/// Optional Boavizta API URL if you want to use your own instance (URL without the trailing slash, e.g. <https://api.boavizta.org>)
boavizta_api_url: Option<String>,

#[arg(short = 't', long)]
Expand All @@ -42,7 +42,7 @@ enum SubCommand {
use_duration_hours: f32,

#[arg(long, short = 'f', action)]
/// Retrieve and output the details from BoaviztaAPI (equivalent to the verbose flag when querying Boavizta API)
/// Retrieve and output the details from `BoaviztaAPI` (equivalent to the verbose flag when querying Boavizta API)
output_verbose_json: bool,

#[arg(long, short = 'b', action)]
Expand All @@ -57,7 +57,7 @@ enum SubCommand {
#[arg(short, long)]
inventory_file: Option<PathBuf>,
},
/// Get estimation of impacts for a given usage duration as OpenMetrics (Prometheus) instead of json
/// Get estimation of impacts for a given usage duration as `OpenMetrics` (Prometheus) instead of json
Metrics {
#[arg(short = 'u', long)]
/// The number of hours of use for which we want to estimate the impacts
Expand All @@ -78,32 +78,29 @@ enum SubCommand {
print_json_schema: bool,
},
/// Run as a standalone server.
/// Access metrics (e.g. http://localhost:8000/metrics?aws_region=eu-west-3), inventory or impacts (see http://localhost:8000/swagger-ui)
/// Access metrics (e.g. <http://localhost:8000/metrics?aws_region=eu-west-3>), inventory or impacts (se<http://localhost:8000/swagger-ui>ui)
Serve {},
}

fn set_region(optional_region: Option<String>) -> String {
match optional_region {
Some(region_arg) => {
info!("Using region: {}", region_arg);
region_arg
}
None => "".to_owned(),
}
optional_region.map_or_else(String::new, |region_arg| {
info!("Using region: {}", region_arg);
region_arg
})
}

fn set_api_url(optional_url: Option<String>) -> String {
match optional_url {
Some(url_arg) => {
info!("Using API at: {}", url_arg);
url_arg
}
None => {
optional_url.map_or_else(
|| {
let default_url = "https://api.boavizta.org".to_string();
warn!("Using default API at: {}", default_url);
warn!("Using default API at: {default_url}");
default_url
}
}
},
|url_arg| {
info!("Using API at: {}", url_arg);
url_arg
},
)
}

#[tokio::main]
Expand All @@ -126,8 +123,8 @@ async fn main() -> Result<()> {
output_verbose_json,
summary_only,
inventory_file,
} => match inventory_file {
Some(path) => {
} => {
if let Some(path) = inventory_file {
info!("Providing estimation for inventory file");
let i = cloud_scanner_cli::estimate_impacts_of_inventory_file(
&use_duration_hours,
Expand All @@ -137,8 +134,7 @@ async fn main() -> Result<()> {
)
.await?;
println!("{}", serde_json::to_string(&i)?);
}
None => {
} else {
info!("Providing estimation for live inventory");
let i: EstimatedInventory = cloud_scanner_cli::estimate_impacts(
&use_duration_hours,
Expand All @@ -152,9 +148,9 @@ async fn main() -> Result<()> {
let result =
get_estimated_inventory_as_json(&i, &region, &use_duration_hours, summary_only)
.await?;
println!("{}", result);
println!("{result}");
}
},
}
SubCommand::Metrics {
use_duration_hours,
include_block_storage,
Expand All @@ -168,7 +164,7 @@ async fn main() -> Result<()> {
include_block_storage,
)
.await?;
println!("{}", metrics);
println!("{metrics}");
}
SubCommand::Inventory {
include_block_storage,
Expand Down
29 changes: 11 additions & 18 deletions cloud-scanner-cli/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@ mod tests {
},
);

let mut instance1tags: Vec<CloudResourceTag> = Vec::new();
instance1tags.push(CloudResourceTag {
let instance1tags: Vec<CloudResourceTag> = vec![CloudResourceTag {
key: "Name".to_string(),
value: Some("App1".to_string()),
});
}];

let instance1: CloudResource = CloudResource {
provider: CloudProvider::AWS,
Expand All @@ -302,8 +301,7 @@ mod tests {
tags: instance1tags,
};

assert_eq!(
true,
assert!(
instance1.has_matching_tagmap(&filtertags),
"Tags should match"
);
Expand All @@ -317,9 +315,8 @@ mod tests {
value: Some("OtherApp".to_string()),
},
);
assert_eq!(
false,
instance1.has_matching_tagmap(&other_name_tag),
assert!(
!instance1.has_matching_tagmap(&other_name_tag),
"Tags should not match"
);

Expand All @@ -332,9 +329,8 @@ mod tests {
value: Some("PROD".to_string()),
},
);
assert_eq!(
false,
instance1.has_matching_tagmap(&more_tags),
assert!(
!instance1.has_matching_tagmap(&more_tags),
"Tags should not match"
);

Expand All @@ -347,16 +343,14 @@ mod tests {
value: None,
},
);
assert_eq!(
false,
instance1.has_matching_tagmap(&tag_without_val),
assert!(
!instance1.has_matching_tagmap(&tag_without_val),
"Tag without a value should not match"
);

// Trying an empty filter
let empty_filter = HashMap::new();
assert_eq!(
true,
assert!(
instance1.has_matching_tagmap(&empty_filter),
"Tags should match"
);
Expand All @@ -372,8 +366,7 @@ mod tests {
value: Some("whatever".to_string()),
},
);
assert_eq!(
true,
assert!(
instance1.has_matching_tagmap(&empty_filter),
"Tags should match (i.e. we should ignore this invalid filter"
);
Expand Down
Loading