Skip to content

Commit 0092716

Browse files
authored
Merge pull request #25 from Chronos2-0/newDevV2
New dev v2
2 parents b4a6ff5 + 58e8dba commit 0092716

File tree

9 files changed

+171
-25
lines changed

9 files changed

+171
-25
lines changed

.DS_Store

0 Bytes
Binary file not shown.

app/assets/chartModal.png

22.9 KB
Loading
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React, { useContext } from 'react';
2+
import { Bar } from 'react-chartjs-2';
3+
import CommunicationsContext from '../context/OverviewContext';
4+
5+
const MicroServiceTraffic = (props) => {
6+
const communicationsData = useContext(CommunicationsContext).overviewData;
7+
8+
//initialize an empty object resObj. This object will store the microservice names as values and its corresponding correlatingId or correlatingid as keys. The microservice names will be stored in array within the order it was to the database.
9+
const resObj = {};
10+
11+
if(communicationsData.length>0 && communicationsData[0]["_id"]){
12+
//Sort the communication array from latest to earliest document
13+
communicationsData.sort((a,b)=>{
14+
if(new Date(a.timeSent) > new Date(b.timeSent)) return 1;
15+
if(new Date(a.timeSent) < new Date(b.timeSent)) return -1;
16+
return 0;
17+
});
18+
19+
//Iterate over sorted communicationsData array from the end to the beginning
20+
for (let i = 0; i < communicationsData.length; i+=1) {
21+
//declare a constant element and initialize it as the object at index i of the communicationsData array
22+
const element = communicationsData[i];
23+
//Pushes the microservice name into the object
24+
if (resObj[element.correlatingId]) {
25+
resObj[element.correlatingId].push(element.currentMicroservice);
26+
}
27+
else resObj[element.correlatingId] = [element.currentMicroservice];
28+
}
29+
}
30+
31+
else {
32+
33+
for (let i = communicationsData.length-1; i >= 0; i--) {
34+
const element = communicationsData[i];
35+
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
36+
else resObj[element.correlatingid] = [element.currentmicroservice];
37+
// initializing the object with the first microservice
38+
};
39+
}
40+
41+
//use object values to destructure locations
42+
const tracePoints = Object.values(resObj);
43+
let position = communicationsData[0].correlatingid ? 0 : tracePoints.length-1;
44+
45+
// Declare Micro-server-count dictinary to capture the amount of times a particular server is hit
46+
const microServiceCountdictionary = {};
47+
48+
// iterate over Trace Points
49+
for (let i = 0; i < tracePoints[position].length; i+=1) {
50+
51+
// populate Micro-count dictionary
52+
if (!microServiceCountdictionary[tracePoints[position][i]]) {
53+
microServiceCountdictionary[tracePoints[position][i]] = 1;
54+
} else {
55+
microServiceCountdictionary[tracePoints[position][i]]+=1
56+
}
57+
};
58+
59+
// capture values of microServiceCountdictionary to use as data to populate chart object
60+
const serverPingCount = Object.values(microServiceCountdictionary);
61+
62+
63+
// Create chart object data to feed into bar component
64+
const myChart = {
65+
//spread dictionary keys inorder to properly label chart x axis
66+
labels: [...Object.keys(microServiceCountdictionary)],
67+
datasets: [
68+
{
69+
label: 'Times server Pinged',
70+
backgroundColor: 'rgba(241, 207, 70,1)',
71+
borderColor: 'rgba(0,0,0,1)',
72+
borderWidth: 1,
73+
data: [...serverPingCount, 0] // spread ping count array into data array to have chart populate the Y axis
74+
}
75+
]
76+
}
77+
78+
79+
// return div with Bar component and Trace Points data
80+
return (
81+
<div>
82+
<Bar
83+
data={myChart}
84+
width={100}
85+
height={50}
86+
options={{
87+
title:{
88+
display:true,
89+
text:'Microservices Overview',
90+
fontSize:20
91+
},
92+
legend:{
93+
display:true,
94+
position:'right'
95+
}
96+
}}
97+
/>
98+
</div>
99+
)
100+
};
101+
102+
export default MicroServiceTraffic;
103+

app/charts/route-trace.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useContext } from 'react';
2+
import { Bar } from 'react-chartjs-2';
23
import CommunicationsContext from '../context/OverviewContext';
34

45
const RouteLocations = (props) => {
@@ -9,14 +10,11 @@ const RouteLocations = (props) => {
910

1011
if(communicationsData.length>0 && communicationsData[0]["_id"]){
1112
//Sort the communication array from latest to earliest document
12-
// communicationsData.sort((a,b)=>{ new Date(a.timeSent) - new Date(b.timeSent)})
1313
communicationsData.sort((a,b)=>{
1414
if(new Date(a.timeSent) > new Date(b.timeSent)) return 1;
1515
if(new Date(a.timeSent) < new Date(b.timeSent)) return -1;
1616
return 0;
1717
});
18-
19-
2018

2119
//Iterate over sorted communicationsData array from the end to the beginning
2220
for (let i = 0; i < communicationsData.length; i+=1) {
@@ -27,35 +25,40 @@ const RouteLocations = (props) => {
2725
resObj[element.correlatingId].push(element.currentMicroservice);
2826
}
2927
else resObj[element.correlatingId] = [element.currentMicroservice];
30-
// initializing the object with the first microservice
3128
}
3229
}
33-
else{
34-
for (let i = communicationsData.length-1; i >= 0; i--) {
30+
31+
else {
32+
33+
for (let i = communicationsData.length-1; i >= 0; i--) {
3534
const element = communicationsData[i];
3635
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
3736
else resObj[element.correlatingid] = [element.currentmicroservice];
3837
// initializing the object with the first microservice
39-
};
40-
}
38+
};
39+
}
4140

4241
//use object values to destructure locations
4342
const tracePoints = Object.values(resObj);
4443
let position = communicationsData[0].correlatingid ? 0 : tracePoints.length-1;
4544

4645
const resArray = [];
4746

47+
// iterate over Trace Points
4848
for (let i = 0; i < tracePoints[position].length; i+=1) {
49+
//push into resulting array current tracepoint as div
4950
resArray.push(
5051
<div className="RouteCircle" key={i}>
5152
<p id="routeText">Point {i+1}: {tracePoints[position][i]}</p>
5253
</div>
5354
)
5455
};
5556

57+
58+
// return div with Trace Points data
5659
return (
5760
<div>
58-
{resArray}
61+
{resArray}
5962
</div>
6063
)
6164
};

app/components/Modal.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TemperatureChart from '../charts/temperature-chart.jsx';
77
import LatencyChart from '../charts/latency-chart.jsx';
88
import MemoryChart from '../charts/memory-chart.jsx';
99
import RouteTrace from '../charts/route-trace.jsx';
10+
import MicroServiceTraffic from '../charts/microservice-traffic.jsx';
1011

1112
const Modal = (props) => {
1213
// Destructuring props to make linter happy
@@ -16,11 +17,12 @@ const Modal = (props) => {
1617
// Dictionary used to render proper data chart within Modal component upon rendering
1718
const dict = {
1819
request: <RequestTypesChart service={service} />,
19-
routes: <RouteTrace service={service} />,
20+
Routes: <RouteTrace service={service} />,
2021
response: <ResponseCodesChart service={service} />,
2122
speed: <SpeedChart service={service} />,
2223
processes: <ProcessesChart service={service} />,
2324
latency: <LatencyChart service={service} />,
25+
Traffic: <MicroServiceTraffic service={service} />,
2426
temperature: <TemperatureChart service={service} />,
2527
memory: <MemoryChart service={service} />,
2628
};

app/components/ServiceDetails.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ const ServiceDetails = (props) => {
2323
const { currentMicroservice } = props;
2424

2525
// Dictionary used by the healthInfoButtons loop below
26-
// { id: 'request', alt: 'Request Data', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
2726

2827
const buttonProperties = [
2928
{ id: 'request', alt: 'Request Data', src: pieChart },
3029
{ id: 'response', alt: 'Response Data', src: pieChart },
31-
// { id: 'routes', alt: 'Route Trace', src: 'https://st2.depositphotos.com/3894705/9581/i/950/depositphotos_95816620-stock-photo-round-button-shows-speedometer.jpg' },
3230
{ id: 'speed', alt: 'Speed Data', src: speedChart},
3331
{ id: 'processes', alt: 'Processes Data', src: processingChart },
3432
{ id: 'latency', alt: 'Latency Data', src: latencyChart },

app/components/ServiceOverview.jsx

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import HealthInformationContext from '../context/DetailsContext';
44
import ServiceDetails from './ServiceDetails.jsx';
55
import Modal from './Modal.jsx';
66
import routeChart from '../assets/routeChart.png'
7+
import chartModal from '../assets/chartModal.png'
78

89
const { ipcRenderer } = window.require('electron');
910

@@ -40,11 +41,42 @@ const ServiceOverview = (props) => {
4041
// Hook used to set the Modal Component title. The "alt" attribute
4142
// is grabbed from the onClick event via event.path[0].alt
4243
const [chartTitle, setChartTitle] = useState();
43-
44-
const routeButtonProperty = { id: 'routes', alt: 'Route Trace', src: routeChart };
44+
45+
//route button AND traffic button property
46+
const routeButtonProperty = { traffic: {id: 'Traffic', alt: 'Microservice Traffic', src: chartModal}, routes: {id: 'Routes', alt: 'Route Trace', src: routeChart} };
47+
48+
//declare routes array to display routes when modal is toggled
4549
const routes = [];
50+
//declare traffic array to display traffic when modal is toggled
51+
const traffic = [];
52+
53+
//push traffic component logic traffic
54+
traffic.push (
55+
56+
<div className="healthChartContainer">
57+
<input
58+
onClick={() => {
59+
setChartTitle(event.path[0].alt);
60+
setModalChart(event.path[0].id);
61+
toggleModalDisplay(!modalDisplay);
62+
}}
63+
type="image"
64+
id={routeButtonProperty.traffic.id}
65+
src={routeButtonProperty.traffic.src}
66+
width="60px"
67+
alt={routeButtonProperty.traffic.alt}
68+
/>
69+
<br/>
70+
<div style={{color:'white', paddingLeft:'7px'}}>
71+
{routeButtonProperty.traffic.id}
72+
</div>
73+
</div>
74+
75+
);
76+
77+
//push routes component logic traffic
4678
routes.push(
47-
<div>
79+
4880
<div className="healthChartContainer">
4981
<input
5082
onClick={() => {
@@ -53,17 +85,17 @@ const ServiceOverview = (props) => {
5385
toggleModalDisplay(!modalDisplay);
5486
}}
5587
type="image"
56-
id={routeButtonProperty.id}
57-
src={routeButtonProperty.src}
88+
id={routeButtonProperty.routes.id}
89+
src={routeButtonProperty.routes.src}
5890
width="60px"
59-
alt={routeButtonProperty.alt}
91+
alt={routeButtonProperty.routes.alt}
6092
/>
6193
<br/>
6294
<div style={{color:'white', paddingLeft:'7px'}}>
63-
{routeButtonProperty.id}
95+
{routeButtonProperty.routes.id}
6496
</div>
6597
</div>
66-
</div>,
98+
6799
);
68100

69101
// Filters data received from IPC to the communications database to create a list of the services tracked in the provided database,
@@ -144,10 +176,9 @@ const ServiceOverview = (props) => {
144176
<div>
145177
<h1 className='overviewTitle'>Microservices Overview</h1>
146178
</div>
147-
<div />
148179
<div className="servicesList">{serviceList()}</div>
149-
{/* adding the route tracer button */}
150-
<h3>Trace Last Route</h3>
180+
<br/>
181+
<h1>Microservices Communications</h1>
151182
{modalDisplay ? (
152183
<Modal
153184
chartTitle={chartTitle}
@@ -159,7 +190,10 @@ const ServiceOverview = (props) => {
159190
}}
160191
/>
161192
) : null}
162-
{routes}
193+
<div id="routeAndTrafficDisplay">
194+
{routes}
195+
{traffic}
196+
</div>
163197
</div>
164198
);
165199
};

app/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ select {
258258
opacity: 0.7;
259259
}
260260

261+
#routeAndTrafficDisplay {
262+
display: inline-flex;
263+
}
264+
265+
261266
#microserviceHealthInfo {
262267
text-align: center;
263268
margin-top: 25px;
@@ -310,6 +315,7 @@ select {
310315
margin-right: 10px;
311316
}
312317

318+
313319
.RouteCircle {
314320
font-family: Arial, Helvetica, sans-serif;
315321
color: white;

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":true,"services":["hard","coded","in"]}
1+
{"setupRequired":true,"services":["hard","coded","in"]}

0 commit comments

Comments
 (0)