Skip to content

Commit e289b37

Browse files
committed
updated electron backend, cleaning up codebase and adding comments for next iteration team. Added cloudbased.ts to modularize backend logic for AWS instances. Co-authored-by: Jon Cruz
<[email protected]> Co-authored-by: Elena Atencio <[email protected]> Co-authored-by: Iris Wong <[email protected]> Co-authored-by: John Donato <[email protected]>
1 parent 0d8a69e commit e289b37

File tree

10 files changed

+525
-563
lines changed

10 files changed

+525
-563
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Chronos is a comprehensive developer tool that monitors the health and web traff
2323

2424
## What's New?
2525

26+
v10
27+
- User's account information and services can now be stored in MongoDB. To start connecting to user's database, please add in the URI in UserModel.ts.
28+
29+
2630
- Option to choose between cloud hosted services and local services, now giving Chronos the ability to monitor instances and clusters on AWS' EC2, ECS, and EKS platforms.
2731
- An updated AWS Graphs Container to dynamically render plots for EC2 or ECS data fetched with Electron using event listeners connecting to AWS CloudWatch w/ the aws-sdk package, as well as utilizing Prometheus data scraping and Grafana integration to fetch and render EKS data.
2832
- A step-by-step instruction on setting up a new, functional EC2 instance, ECS cluster, and EKS cluster, ready to be monitored and tested by the app.

app/components/Occupied.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,9 @@ const Occupied = React.memo(() => {
121121
selectedService === 'AWS/EKS'
122122
) {
123123
setAppIndex(i);
124-
// setApp is never invoked, function is not established?
125124
setApp(selectedApp);
126125
navigate(`/aws/:${app}`, { state: { typeOfService: selectedService } });
127126
} else {
128-
console.log('In handleClick Method (local) in Occupied.tsx');
129-
console.log('The following are the new values for appIndex, app, servicesData, and serviceModalOpen:');
130-
console.log(i, ' ', selectedApp, ' ', 'N/A ', serviceModalOpen );
131-
132127
setAppIndex(i);
133128
setApp(selectedApp);
134129
setServicesData([]);

app/context/ApplicationContext.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { ipcRenderer } = window.require('electron');
99
* @property {Array} servicesData The microservices of that application
1010
* @method fetchServicesNames
1111
* @method connectToDB
12+
* @method getSavedMetrics
1213
*/
1314

1415
interface AppContextProps {
@@ -20,59 +21,32 @@ export const ApplicationContext = React.createContext<any>(null);
2021
const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props => {
2122
const children = props.children;
2223
const [servicesData, setServicesData] = useState([]);
23-
const [serviceConnected, setServiceConnected] = useState<boolean>(false);
24-
// v10 note: there is not function for setApp so app is never updated.
2524
const [app, setApp] = useState<string>('');
2625
const [savedMetrics, setSavedMetrics] = useState({});
2726
const [appIndex, setAppIndex] = useState<number>(0);
2827
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
2928

30-
/**
31-
* @function tryParseJson - a function that will parse the JSON data into an object. If there is any error during parsing (a.k.a there is a circular inside the JSON data), console log the error
32-
* @param jsonString - JSON data that is received from backend
33-
* @return an object with all information from backend
34-
*/
35-
function tryParseJSON(jsonString: string) {
36-
try {
37-
const o = JSON.parse(jsonString);
38-
39-
if (o && typeof o === 'object') {
40-
return o;
41-
}
42-
} catch (e) {
43-
console.log({ error: e });
44-
}
45-
return false;
46-
}
4729

4830
/**
4931
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
5032
* 1. Take in an application name
51-
*
5233
* 2. Send a `servicesRequest` to backend
53-
*
5434
* 3. Upon `servicesResponse`, parse the received JSON data and assign it to `servicesData`
55-
*
5635
* 4. Remove the listener for `servicesResponse`
5736
* @param application - application name
5837
*/
5938
// v10: Invoked by connectToDB, passing in app (card title)
6039
const fetchServicesNames = useCallback((application: string) => {
61-
console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
62-
console.log('app when fetch services name: ', application);
63-
// setApp(application);
64-
40+
// console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
41+
// console.log('app when fetch services name: ', application);
6542
ipcRenderer.send('servicesRequest');
66-
6743
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
6844
let result: any;
69-
// Parse JSON data into object
70-
// if (tryParseJSON(data)) result = JSON.parse(data);
7145
result = JSON.parse(data);
72-
console.log('result from ipcrenderer services response is: ', result);
73-
console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
46+
// console.log('result from ipcrenderer services response is: ', result);
47+
// console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
7448
setServicesData(result);
75-
console.log('Leaving fetchedServicesNames function.');
49+
// console.log('Leaving fetchedServicesNames function.');
7650
ipcRenderer.removeAllListeners('servicesResponse');
7751
});
7852

@@ -138,3 +112,22 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
138112
});
139113

140114
export default ApplicationContextProvider;
115+
116+
117+
// /**
118+
// * @function tryParseJson - a function that will parse the JSON data into an object. If there is any error during parsing (a.k.a there is a circular inside the JSON data), console log the error
119+
// * @param jsonString - JSON data that is received from backend
120+
// * @return an object with all information from backend
121+
// */
122+
// function tryParseJSON(jsonString: string) {
123+
// try {
124+
// const o = JSON.parse(jsonString);
125+
126+
// if (o && typeof o === 'object') {
127+
// return o;
128+
// }
129+
// } catch (e) {
130+
// console.log({ error: e });
131+
// }
132+
// return false;
133+
// }

app/modals/ServicesModal.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
2424
console.log('ServicesModal current props (index, app): ', i, ' ', app);
2525

2626
const { user, applications } = useContext(DashboardContext);
27-
console.log('user from Dashboard Context:', user);
28-
console.log('applications from Dashboard Context: ', applications);
29-
console.log('applications[i][2]: ', applications[i][2]);
3027
const { servicesData, connectToDB } = useContext(ApplicationContext);
3128
const [services, setServices] = useState<Array<string>>([]);
3229

@@ -45,8 +42,6 @@ const ServicesModal: React.FC<ServicesModalProps> = React.memo(({ i, app }) => {
4542
// adding database type to make connection and fetchServiceNames more efficient
4643
useEffect(() => {
4744
console.log('Hi, inside useEffect in ServicesModal. Calling connectToDB function.');
48-
console.log("Passing the following parameters for user, i, app, applications, ");
49-
console.log(user, ' ', i, ' ', app, ' ', applications, applications[i][1]);
5045
connectToDB(user, i, app, applications[i][2], applications[i][1]);
5146
}, [i]);
5247

electron/Main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { app, BrowserWindow, ipcMain } from 'electron';
22
import './routes/dashboard';
33
import { clearGuestSettings } from './routes/dashboard';
44
import './routes/data';
5+
import './routes/cloudbased';
56
import path from 'path';
67

78
// Declare variable to be used as the application window

electron/databases/mongo.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import mongoose from 'mongoose';
22
// import { MongoError } from 'mongodb';
3-
const testURL = 'mongodb+srv://seconddbtest:[email protected]/?retryWrites=true&w=majority';
43
// Mongoose connection wrapped in function that takes the index of the selected database as the parameter. This index is used to target the correct database for querying.
54
const connectMongoose = async (i:number, URI: string) => {
65
try {
@@ -13,14 +12,4 @@ const connectMongoose = async (i:number, URI: string) => {
1312
}
1413
};
1514

16-
// const connectMongoose = async (i: number, URI: string) => {
17-
// try {
18-
// const db2 = mongoose.createConnection(testURL);
19-
// console.log('connection to user provided db established..');
20-
// return db2;
21-
// } catch (error) {
22-
// console.log('Error connecting to second db... ', error);
23-
// }
24-
// }
25-
2615
export default connectMongoose;

electron/models/UserModel.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1+
// INSERT URI TO MONGODB TO SET UP USER DATABASE
12
const MONGO_URI = 'mongodb+srv://seconddbtest:[email protected]/?retryWrites=true&w=majority';
2-
// import mongoose, { Schema, Document } from 'mongoose';
3-
4-
// export interface IService extends Document {
5-
// microservice: string;
6-
// interval: number;
7-
// }
83
const mongoose = require('mongoose')
94

10-
const db2 = mongoose.createConnection(MONGO_URI);
5+
const db2 = mongoose.createConnection(MONGO_URI)
6+
.then(() => {
7+
console.log('Connected to User database...');
8+
})
9+
.catch(err => {
10+
console.log('Error connecting to User database: ', err);
11+
})
1112
console.log('establishing connection to database');
12-
// const connectToUserDB = async (URI: string) => {
13-
// console.log('connecting to user info db...')
14-
// return await mongoose.createConnection(URI);
15-
// }
1613

1714

1815
const userSchema = new mongoose.Schema({
19-
// User: {
2016
username: {type: String, required:true, unique: true},
2117
password: {type: String, required:true},
2218
email: String,
2319
services: [],
2420
mode: {type: String, default: 'light'}
25-
// },
2621
});
2722

28-
// export default mongoose.model<IService>('services', ServicesSchema);
29-
30-
// export default mongoose.model('User', userSchema);
3123
const UserModel = db2.model('users', userSchema);
32-
3324
module.exports = UserModel;

0 commit comments

Comments
 (0)