diff --git a/bottlecap/src/lifecycle/invocation/context.rs b/bottlecap/src/lifecycle/invocation/context.rs index 680a967b..97e6bbf1 100644 --- a/bottlecap/src/lifecycle/invocation/context.rs +++ b/bottlecap/src/lifecycle/invocation/context.rs @@ -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. @@ -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); @@ -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); @@ -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); @@ -263,13 +263,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); - 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] @@ -277,7 +277,7 @@ 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); @@ -291,13 +291,15 @@ 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] @@ -305,27 +307,27 @@ 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 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(()); diff --git a/bottlecap/src/lifecycle/invocation/triggers/s3_event.rs b/bottlecap/src/lifecycle/invocation/triggers/s3_event.rs index d45dc1f5..43065cb0 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/s3_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/s3_event.rs @@ -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; diff --git a/bottlecap/src/lifecycle/invocation/triggers/sns_event.rs b/bottlecap/src/lifecycle/invocation/triggers/sns_event.rs index 47091a9d..091dcdf5 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/sns_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/sns_event.rs @@ -174,6 +174,7 @@ impl ServiceNameResolver for SnsRecord { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod tests { use datadog_trace_protobuf::pb::Span; diff --git a/bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs b/bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs index 5bbcc3e0..90547a01 100644 --- a/bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs +++ b/bottlecap/src/lifecycle/invocation/triggers/sqs_event.rs @@ -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; diff --git a/bottlecap/src/traces/propagation/mod.rs b/bottlecap/src/traces/propagation/mod.rs index 72366640..300e6eff 100644 --- a/bottlecap/src/traces/propagation/mod.rs +++ b/bottlecap/src/traces/propagation/mod.rs @@ -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 @@ -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)); @@ -786,8 +792,10 @@ 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); @@ -795,11 +803,13 @@ pub mod tests { #[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)); @@ -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)); @@ -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"); } } diff --git a/bottlecap/src/traces/propagation/text_map_propagator.rs b/bottlecap/src/traces/propagation/text_map_propagator.rs index f1c5cbcf..52042863 100644 --- a/bottlecap/src/traces/propagation/text_map_propagator.rs +++ b/bottlecap/src/traces/propagation/text_map_propagator.rs @@ -456,6 +456,7 @@ impl TraceContextPropagator { } #[cfg(test)] +#[allow(clippy::unwrap_used)] mod test { use super::*;