Skip to content

Commit

Permalink
Fixed mermaid for stitched-data
Browse files Browse the repository at this point in the history
  • Loading branch information
cvkem committed Apr 21, 2024
1 parent 49658b0 commit 7bb30d8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/main/mermaid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn main() {
);
write_diagram(&folder, &args.service_oper, mermaid);
}
Err(err) => panic!("Reading '{}' failed with error: {err:?}", args.input),
Err(err) => panic!("Reading '{}' failed with error: {err:?}\nNOTE: Raw trace-json is not a valid input. You need data as returned by either 'trace_analysis' or 'stitch'.", args.input),
}

// PREVIOUS VERSION that only supported single format
Expand Down
1 change: 1 addition & 0 deletions src/mermaid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ mod tt_utils;

pub use trace_data::TraceData;
pub use trace_paths::TracePaths;
pub use tt_utils::split_service_operation;
58 changes: 8 additions & 50 deletions src/stitch/api/stitched_data_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ use super::{
utils,
};
use crate::{
mermaid,
view_api::types::{ChartDataParameters, ProcessList, Selection, Table},
MermaidScope, Metric, TraceScope, ViewError, Viewer,
view_api::types::{ChartDataParameters, ProcessList, Selection, Table},
MermaidScope,
Metric,
TraceScope,
ViewError,
Viewer
};
use log::{error, info};
use std::{path::Path, sync::Arc};
Expand Down Expand Up @@ -106,54 +109,9 @@ impl Viewer for StitchedDataSet {
scope: MermaidScope,
compact: bool,
) -> String {
let trace_tree = self
self
.current
.call_chain
.iter()
.map(|(k, ccd)| {
/// TODO: it seems that we need an additional step to cummulate to Service (instead of Service_oper)
let trace_data = ccd
.iter()
.map(|ccd| {
let count: u64 = ccd
.data
.0
.first()
.and_then(|data| data.data_avg)
.unwrap()
.round() as u64;
let avg_duration_millis = ccd
.data
.0
.iter()
.find(|x| x.metric == Metric::AvgDurationMillis)
.and_then(|data| data.data_avg)
.expect("avg-duration missing");
mermaid::TraceData::new(
&ccd.full_key,
ccd.rooted,
ccd.is_leaf,
count,
//TODO: some more parameters need to be passed.
None,
avg_duration_millis,
None,
None,
None,
None,
)
})
.collect();
(k.clone(), trace_data)
})
.collect();
mermaid::TracePaths(trace_tree).get_diagram(
service_oper,
call_chain_key,
edge_value,
scope,
compact,
)
.get_mermaid_diagram(service_oper, call_chain_key, edge_value, scope, compact)
}

fn get_call_chain_chart_data(
Expand Down
79 changes: 78 additions & 1 deletion src/stitch/stitched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::{collections::HashMap, error::Error, fs, io};

use crate::{
string_hash,
Metric,
MermaidScope,
mermaid,
utils::{self, CsvFileBuffer},
view_api::Version,
ServiceOperString, StitchList,
Expand Down Expand Up @@ -201,7 +204,6 @@ impl Stitched {
if CHECK_WRITTEN_FILE {
println!("the basic items are: {:?}", self.basic);

use crate::Metric;
println!(" And specificaly 'NumFixes': {:?}", self.basic.0.iter().find(|stitched_line| stitched_line.metric == Metric::NumFixes));

println!("\n\nFile written, now checking whether we can read it.");
Expand Down Expand Up @@ -462,6 +464,81 @@ impl Stitched {
mem::take(&mut self.service_operation).into_iter().collect()
}

/// get a mermaid diagram that depicts the this stitched dataset based on proc_oper and optionally a call-chain.
pub fn get_mermaid_diagram(
&self,
service_oper: &str,
call_chain_key: Option<&str>,
edge_value: Metric,
scope: MermaidScope,
compact: bool,
) -> String {
// bundle all data that corresponds to the same Service (currently grouped by Service-operation)
let mut grouped_cc: HashMap<&str, Vec<&Vec<_>>> = HashMap::new();
self
.call_chain
.iter()
.for_each(|(service_oper, v)| {
let (service, oper_opt) = mermaid::split_service_operation(service_oper);
grouped_cc
.entry(service)
.and_modify(|values| values.push(&v))
.or_insert([v].to_vec());
});


let trace_tree = grouped_cc
.into_iter()
.map(|(service, ccd_vv)| {
// TODO: it seems that we need an additional step to cummulate to Service (instead of Service_oper)
let trace_data = ccd_vv
.into_iter()
.flat_map(|ccd_v| {
ccd_v
.iter()
.map(|ccd| {
let count: u64 = ccd
.data
.0
.first()
.and_then(|data| data.data_avg)
.unwrap()
.round() as u64;
let avg_duration_millis = ccd
.data
.0
.iter()
.find(|x| x.metric == Metric::AvgDurationMillis)
.and_then(|data| data.data_avg)
.expect("avg-duration missing");
mermaid::TraceData::new(
&ccd.full_key,
ccd.rooted,
ccd.is_leaf,
count,
//TODO: some more parameters need to be passed.
None,
avg_duration_millis,
None,
None,
None,
None,
)
})
})
.collect();
(service.to_string(), trace_data)
})
.collect();
mermaid::TracePaths(trace_tree).get_diagram(
service_oper,
call_chain_key,
edge_value,
scope,
compact,
)
}

// /// Take the call_chain data out of the record and return as a hashmap
// pub fn call_chain_as_hashmap(&mut self) -> HashMap<String, StitchedSet> {
// mem::take(&mut self.call_chain).into_iter().collect()
Expand Down

0 comments on commit 7bb30d8

Please sign in to comment.