Skip to content

Commit 7e3734b

Browse files
authored
Merge pull request #9 from Chronos2-0/jenae/valid_uri
updated the chronos frontend glitch and removed MichelleWasHere
2 parents 91ac1c0 + e4ddaa6 commit 7e3734b

21 files changed

Lines changed: 336 additions & 899 deletions

Main.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const connectMongoose = require('./model/mongoose-connect');
66
const CommunicationSchema = require('./model/mongoose-communicatonSchema');
77
const HealthInfoSchema = require('./model/mongoose-healthInfoSchema');
88

9+
//declare a variable pool for SQL connection
10+
let pool;
911
let win;
1012
function createWindow() {
1113
win = new BrowserWindow({
@@ -54,20 +56,26 @@ ipcMain.on('setup', (message) => {
5456

5557
// Loads existing settings JSON and update settings to include new services entered by the user.
5658
ipcMain.on('submit', (message, newService) => {
59+
// set the variable 'state' to the contents of /user/settings.json
60+
// contents => "setupRequired" (boolean),"services" (Array)
61+
// setupRequired- toggle the page for adding database
62+
// services - name of DB stores dbType, and uri
5763
const state = JSON.parse(
5864
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), {
5965
encoding: 'UTF-8',
6066
}),
6167
);
62-
// if statement is used to replace hard coded data. Hard coded data and the michelleWasHere key is needed to avoid a load error caused by Electron querying the database before a user has added or selected a database.
63-
if (state.michelleWasHere) {
68+
// if statement is used to replace hard coded data. Hard coded data is needed to avoid a load error caused by Electron querying the database before a user has added or selected a database.
69+
if (state.setupRequired) {
6470
state.setupRequired = false;
65-
state.michelleWasHere = false;
6671
state.services = [JSON.parse(newService)];
72+
//is updating the /user/settings.json file with the first new service
6773
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
6874
} else {
75+
//what is the new service?
6976
state.setupRequired = false;
7077
state.services.push(JSON.parse(newService));
78+
//is updating the /user/settings.json file with the new service
7179
fs.writeFileSync(path.resolve(__dirname, './user/settings.json'), JSON.stringify(state));
7280
}
7381
});
@@ -79,44 +87,53 @@ ipcMain.on('dashboard', (message) => {
7987
encoding: 'UTF-8',
8088
}),
8189
);
90+
//getting the array of databases [name, dbType, uri]
8291
const { services } = state;
92+
//creates an array of the database names
8393
const dashboardList = services.reduce((acc, curVal) => {
8494
acc.push(curVal[0]);
8595
return acc;
8696
}, []);
97+
//returns the array of the database names
8798
message.returnValue = dashboardList;
8899
});
89100

90101
// Queries the database for communications information and returns it back to the render process.
91102
ipcMain.on('overviewRequest', (message, index) => {
92-
const databaseType = JSON.parse(
103+
//acquires the services from user settings.json file
104+
const services = JSON.parse(
93105
fs.readFileSync(path.resolve(__dirname, './user/settings.json'), { encoding: 'UTF-8' }),
94-
).services[index][1];
106+
).services
107+
const databaseType = services[index][1];
108+
const URI = services[index][2];
95109

96110
if (databaseType === 'MongoDB') {
97-
connectMongoose(index);
111+
connectMongoose(index,URI);
98112
CommunicationSchema.find({}, (err, data) => {
99113
if (err) {
100114
console.log(`An error occured while querying the database: ${err}`);
101-
message.sender.send('overviewResponse', JSON.stringify(err));
115+
return message.sender.send('overviewResponse', JSON.stringify(err));
102116
}
117+
//queryResults is an array of objects with the following keys {"_id","currentMicroservice","targetedEndpoint","reqType","timeSent","resStatus","resMessage","__v"}
103118
const queryResults = JSON.stringify(data);
119+
104120
// Asynchronous event emitter used to transmit query results back to the render process.
105-
message.sender.send('overviewResponse', queryResults);
121+
return message.sender.send('overviewResponse', queryResults);
106122
});
107123
}
108124

109125
if (databaseType === 'SQL') {
110-
const pool = connectSQL(index);
126+
pool = connectSQL(index,URI);
111127
const getCommunications = 'SELECT * FROM communications';
112128
pool.query(getCommunications, (err, result) => {
113129
if (err) {
114-
console.log(err);
115-
message.sender.send(JSON.stringify('Database info could not be retreived.'));
130+
return message.sender.send(JSON.stringify('Database info could not be retrieved.'));
116131
}
132+
console.log('Connected to SQL Database')
133+
//queryResults is an array of objects with the following keys {"id","currentmicroservice","targetedendpoint","reqtype","resstatus","resmessage","timesent"}
117134
const queryResults = JSON.stringify(result.rows);
118135
// Asynchronous event emitter used to transmit query results back to the render process.
119-
message.sender.send('overviewResponse', queryResults);
136+
return message.sender.send('overviewResponse', queryResults);
120137
});
121138
}
122139
});
@@ -128,27 +145,27 @@ ipcMain.on('detailsRequest', (message, index) => {
128145
).services[index][1];
129146

130147
if (databaseType === 'MongoDB') {
131-
connectMongoose(index);
132148
HealthInfoSchema.find({}, (err, data) => {
133149
if (err) {
134150
message.sender.send('detailsResponse', JSON.stringify(err));
135151
}
136152
const queryResults = JSON.stringify(data);
137153
// Asynchronous event emitter used to transmit query results back to the render process.
138-
message.sender.send('detailsResponse', queryResults);
154+
return message.sender.send('detailsResponse', queryResults);
139155
});
140156
}
141157

142158
if (databaseType === 'SQL') {
143-
const pool = connectSQL(index);
159+
160+
// const pool = connectSQL(index);
144161
const getHealth = 'SELECT * FROM healthInfo';
145162
pool.query(getHealth, (err, result) => {
146163
if (err) {
147164
message.sender.send('detailsResponse', JSON.stringify('Database info could not be retreived.'));
148165
}
149166
const queryResults = JSON.stringify(result.rows);
150167
// Asynchronous event emitter used to transmit query results back to the render process.
151-
message.sender.send('detailsResponse', queryResults);
168+
return message.sender.send('detailsResponse', queryResults);
152169
});
153170
}
154171
});

README.md

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,88 @@
1-
##Chronos Microservice Debugger
2-
Chronos Microservice Debugger consists of an npm package with an optional Electron front end to visualize and monitor your microservices.
1+
# Chronos
2+
Chronos consists of an NPM package to be required into a user’s microservices that intercepts all http and gRPC microservice communications, as well as monitors the health of each microservice over time. This information is written to a user-owned database (PostgreSQL or NoSQL) where it is queried and rendered by the frontend utilizing Node in conjunction with a native, cross-platform Electron desktop application with React components to ensure agreement between the frontend and database.
33

4-
## Install
4+
## Why was Chronos created?
5+
As companies grow larger and begin to scale, they have a tendency to move from a monolithic code architecture and microservices and distributed systems architecture in order to build faster, more maintainable code.
6+
7+
The process of modularizing a code bases and breaking a monolith into individual services can be a daunting task. How do you break apart and re-connect these services? There is often a transitional period where valuable time is spent debugging these connections between services.
8+
9+
Chronos is deigned to meet the needs of companies and developers working to break down their monoliths into distributed systems by combining an NPM package together with an Electron application to monitor and assist in the debugging of their services.
10+
11+
## How to Install Chronos
12+
The Chronos-Microservice-Debugger Express Middleware can be found on npm: https://www.npmjs.com/package/chronos-microservice-debugger
13+
14+
To install the NPM package:
515
```javascript
616
npm install chronos-microservice-debugger
717
```
818

9-
## Usage
19+
The Chronos Electron application is in progress and will soon be availble for public download for all platforms. Please stay tuned.
20+
21+
## How to Use Chronos
1022
There are two main aspects to Chronos-Microservice-Debugger
11-
*Communication Monitor: Listens in on all microservice-microservice and microservice-client communication and monitors the response statuses and messages to ensure communications are making it to the correct destination successfully.
12-
*Health Monitor: The health monitor checks the status of your microservice every second and sends this health information to an optional electron frontend where it is visualized for easier use.
23+
1. Communication Monitor: Listens in on all microservice-microservice and microservice-client communication and monitors the response statuses and messages to ensure communications are making it to the correct destination successfully.
24+
2. Health Monitor: The health monitor checks the status of your microservice every second and sends this health information to an optional electron frontend where it is visualized for easier use.
25+
26+
To use the npm package, there are three required parameters and an optional fourth parameter. You can enter the items as individual strings or as an array containing the three required parameters and one optional parameter.
1327

28+
The parameters are:
29+
1. microserviceName: What do you want to name the current microservice
30+
2. databaseType: We currently support PostgreSQL and Mongo. Enter "mongo" or "sql"
31+
3. databaseURL: Where would you like to store your information? Enter the URL to your database
32+
4. queryFrequency: How often do you want microHealth to monitor the health of your database? It defaults to every second, but you can choose:
33+
* "s" : The default, monitors every second
34+
* "m" : Monitors every minute
35+
* "h" : Monitors every hour
36+
* "d" : Monitors once per day
37+
* "w" : Monitors once per week
1438

39+
String parameter example:
1540
```javascript
16-
app.use('/', chronos-microservice-debugger.microCom('microserviceName', 'databaseType', 'databaseURL'))
17-
chronos-microservice-debugger.microHealth('microserviceName', databaseType, databaseURL))
41+
// How to use chronos-microservice-debugger
42+
app.use('/', chronos-microservice-debgugger.microCom('microserviceName', 'databaseType', 'databaseURL'))
43+
44+
chronos-microservice-debugger.microHealth('microserviceName', 'databaseType', 'databaseURL', 'queryFrequency'))
45+
46+
// Example using string parameters
47+
app.use('/', chronos-microservice-debugger.microCom('books', 'sql', 'thisIsMyURL'))
48+
// Note: microCom does not utilize queryFreq because it logs all communication when an endpoint is hit
49+
50+
chronos-microservice-debugger.microHealth('books', 'sql', 'thisIsMyURL', 'h')
1851
```
19-
Chronos uses a user-owned and provided database to ensure that your private data stays private. We currently support MongoDB and SQL/PostgreSQL databases.
2052

21-
## Things in the Works
22-
*gRPC support
23-
*Ability to determine how often your microservice health is monitored (currently every second)
24-
*'Time Travel' to see how your microservices have changed over time
25-
*Docker health information for containerized microservices
26-
*Implement additional unit testing
53+
Array parameter example:
54+
```javascript
55+
let values = [
56+
'microserviceName',
57+
'databaseType',
58+
'databaseURL',
59+
'queryFrequency'
60+
]
61+
// How to use chronos-micrservice-debugger with an array parameter
62+
app.use('/', chronos-microservice-debgugger.microCom(values)
63+
64+
chronos-microservice-debugger.microHealth(values)
65+
66+
// Example using an array parameter
67+
let values = [
68+
'books',
69+
'mongo',
70+
'thisIsMyNewURL',
71+
'w'
72+
]
2773

28-
## Links
29-
*Chronos Website: http://chronos.ninja
30-
*Gitub Page: https://github.com/oslabs-beta/Chronos
74+
app.use('/', chronos-microservice-debgugger.microCom(values)
75+
// Note: microCom does not utilize queryFreq because it logs all communication when an endpoint is hit
76+
77+
chronos-microservice-debugger.microHealth(values)
78+
79+
```
3180
32-
## Contact Us
33-
For questions, requests, or more information, please contact us at teammicronos@gmail.com
81+
## How to Contribute to Chronos
82+
Chronos hopes to inspire an active community of both users and developers. For questions, comments, suggestions, please contact us at teammicronos@gmail.com or submit a pull request.
3483
84+
## Created By
85+
* Duane McFarlane
86+
* Michelle Herrera
87+
* Mohtasim Chowdhury
88+
* Natalie Umanzor

app/assets/pieChart.png

47.3 KB
Loading

app/components/AddService.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState, useContext, useEffect } from 'react';
22
import logo from '../assets/logo2.png';
33
import SetupContext from '../context/SetupContext';
44
import ServicesDashboard from './ServicesDashboard.jsx';
@@ -10,37 +10,46 @@ const AddService = () => {
1010
const ChronosSetup = useContext(SetupContext);
1111

1212
// Local state created for form entries ONLY.
13-
const [dbState, setDbType] = useState('SQL');
13+
const [dbState, setDbType] = useState('');
1414
const [uriState, setUri] = useState('');
1515
const [labelState, setLabel] = useState('');
1616

1717
// Submits data provided by the user to added to the setting file.
1818
const onSubmit = () => {
1919
const userSettings = [labelState, dbState, uriState];
20+
2021
// IPC communication used to update settings JSON with user input.
2122
ipcRenderer.send('submit', JSON.stringify(userSettings));
2223
ChronosSetup.setupRequired = ChronosSetup.toggleSetup(true);
2324
// Refresh window after submit.
2425
document.location.reload();
2526
};
27+
//it is setting the dbState
28+
useEffect(()=>{
29+
setDbType(document.getElementById('dbType').value)
30+
},[dbState, setDbType])
31+
2632

2733
return (
2834
<div className="mainContainer">
2935
<img src={logo} alt="logo" />
3036
<h2 className="signUpHeader">Enter Your Database Information</h2>
3137
<form>
3238
Database Type:
33-
<select value={dbState} onChange={(e) => setDbType(e.target.value)}>
39+
{/* the select e.target.value of onchange is reading the value SQL and MongDB, the value the setState is delay by one action. Stack Over Flow says the action is an async call so dbState is updated late. So I did another setDbtype callwith useEffect*/}
40+
<select id="dbType" onChange={()=>setDbType(document.getElementById('dbType').value)}>
3441
<option value="SQL">SQL</option>
3542
<option value="MongoDB">MongoDB</option>
3643
</select>
3744
Database URI:
45+
{/* This is where the uri value is set with setUri */}
3846
<input
3947
className="userInput"
4048
id="dburi"
4149
onChange={(e) => setUri(e.target.value)}
4250
placeholder="Database URI"
4351
/>
52+
{/* This is where the name of the database is set with setLabel */}
4453
Database Name:
4554
<input
4655
className="userInput"

app/components/Modal.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import RequestTypesChart from '../charts/request-type-chart.jsx';
3+
import ResponseCodesChart from '../charts/response-code-chart.jsx';
4+
import SpeedChart from '../charts/speed-chart.jsx';
5+
import ProcessesChart from '../charts/processes-chart.jsx';
6+
import TemperatureChart from '../charts/temperature-chart.jsx';
7+
import LatencyChart from '../charts/latency-chart.jsx';
8+
import MemoryChart from '../charts/memory-chart.jsx';
9+
10+
const Modal = (props) => {
11+
// Destructuring props to make linter happy
12+
const {
13+
modalChart, service, toggleModalDisplay, chartTitle,
14+
} = props;
15+
// Dictionary used to render proper data chart within Modal component upon rendering
16+
const dict = {
17+
request: <RequestTypesChart service={service} />,
18+
response: <ResponseCodesChart service={service} />,
19+
speed: <SpeedChart service={service} />,
20+
processes: <ProcessesChart service={service} />,
21+
latency: <LatencyChart service={service} />,
22+
temperature: <TemperatureChart service={service} />,
23+
memory: <MemoryChart service={service} />,
24+
};
25+
26+
// event.stopPropogation allows the user to interact with the chart as opposed to a click on the
27+
// chart bubbling out and closing the Modal.
28+
return (
29+
<div id="modalWindow" onClick={() => toggleModalDisplay(!toggleModalDisplay)}>
30+
<div id="modalContent" onClick={(event) => event.stopPropagation()}>
31+
<h3 id="chartTitle">{`${service} - ${chartTitle}`}</h3>
32+
<button id="modalCloseButton" onClick={() => toggleModalDisplay(!toggleModalDisplay)}>&times;</button>
33+
{dict[modalChart]}
34+
</div>
35+
</div>
36+
);
37+
};
38+
39+
export default Modal;

0 commit comments

Comments
 (0)