Skip to content

Commit 6d2241e

Browse files
committed
traces showing microservices, edges with duration
1 parent 7019e04 commit 6d2241e

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

app/charts/RouteCopy.jsx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const RouteLocations = props => {
7676
// (len == 1 means there's only one point in the route. There's no meaningful data to be gained from those.)
7777
const tracePoints = Object.values(resObj).filter(subArray => subArray.length > 1);
7878
console.log('tracepoints =======>', tracePoints);
79-
79+
8080
// // Construct an obj that stores data necessary for calculating avg speed of requests btw 2 pts.
8181
// const avgDataObj = {};
8282
// /****** Build the object here w/ nested loops ************/
@@ -107,10 +107,10 @@ const RouteLocations = props => {
107107

108108
// Array of <divs> to be rendered. Each <div> contains route name and time difference.
109109
// const resArray = []
110-
110+
111111
// // const position = communicationsData[0].correlatingid ? 0 : tracePoints.length - 1;
112112
// const position = 0;
113-
113+
114114
// // iterate over ONE elem in tracePoints, creating a <div> for every data obj.
115115
// for (let i = 0; i < tracePoints[position].length; i += 1) {
116116
// if (i !== tracePoints[position].length - 1) {
@@ -191,17 +191,41 @@ const RouteLocations = props => {
191191
// console.log('totalTime:', totalTime);
192192
// console.log('count:', count);
193193
/****************/
194+
const nodeListObj = {};
195+
const edgeList = [];
196+
for (let route of tracePoints) {
197+
for (let i = 0; i < route.length; i += 1) {
198+
// check if node exists if not then add node
199+
let id = route[i].microservice
200+
if (nodeListObj[id] === undefined) {
201+
nodeListObj[id] = { id: id, label: id, color: '#e04141' }
202+
}
203+
// add edge from node 1 to node 2 (repeat til end)
204+
if (i !== 0) {
205+
let duration = new Date(route[i].time) - new Date(route[i-1].time);
206+
let edge = { from: route[i - 1].microservice, to: id, label: `${duration} ms`}
207+
edgeList.push(edge)
208+
}
209+
}
210+
}
211+
const nodeList = Object.values(nodeListObj);
212+
console.log(edgeList);
213+
console.log(nodeList);
194214

195215
const graph = {
196-
nodes: [
197-
{ id: 1, label: "Node 1", color: "#e04141" },
198-
{ id: 2, label: "Node 2", color: "#e09c41" },
199-
{ id: 3, label: "Node 3", color: "#e0df41" },
200-
{ id: 4, label: "Node 4", color: "#7be041" },
201-
{ id: 5, label: "Node 5", color: "#41e0c9" }
202-
],
203-
edges: [{ from: 4, to: 2, label:'hello' }, { from: 1, to: 3 }, { from: 2, to: 4 }, { from: 2, to: 5 }]
216+
nodes: nodeList,
217+
edges: edgeList
204218
};
219+
// const graph = {
220+
// nodes: [
221+
// { id: 'one', label: "Node 1", color: "#e04141" },
222+
// { id: 2, label: "Node 2", color: "#e09c41" },
223+
// { id: 3, label: "Node 3", color: "#e0df41" },
224+
// { id: 4, label: "Node 4", color: "#7be041" },
225+
// { id: 5, label: "Node 5", color: "#41e0c9" }
226+
// ],
227+
// edges: [{ from: 4, to: 2, label: 'hello' }, { from: 'one', to: 3 }, { from: 2, to: 4 }, { from: 2, to: 5 }]
228+
// };
205229
const options = {
206230
layout: {
207231
hierarchical: false
@@ -217,7 +241,7 @@ const RouteLocations = props => {
217241
};
218242

219243
const events = {
220-
select: function(event) {
244+
select: function (event) {
221245
var { nodes, edges } = event;
222246
console.log("Selected nodes:");
223247
console.log(nodes);

0 commit comments

Comments
 (0)