Skip to content

Commit

Permalink
fix import and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgallotta committed Nov 15, 2024
1 parent 6fd20ad commit 7128ed8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bottlecap/src/lifecycle/invocation/span_inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::lifecycle::invocation::{
lambda_function_url_event::LambdaFunctionUrlEvent,

Check warning on line 17 in bottlecap/src/lifecycle/invocation/span_inferrer.rs

View workflow job for this annotation

GitHub Actions / Format (ubuntu-22.04)

Diff in /home/runner/work/datadog-lambda-extension/datadog-lambda-extension/bottlecap/src/lifecycle/invocation/span_inferrer.rs
s3_event::S3Record,
sns_event::{SnsEntity, SnsRecord},
sqs_event::SqsRecord,
sqs_event::{SqsRecord, extract_trace_context_from_aws_trace_header},
step_function_event::StepFunctionEvent,
Trigger, FUNCTION_TRIGGER_EVENT_SOURCE_ARN_TAG,
},
Expand Down
44 changes: 21 additions & 23 deletions bottlecap/src/proc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ mod tests {
use super::*;
use std::path::PathBuf;

const PRECISION: f64 = 1e-6;

fn path_from_root(file: &str) -> String {
let mut safe_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
safe_path.push(file);
Expand All @@ -341,7 +339,7 @@ mod tests {
#[test]
fn test_get_pid_list() {
let path = "./tests/proc";
let mut pids = get_pid_list_from_path(path);
let mut pids = get_pid_list_from_path(path_from_root(path).as_str());
pids.sort();
assert_eq!(pids.len(), 2);
assert_eq!(pids[0], 13);
Expand All @@ -358,8 +356,8 @@ mod tests {
let network_data_result = get_network_data_from_path(path_from_root(path).as_str());
assert!(network_data_result.is_ok());
let network_data = network_data_result.unwrap();
assert!((network_data.rx_bytes - 180.0).abs() < PRECISION);
assert!((network_data.tx_bytes - 254.0).abs() < PRECISION);
assert!((network_data.rx_bytes - 180.0).abs() < f64::EPSILON);
assert!((network_data.tx_bytes - 254.0).abs() < f64::EPSILON);

let path = "./tests/proc/net/invalid_dev_malformed";
let network_data_result = get_network_data_from_path(path);
Expand All @@ -384,9 +382,9 @@ mod tests {
let cpu_data_result = get_cpu_data_from_path(path_from_root(path).as_str());
assert!(cpu_data_result.is_ok());
let cpu_data = cpu_data_result.unwrap();
assert!((cpu_data.total_user_time_ms - 23370.0).abs() < PRECISION);
assert!((cpu_data.total_system_time_ms - 1880.0).abs() < PRECISION);
assert!((cpu_data.total_idle_time_ms - 178_380.0).abs() < PRECISION);
assert!((cpu_data.total_user_time_ms - 23370.0).abs() < f64::EPSILON);
assert!((cpu_data.total_system_time_ms - 1880.0).abs() < f64::EPSILON);
assert!((cpu_data.total_idle_time_ms - 178_380.0).abs() < f64::EPSILON);
assert_eq!(cpu_data.individual_cpu_idle_times.len(), 2);
assert!(
(*cpu_data
Expand All @@ -395,7 +393,7 @@ mod tests {
.expect("cpu0 not found")
- 91880.0)
.abs()
< PRECISION
< f64::EPSILON
);
assert!(
(*cpu_data
Expand All @@ -404,7 +402,7 @@ mod tests {
.expect("cpu1 not found")
- 86490.0)
.abs()
< PRECISION
< f64::EPSILON
);

let path = "./tests/proc/stat/invalid_stat_non_numerical_value_1";
Expand Down Expand Up @@ -438,7 +436,7 @@ mod tests {
let uptime_data_result = get_uptime_from_path(path_from_root(path).as_str());
assert!(uptime_data_result.is_ok());
let uptime_data = uptime_data_result.unwrap();
assert!((uptime_data - 3_213_103_123_000.0).abs() < PRECISION);
assert!((uptime_data - 3_213_103_123_000.0).abs() < f64::EPSILON);

let path = "./tests/proc/uptime/invalid_data_uptime";
let uptime_data_result = get_uptime_from_path(path);
Expand All @@ -456,29 +454,29 @@ mod tests {
#[test]
fn test_get_fd_max_data() {
let path = "./tests/proc/process/valid";
let pids = get_pid_list_from_path(path);
let pids = get_pid_list_from_path(path_from_root(path).as_str());
let fd_max = get_fd_max_data_from_path(path, &pids);
assert!((fd_max - 900.0).abs() < PRECISION);
assert!((fd_max - 900.0).abs() < f64::EPSILON);

let path = "./tests/proc/process/invalid_malformed";
let fd_max = get_fd_max_data_from_path(path, &pids);
// assert that fd_max is equal to AWS Lambda limit
assert!((fd_max - constants::LAMBDA_FILE_DESCRIPTORS_DEFAULT_LIMIT).abs() < PRECISION);
assert!((fd_max - constants::LAMBDA_FILE_DESCRIPTORS_DEFAULT_LIMIT).abs() < f64::EPSILON);

let path = "./tests/proc/process/invalid_missing";
let fd_max = get_fd_max_data_from_path(path, &pids);
// assert that fd_max is equal to AWS Lambda limit
assert!((fd_max - constants::LAMBDA_FILE_DESCRIPTORS_DEFAULT_LIMIT).abs() < PRECISION);
assert!((fd_max - constants::LAMBDA_FILE_DESCRIPTORS_DEFAULT_LIMIT).abs() < f64::EPSILON);
}

#[test]
fn test_get_fd_use_data() {
let path = "./tests/proc/process/valid";
let pids = get_pid_list_from_path(path);
let pids = get_pid_list_from_path(path_from_root(path).as_str());
let fd_use_result = get_fd_use_data_from_path(path, &pids);
assert!(fd_use_result.is_ok());
let fd_use = fd_use_result.unwrap();
assert!((fd_use - 5.0).abs() < PRECISION);
assert!((fd_use - 5.0).abs() < f64::EPSILON);

let path = "./tests/proc/process/invalid_missing";
let fd_use_result = get_fd_use_data_from_path(path, &pids);
Expand All @@ -488,33 +486,33 @@ mod tests {
#[test]
fn test_get_threads_max_data() {
let path = "./tests/proc/process/valid";
let pids = get_pid_list_from_path(path);
let pids = get_pid_list_from_path(path_from_root(path).as_str());
let threads_max = get_threads_max_data_from_path(path, &pids);
assert!((threads_max - 1024.0).abs() < PRECISION);
assert!((threads_max - 1024.0).abs() < f64::EPSILON);

let path = "./tests/proc/process/invalid_malformed";
let threads_max = get_threads_max_data_from_path(path, &pids);

Check warning on line 494 in bottlecap/src/proc/mod.rs

View workflow job for this annotation

GitHub Actions / Format (ubuntu-22.04)

Diff in /home/runner/work/datadog-lambda-extension/datadog-lambda-extension/bottlecap/src/proc/mod.rs
// assert that threads_max is equal to AWS Lambda limit
assert!(
(threads_max - constants::LAMBDA_EXECUTION_PROCESSES_DEFAULT_LIMIT).abs() < PRECISION
(threads_max - constants::LAMBDA_EXECUTION_PROCESSES_DEFAULT_LIMIT).abs() < f64::EPSILON
);

let path = "./tests/proc/process/invalid_missing";
let threads_max = get_threads_max_data_from_path(path, &pids);

Check warning on line 501 in bottlecap/src/proc/mod.rs

View workflow job for this annotation

GitHub Actions / Format (ubuntu-22.04)

Diff in /home/runner/work/datadog-lambda-extension/datadog-lambda-extension/bottlecap/src/proc/mod.rs
// assert that threads_max is equal to AWS Lambda limit
assert!(
(threads_max - constants::LAMBDA_EXECUTION_PROCESSES_DEFAULT_LIMIT).abs() < PRECISION
(threads_max - constants::LAMBDA_EXECUTION_PROCESSES_DEFAULT_LIMIT).abs() < f64::EPSILON
);
}

#[test]
fn test_get_threads_use_data() {
let path = "./tests/proc/process/valid";
let pids = get_pid_list_from_path(path);
let pids = get_pid_list_from_path(path_from_root(path).as_str());
let threads_use_result = get_threads_use_data_from_path(path, &pids);
assert!(threads_use_result.is_ok());
let threads_use = threads_use_result.unwrap();
assert!((threads_use - 5.0).abs() < PRECISION);
assert!((threads_use - 5.0).abs() < f64::EPSILON);

let path = "./tests/proc/process/invalid_missing";
let threads_use_result = get_threads_use_data_from_path(path, &pids);
Expand Down

0 comments on commit 7128ed8

Please sign in to comment.