Skip to content

Commit

Permalink
Applied clippy hints (lints)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvkem committed Feb 10, 2024
1 parent 37fc3f9 commit 91c5901
Show file tree
Hide file tree
Showing 44 changed files with 129 additions and 167 deletions.
1 change: 1 addition & 0 deletions src/graph/process_node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::stats::call_chain::{Call, CallChain, CallDirection};
use std::{collections::HashMap, iter};

#[allow(dead_code)] // enum might have unused variants
#[derive(Default, Debug)]
pub enum ProcessNodeType {
/// represents a process that is directly exposed (via an API gateway), so this is the starting point of a service-process
Expand Down
6 changes: 3 additions & 3 deletions src/main/mermaid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ struct Args {
scope: MermaidScope,
}

fn to_opt_str(s: &String) -> Option<&str> {
if &s[..] != EMPTY_ARG {
Some(s.as_str())
fn to_opt_str(s: &str) -> Option<&str> {
if s != EMPTY_ARG {
Some(s)
} else {
None
}
Expand Down
1 change: 0 additions & 1 deletion src/main/show_traces.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::Parser;
use jaeger_stats;
use std::path::Path;

/// Show the Jaeger-traces, or a selection of jaeger-traces, as Pretty-printed JSON in UTF-8 format.
Expand Down
6 changes: 3 additions & 3 deletions src/main/trace_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ struct Args {
display_call_chain: String,
}

fn to_opt_str(s: &String) -> Option<&str> {
if &s[..] != EMPTY_ARG {
Some(s.as_str())
fn to_opt_str(s: &str) -> Option<&str> {
if s != EMPTY_ARG {
Some(s)
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/mermaid/flowchart/escape_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const REPLACE_CHAR: &str = "_";

/// escape a name such that it can be used as valid Mermaid label if the current input can not be used as label, otherwise None
pub fn escape_mermaid_label(name: &str) -> Option<String> {
if name.contains(&TO_REPLACE) {
Some(name.replace(&TO_REPLACE, REPLACE_CHAR))
if name.contains(TO_REPLACE) {
Some(name.replace(TO_REPLACE, REPLACE_CHAR))
} else {
None
}
Expand Down
7 changes: 2 additions & 5 deletions src/mermaid/flowchart/mermaid.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::{
super::service_oper_graph::LinkType,
basic_node::MermaidBasicNode,
link::MermaidLink,
node::MermaidNode,
sub_graph::MermaidSubGraph,
super::service_oper_graph::LinkType, basic_node::MermaidBasicNode, link::MermaidLink,
node::MermaidNode, sub_graph::MermaidSubGraph,
};

pub struct Mermaid {
Expand Down
2 changes: 1 addition & 1 deletion src/mermaid/service_oper_graph/compact_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ impl<'a> CompactLink<'a> {
self.0
.entry(key)
.and_modify(|value| value.merge(c_value))
.or_insert(c_value.clone());
.or_insert(c_value);
}
}
2 changes: 1 addition & 1 deletion src/mermaid/service_oper_graph/edge_value_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub type EdgeValueSelector = fn(Option<&CallDescriptorStats>) -> Option<f64>;

pub fn edge_value_to_selector(edge_value: EdgeValue) -> EdgeValueSelector {
match edge_value {
EdgeValue::Count => |cds| cds.and_then(|ips| Some(ips.count as f64)),
EdgeValue::Count => |cds| cds.map(|ips| ips.count as f64),
EdgeValue::AvgMillis => |cds| cds.and_then(|ips| ips.avg_duration_millis.get_value()),
EdgeValue::P75Millis => |cds| cds.and_then(|ips| ips.p75_millis.get_value()),
EdgeValue::P90Millis => |cds| cds.and_then(|ips| ips.p90_millis.get_value()),
Expand Down
4 changes: 2 additions & 2 deletions src/mermaid/service_oper_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ mod node_select;
mod operation;
mod position;
mod service;
mod service_oper_graph;
mod service_oper_type;
mod sog;

pub use link_type::LinkType;
pub use position::Position;
pub use service_oper_graph::ServiceOperGraph;
pub use service_oper_type::ServiceOperationType;
pub use sog::ServiceOperGraph;
24 changes: 15 additions & 9 deletions src/mermaid/service_oper_graph/node_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ pub type NodeSelector = fn(&Service) -> bool;
pub fn scope_to_node_selector(scope: MermaidScope) -> NodeSelector {
match scope {
MermaidScope::Full => |_service| true,
MermaidScope::Centered => |service| match service.position {
super::Position::Center | Position::InboundCenter | Position::OutboundCenter => true,
_ => false,
MermaidScope::Centered => |service| {
matches!(
service.position,
|super::Position::Center| Position::InboundCenter | Position::OutboundCenter,
)
},
MermaidScope::Inbound => |service| match service.position {
super::Position::Center | super::Position::Inbound | Position::InboundCenter => true,
_ => false,
MermaidScope::Inbound => |service| {
matches!(
service.position,
|super::Position::Center| super::Position::Inbound | Position::InboundCenter,
)
},
MermaidScope::Outbound => |service| match service.position {
super::Position::Center | super::Position::Outbound | Position::OutboundCenter => true,
_ => false,
MermaidScope::Outbound => |service| {
matches!(
service.position,
|super::Position::Center| super::Position::Outbound | Position::OutboundCenter,
)
},
}
}
3 changes: 2 additions & 1 deletion src/mermaid/service_oper_graph/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::stats::call_chain::Call;
/// These output formats are needed:
/// * to prevent that views grow to large to be visible (easy zooming in on the relevant parts)
/// * to allow for generation of tailored diagrams for inclusion in architect documentation.
#[allow(dead_code)] // might contain unused variants
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Position {
Unknown, // or do not change position
Expand All @@ -31,7 +32,7 @@ impl Position {
(true, true) => (Position::Center, Position::Center),
(true, false) => (Position::Center, Position::OutboundCenter),
(false, true) => (Position::InboundCenter, Position::Center),
(false, false) => (default_pos.clone(), default_pos),
(false, false) => (default_pos, default_pos),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mermaid/service_oper_graph/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use super::{
node_select::NodeSelector,
operation::Operation,
position::Position,
service_oper_graph::ServiceOperGraph,
service_oper_type::ServiceOperationType,
sog::ServiceOperGraph,
};
use crate::{stats::call_chain::CallDirection};
use crate::stats::call_chain::CallDirection;

#[derive(Debug)]
pub struct Service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ impl ServiceOperGraph {
/// find the Service-Operation combination, and return the index-pair as a Location in the ServiceOperGraph or None
fn get_service_operation_idx(&self, call: &Call) -> Option<Loc> {
match self.get_service_idx(&call.service) {
Some(serv_idx) => match self.0[serv_idx]
Some(serv_idx) => self.0[serv_idx]
.operations
.iter()
.position(|o| o.oper == call.operation)
{
Some(oper_idx) => Some(Loc {
.map(|oper_idx| Loc {
service_idx: serv_idx,
oper_idx,
}),
None => None,
},
None => None,
}
}
Expand Down Expand Up @@ -96,9 +93,9 @@ impl ServiceOperGraph {
default_pos: Position,
) {
// determine the from and to and add them if they do not exist
let (from_pos, to_pos) = Position::find_positions(&from, &to, service, default_pos);
let from = self.get_create_service_operation_idx(&from, from_pos);
let to = self.get_create_service_operation_idx(&to, to_pos);
let (from_pos, to_pos) = Position::find_positions(from, to, service, default_pos);
let from = self.get_create_service_operation_idx(from, from_pos);
let to = self.get_create_service_operation_idx(to, to_pos);
// Add new link or update the existing link with the data
self.0[from.service_idx].operations[from.oper_idx].upsert_link(to, data)
}
Expand Down
5 changes: 3 additions & 2 deletions src/mermaid/trace_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ pub struct TraceData {
}

impl TraceData {
#[allow(clippy::too_many_arguments)]
pub fn new(
full_key: &String,
full_key: &str,
rooted: bool,
is_leaf: bool,
count: u64,
Expand All @@ -49,7 +50,7 @@ impl TraceData {
p95_millis: Option<f64>,
p99_millis: Option<f64>,
) -> Self {
let full_key = full_key.clone();
let full_key = full_key.to_owned();
let trace_path = CChainStatsKey::parse(&full_key).unwrap_or_else(|err| {
panic!("Failed to parse CChainKey: '{full_key}'\nGot error '{err:?}'")
});
Expand Down
3 changes: 1 addition & 2 deletions src/mermaid/trace_forrest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl<'a> TraceForrest<'a> {
self.0
.iter()
.enumerate()
.filter(|(_, tn)| tn.service == call.service && tn.operation == call.operation)
.next()
.find(|(_, tn)| tn.service == call.service && tn.operation == call.operation)
.map(|(idx, _tn)| idx)
}

Expand Down
4 changes: 2 additions & 2 deletions src/mermaid/trace_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TracePaths {
let call_chain = &ccd.trace_path.call_chain;
if call_chain.len() >= 2 {
let skip = call_chain.len() - 2;
let mut cc = call_chain.into_iter().skip(skip);
let mut cc = call_chain.iter().skip(skip);
let from = cc.next().unwrap();
let to = cc.next().unwrap();

Expand All @@ -98,7 +98,7 @@ impl TracePaths {
};
sog
// TODO: remove the clone operations (and fix downstream)
.add_connection(&from, &to, edge_data, service, default_pos);
.add_connection(from, to, edge_data, service, default_pos);
sog
},
);
Expand Down
5 changes: 2 additions & 3 deletions src/mermaid/tt_utils.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use super::service_oper_graph::{LinkType, ServiceOperGraph};
use crate::stats::CChainStatsKey;
use regex;

// split a service out of a service-oper string by spitting at the '/' (or returning the full str if no '/' is present)
pub fn split_service(service_oper: &str) -> &str {
service_oper.split("/").next().unwrap()
service_oper.split('/').next().unwrap()
}

// split a a service-oper string by spitting at the '/' and returnning the tuple `(service, Some(operation))` (or returning the `(Service, None)`` if no '/' is present)
pub fn split_service_operation(service_oper: &str) -> (&str, Option<&str>) {
let mut parts = service_oper.split("/");
let mut parts = service_oper.split('/');
let service = parts.next().unwrap();
let oper_opt = parts.next();
(service, oper_opt)
Expand Down
2 changes: 1 addition & 1 deletion src/processed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod trace;
mod unify_operation;

pub use self::{
span::{set_max_log_msg_length, Span, Spans},
span::{Span, Spans},
trace::{extract_traces, Trace},
};
4 changes: 2 additions & 2 deletions src/raw/file_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ impl FileTracker {
!self.files.is_empty(),
"Add at least one filename before getting an index"
);
self.files.len() as usize - 1
self.files.len() - 1
}

#[allow(dead_code)]
#[allow(dead_code)]
pub fn get_file_name(&self, idx: usize) -> String {
assert!(idx < self.files.len(), "Index out of bounds");
self.files[idx].to_owned()
Expand Down
3 changes: 1 addition & 2 deletions src/raw/jaeger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ pub struct JaegerTrace {
impl JaegerTrace {
/// Build a JaegerTrace with a single JaegerItem in it (so a single TraceId)
pub fn new(ji: JaegerItem) -> Self {
let mut data = Vec::with_capacity(1);
data.push(ji);
let data = vec![ji];

JaegerTrace {
data,
Expand Down
5 changes: 2 additions & 3 deletions src/raw/read_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ fn extract_jaeger_traces(jt: JaegerTrace) -> Vec<JaegerTrace> {
Some(err) if err.is_empty() => (),
Some(err) => {
// TODO: send this to the report file instead of just console
println!("Discovered errors: {err:?}");
()
println!("Discovered errors: {err:?}")
}
};

jt.data.into_iter().map(|ji| JaegerTrace::new(ji)).collect()
jt.data.into_iter().map(JaegerTrace::new).collect()
}

/// read a series of raw Jaeger-traces from a file or a folder
Expand Down
14 changes: 4 additions & 10 deletions src/raw/write.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use super::JaegerTrace;
use crate::utils;
use serde_json;
use std::{
collections::HashSet,
fs::File,
io::Write,
path::{Path, PathBuf},
};
use std::{collections::HashSet, fs::File, io::Write, path::Path};

/// write a single trace as a pretty-printed json to a folder given in 'path' and use the trace_id as the file_base.
fn write_trace(trace_folder: &PathBuf, jt: &JaegerTrace) {
fn write_trace(trace_folder: &Path, jt: &JaegerTrace) {
assert!(!jt.data.is_empty(), "Can not write an empty JaegerTrace");
let file_path = {
let file_name = format!("{}.json", jt.data[0].traceID);
let mut trace_folder = trace_folder.clone();
let mut trace_folder = trace_folder.to_path_buf();
trace_folder.push(file_name);
trace_folder.into_os_string()
};
Expand Down Expand Up @@ -47,7 +41,7 @@ fn write_trace(trace_folder: &PathBuf, jt: &JaegerTrace) {
pub fn write_traces(folder: &Path, traces: Vec<JaegerTrace>, trace_ids: &str) -> u32 {
let trace_ids: HashSet<String> = trace_ids
.split(',')
.filter(|s| *s != "") // drop the empty strings
.filter(|s| !s.is_empty()) // drop the empty strings
.map(|s| s.to_owned())
.collect();
let selected = |jt: &&JaegerTrace| {
Expand Down
15 changes: 6 additions & 9 deletions src/stats/call_chain/cchain_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,12 @@ impl CChainEndPointCache {
impl Drop for CChainEndPointCache {
/// write all dirty cache entries to a file
fn drop(&mut self) {
mem::take(&mut self.cache)
.into_iter()
.for_each(|(k, v)| match v {
Some(v) => {
if v.is_dirty() {
v.write_call_chain(self.path.clone(), &k);
}
mem::take(&mut self.cache).into_iter().for_each(|(k, v)| {
if let Some(v) = v {
if v.is_dirty() {
v.write_call_chain(self.path.clone(), &k);
}
None => (),
});
}
});
}
}
2 changes: 1 addition & 1 deletion src/stats/call_chain/cchain_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl CChainStatsKey {
.map(|call| call.get_process_method())
.collect::<Vec<_>>()
.join(", ");
if key.is_empty() && self.call_chain.len() > 0 {
if key.is_empty() && !self.call_chain.is_empty() {
// if string is empty but call-chain is not we show the first call (the api-gateway call that apparantly is not marked as inbound)
self.call_chain[0].get_process_method()
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/stats/call_chain/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn read_cchain_file(path: &Path) -> Result<EndPointCChains, Box<dyn Error>>
}

/// the label shows whether cached processes are in the call-chain and if so returns a suffix to represent it.
pub fn caching_process_label(caching_process: &Vec<String>, call_chain: &CallChain) -> String {
pub fn caching_process_label(caching_process: &[String], call_chain: &CallChain) -> String {
if caching_process.is_empty() {
return "".to_owned();
}
Expand Down
6 changes: 3 additions & 3 deletions src/stats/operation_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl OperationStats {
idx: usize,
span: &Span,
spans: &Spans,
caching_process: &Vec<String>,
caching_process: &[String],
root_call: &str,
) {
match &span.span_kind {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl OperationStats {
self.operation
.0
.entry(method.to_owned())
.and_modify(|oper_stat| update_proc_oper_value(oper_stat))
.and_modify(update_proc_oper_value)
.or_insert_with(|| {
let mut oper_stat = ProcOperStatsValue::default();
update_proc_oper_value(&mut oper_stat);
Expand Down Expand Up @@ -133,7 +133,7 @@ impl OperationStats {
.0
.entry(ps_key)
// next part could be made more dry via an update-closure
.and_modify(|ps| update_ps_val(ps))
.and_modify(update_ps_val)
.or_insert_with(|| {
let mut ps = CChainStatsValue::new(depth, looped, rooted);
update_ps_val(&mut ps);
Expand Down
Loading

0 comments on commit 91c5901

Please sign in to comment.