Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgallotta committed Nov 15, 2024
1 parent 4abd3a9 commit 6fd20ad
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 40 deletions.
46 changes: 24 additions & 22 deletions bottlecap/src/lifecycle/invocation/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl ContextBuffer {
/// Creates a new `Context` and adds it to the buffer.
///
pub fn create_context(&mut self, request_id: String) {
self.insert(Context::new(request_id, 0.0, 0.0, 0, None));
self.insert(Context::new(request_id, 0f64, 0f64, 0, None));
}

/// Adds the init duration to a `Context` in the buffer.
Expand Down Expand Up @@ -188,20 +188,20 @@ mod tests {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

let request_id_2 = String::from("2");
let context = Context::new(request_id_2.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id_2.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 2);
assert_eq!(buffer.get(&request_id_2).unwrap(), &context);

// This should replace the first context
let request_id_3 = String::from("3");
let context = Context::new(request_id_3.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id_3.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 2);
assert_eq!(buffer.get(&request_id_3).unwrap(), &context);
Expand All @@ -215,13 +215,13 @@ mod tests {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

let request_id_2 = String::from("2");
let context = Context::new(request_id_2.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id_2.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 2);
assert_eq!(buffer.get(&request_id_2).unwrap(), &context);
Expand All @@ -242,13 +242,13 @@ mod tests {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

let request_id_2 = String::from("2");
let context = Context::new(request_id_2.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id_2.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 2);
assert_eq!(buffer.get(&request_id_2).unwrap(), &context);
Expand All @@ -263,21 +263,21 @@ mod tests {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

buffer.add_init_duration(&request_id, 100.0);
assert_eq!(buffer.get(&request_id).unwrap().init_duration_ms, 100.0);
buffer.add_init_duration(&request_id, 100f64);
assert!((buffer.get(&request_id).unwrap().init_duration_ms - 100f64).abs() < f64::EPSILON);
}

#[test]
fn test_add_start_time() {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);
Expand All @@ -291,41 +291,43 @@ mod tests {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

buffer.add_runtime_duration(&request_id, 100.0);
assert_eq!(buffer.get(&request_id).unwrap().runtime_duration_ms, 100.0);
buffer.add_runtime_duration(&request_id, 100f64);
assert!(
(buffer.get(&request_id).unwrap().runtime_duration_ms - 100f64).abs() < f64::EPSILON
);
}

#[test]
fn test_add_enhanced_metric_data() {
let mut buffer = ContextBuffer::with_capacity(2);

let request_id = String::from("1");
let context = Context::new(request_id.clone(), 0.0, 0.0, 0, None);
let context = Context::new(request_id.clone(), 0f64, 0f64, 0, None);
buffer.insert(context.clone());
assert_eq!(buffer.size(), 1);
assert_eq!(buffer.get(&request_id).unwrap(), &context);

let network_offset = Some(NetworkData {
rx_bytes: 180.0,
rx_bytes: 180f64,
tx_bytes: 254.0,
});

let mut individual_cpu_idle_times = HashMap::new();
individual_cpu_idle_times.insert("cpu0".to_string(), 10.0);
individual_cpu_idle_times.insert("cpu1".to_string(), 20.0);
individual_cpu_idle_times.insert("cpu0".to_string(), 10f64);
individual_cpu_idle_times.insert("cpu1".to_string(), 20f64);
let cpu_offset = Some(CPUData {
total_user_time_ms: 100.0,
total_user_time_ms: 100f64,
total_system_time_ms: 53.0,
total_idle_time_ms: 20.0,
total_idle_time_ms: 20f64,
individual_cpu_idle_times,
});

let uptime_offset = Some(50.0);
let uptime_offset = Some(50f64);
let (tmp_chan_tx, _) = watch::channel(());
let (process_chan_tx, _) = watch::channel(());

Expand Down
1 change: 1 addition & 0 deletions bottlecap/src/lifecycle/invocation/triggers/s3_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl ServiceNameResolver for S3Record {
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use crate::lifecycle::invocation::triggers::test_utils::read_json_file;
Expand Down
1 change: 1 addition & 0 deletions bottlecap/src/lifecycle/invocation/triggers/sns_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl ServiceNameResolver for SnsRecord {
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use datadog_trace_protobuf::pb::Span;

Expand Down
1 change: 1 addition & 0 deletions bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ pub(crate) fn extract_trace_context_from_aws_trace_header(


#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use crate::lifecycle::invocation::triggers::test_utils::read_json_file;
Expand Down
48 changes: 30 additions & 18 deletions bottlecap/src/traces/propagation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,13 @@ pub mod tests {

use super::*;

fn lower_64_bits(value: u128) -> u64 {
(value & 0xFFFF_FFFF_FFFF_FFFF) as u64
}

lazy_static! {
static ref TRACE_ID: u128 = 171_395_628_812_617_415_352_188_477_958_425_669_623;
static ref TRACE_ID_LOWER_ORDER_BITS: u64 = *TRACE_ID as u64;
static ref TRACE_ID_LOWER_ORDER_BITS: u64 = lower_64_bits(*TRACE_ID);
static ref TRACE_ID_HEX: String = String::from("80f198ee56343ba864fe8b2a57d3eff7");

// TraceContext Headers
Expand Down Expand Up @@ -771,13 +775,15 @@ pub mod tests {

#[test]
fn test_new_filter_propagators() {
let mut config = config::Config::default();
config.trace_propagation_style_extract = vec![
TracePropagationStyle::Datadog,
TracePropagationStyle::TraceContext,
TracePropagationStyle::B3,
TracePropagationStyle::B3Multi,
];
let config = config::Config {
trace_propagation_style_extract: vec![
TracePropagationStyle::Datadog,
TracePropagationStyle::TraceContext,
TracePropagationStyle::B3,
TracePropagationStyle::B3Multi,
],
..Default::default()
};

let propagator = DatadogCompositePropagator::new(Arc::new(config));

Expand All @@ -786,20 +792,24 @@ pub mod tests {

#[test]
fn test_new_no_propagators() {
let mut config = config::Config::default();
config.trace_propagation_style_extract = vec![TracePropagationStyle::None];
let config = config::Config {
trace_propagation_style_extract: vec![TracePropagationStyle::None],
..Default::default()
};
let propagator = DatadogCompositePropagator::new(Arc::new(config));

assert_eq!(propagator.propagators.len(), 0);
}

#[test]
fn test_extract_available_contexts() {
let mut config = config::Config::default();
config.trace_propagation_style_extract = vec![
TracePropagationStyle::Datadog,
TracePropagationStyle::TraceContext,
];
let config = config::Config {
trace_propagation_style_extract: vec![
TracePropagationStyle::Datadog,
TracePropagationStyle::TraceContext,
],
..Default::default()
};

let propagator = DatadogCompositePropagator::new(Arc::new(config));

Expand Down Expand Up @@ -835,8 +845,10 @@ pub mod tests {

#[test]
fn test_extract_available_contexts_no_contexts() {
let mut config = config::Config::default();
config.trace_propagation_style_extract = vec![TracePropagationStyle::Datadog];
let config = config::Config {
trace_propagation_style_extract: vec![TracePropagationStyle::Datadog],
..Default::default()
};

let propagator = DatadogCompositePropagator::new(Arc::new(config));

Expand Down Expand Up @@ -868,6 +880,6 @@ pub mod tests {
DatadogCompositePropagator::attach_baggage(&mut context, &carrier);

assert_eq!(context.tags.len(), 1);
assert_eq!(context.tags.get("key1").unwrap(), "value1");
assert_eq!(context.tags.get("key1").expect("Missing tag"), "value1");
}
}
1 change: 1 addition & 0 deletions bottlecap/src/traces/propagation/text_map_propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ impl TraceContextPropagator {
}

#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod test {
use super::*;

Expand Down

0 comments on commit 6fd20ad

Please sign in to comment.