Skip to content

Commit 2a00b5d

Browse files
authored
Merge pull request #25 from oslabs-beta/chronos-npm
Chronos npm
2 parents f2168fd + 14b2319 commit 2a00b5d

File tree

24 files changed

+103
-133
lines changed

24 files changed

+103
-133
lines changed

app/components/TransferColumns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { EventContext } from '../context/EventContext';
66
import { DataGrid } from '@material-ui/data-grid';
77
import * as DashboardContext from '../context/DashboardContext';
88
import lightAndDark from './Styling';
9+
910
import { Button, TextField } from '@mui/material';
1011
import SearchBar from './SearchBar/SearchBar';
1112

12-
1313
interface Params {
1414
service: string;
1515
}

app/containers/GraphsContainer/GraphsContainer.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface Params {
3333
const GraphsContainer: React.FC = React.memo(() => {
3434
const { app, service } = useParams<keyof Params>() as Params;
3535
const [live, setLive] = useState<boolean>(false);
36-
const { intervalID, setIntervalID, example, chart, setChart } = useContext(ApplicationContext);
36+
const { intervalID, setIntervalID, chart, setChart } = useContext(ApplicationContext);
3737
const { getSavedMetrics } = useContext(ApplicationContext);
3838
const { fetchHealthData, setHealthData } = useContext(HealthContext);
3939
const { setDockerData, dockerData } = useContext(DockerContext);
@@ -47,7 +47,6 @@ const GraphsContainer: React.FC = React.memo(() => {
4747

4848
useEffect(() => {
4949
const serviceArray = service.split(' ');
50-
// You would think you should add "kubernetesmetrics" into the below for consistency's sake but it makes it not work correctly, so it has been omitted
5150
const healthServiceArray = serviceArray.filter(
5251
(value: string) => value !== 'kafkametrics' && value !== 'kubernetesmetrics'
5352
);
@@ -60,23 +59,27 @@ const GraphsContainer: React.FC = React.memo(() => {
6059
if (service.includes('kafkametrics')) {
6160
fetchEventData('kafkametrics');
6261
}
63-
// JJ-ADDITION
6462
if (service.includes('kubernetesmetrics')) {
6563
fetchEventData('kubernetesmetrics');
6664
}
6765
}, 10000)
6866
);
6967
} else {
68+
//This block gets data from the metrics db, the health data from each of the services respective dbs and the communcations logs in the communications db
69+
//The respective states are commsData, healthData and savedMetrics
7070
if (intervalID) clearInterval(intervalID);
71+
// gets all the communication logs from the communications database and sets the communications data state
7172
fetchCommsData(app, live);
73+
// gets all health data stored in each of the services databases
7274
fetchHealthData(healthServiceArray);
75+
//kafka and kubernetes are currently not hooked up so these blocks will never fire
7376
if (service.includes('kafkametrics')) {
7477
fetchEventData('kafkametrics');
7578
}
76-
// JJ-ADDITION
7779
if (service.includes('kubernetesmetrics')) {
7880
fetchEventData('kubernetesmetrics');
7981
}
82+
// gets all metric data (cpu related metrics)
8083
getSavedMetrics();
8184
}
8285

@@ -88,7 +91,6 @@ const GraphsContainer: React.FC = React.memo(() => {
8891
};
8992
}, [service, live]);
9093

91-
//random variable to hold the light or dark mode of the display?..ok....sure
9294
const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText;
9395

9496
return (

app/context/ApplicationContext.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
2222
const children = props.children;
2323
const [ example,setExample ] = useState(false)
2424
const [chart, setChart] = useState<string>('all');
25-
2625
const [servicesData, setServicesData] = useState([]);
2726
const [app, setApp] = useState<string>('');
2827
const [savedMetrics, setSavedMetrics] = useState({});
2928
const [appIndex, setAppIndex] = useState<number>(0);
3029
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
3130

32-
3331
/**
3432
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
3533
* 1. Take in an application name
@@ -41,17 +39,11 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4139
// v10: Invoked by connectToDB, passing in app (card title)
4240
const fetchServicesNames = useCallback((application: string) => {
4341

44-
console.log({application});
45-
// console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
46-
console.log('app when fetch services name: ', application);
47-
4842
ipcRenderer.send('servicesRequest');
4943
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
50-
//data here refers to the data coming the services document of the database
44+
//data here refers to the services coming the services document of the database
5145
let result: any;
5246
result = JSON.parse(data);
53-
54-
// console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
5547
setServicesData(result);
5648
ipcRenderer.removeAllListeners('servicesResponse');
5749
});
@@ -90,8 +82,6 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
9082
data.forEach(el => {
9183
store[el.metric] = el;
9284
});
93-
// console.log({store})
94-
// console.log('result from getSavedMetrics is: ', store);
9585
setSavedMetrics(store);
9686
});
9787
}, []);

app/context/CommsContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const CommsContextProvider: React.FC<Props> = React.memo((props) => {
5050
ipcRenderer.send('commsRequest');
5151
ipcRenderer.on('commsResponse', (event: Electron.Event, data: any) => {
5252
let result: any;
53-
//Here we are grabbing all the data from our test database
53+
//Here we are grabbing all the data from our communications database
5454
if (tryParseJSON(data)) result = JSON.parse(data);
5555
setCommsData(result);
5656
});

app/context/HealthContext.tsx

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,48 +55,47 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5555
*/
5656

5757
const fetchHealthData = useCallback(async servers => {
58-
// console.log({servers})
5958
ipcRenderer.removeAllListeners('healthResponse');
6059

6160
let temp: HealthDataObject[] = [];
62-
//Promise.all(
63-
let promises = await Promise.all(servers.map( async (service: string) => {
64-
//NOT WORKING HERE
65-
try {
66-
const newPromise: any = await new Promise((resolve, reject) => {
67-
ipcRenderer.send('healthRequest', `${service}`);
68-
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
69-
let result: object[];
70-
// console.log({data})
71-
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
72-
result = JSON.parse(data);
73-
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
74-
//result exists, has a length prop, and the service name and database name are same
75-
if (result && result.length && `${service}` === Object.keys(result[0])[0]) {
76-
resolve(result[0]);
77-
}
78-
}
79-
});
80-
})
81-
temp.push(newPromise);
82-
// console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
83-
if (checkServicesComplete(temp, [`${service}`])) {
84-
setServices([`${service}`]);
85-
let transformedData: any = {};
86-
// console.log('original healthData before transformation: ', temp);
87-
// transformedData = {
88-
// healthDataList: [1,2,3,4,5],
89-
// healthTimeList: [1,2,3,4,5]
90-
// } //testing typescript, transformedDATA of type 2 arrays with basic entries?
91-
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
92-
// console.log('healthData after tranformation: ', transformedData);
93-
setHealthData(transformedData);
61+
await Promise.all(servers.map( async (service: string) => {
62+
//NOT WORKING HERE
63+
try {
64+
const newPromise: any = await new Promise((resolve, reject) => {
65+
ipcRenderer.send('healthRequest', `${service}`);
66+
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
67+
let result: object[];
68+
// console.log({data})
69+
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
70+
result = JSON.parse(data);
71+
// console.log({result})
72+
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
73+
//result exists, has a length prop, and the service name and database name are same
74+
if (result && result.length && `${service}` === Object.keys(result[0])[0]) {
75+
resolve(result[0]);
76+
}
9477
}
95-
} catch (err) {
96-
// console.log("healthcontext.tsx ERROR: ", err);
97-
};
78+
});
79+
})
80+
temp.push(newPromise);
81+
// console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
82+
if (checkServicesComplete(temp, [`${service}`])) {
83+
setServices([`${service}`]);
84+
let transformedData: any = {};
85+
// console.log('original healthData before transformation: ', temp);
86+
// transformedData = {
87+
// healthDataList: [1,2,3,4,5],
88+
// healthTimeList: [1,2,3,4,5]
89+
// } //testing typescript, transformedDATA of type 2 arrays with basic entries?
90+
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
91+
// console.log('healthData after tranformation: ', transformedData);
92+
setHealthData(transformedData);
9893
}
99-
))
94+
} catch (err) {
95+
// console.log("healthcontext.tsx ERROR: ", err);
96+
};
97+
}
98+
))
10099
} , []);
101100

102101
const checkServicesComplete = (temp: any[], servers: string[]) => {

chronos_npm_package/chronos.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ class Chronos {
7070
* endpoint that the user Request travels through (tracked with hpropograte) for express routes
7171
*/
7272
if (database.type === 'MongoDB') {
73+
//mongo is referring to controller function defined locally, not the actual mongodb object
7374
mongo.connect(this.config);
7475
mongo.services(this.config);
75-
// console.log('dockerized really? chronos.js LN 75', dockerized, this.config)
7676
dockerized ? mongo.docker(this.config) : mongo.health(this.config);
77+
7778
if (database.connection === 'REST') {
7879
return mongo.communications(this.config);
7980
}

chronos_npm_package/controllers/healthHelpers.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,17 @@ const collectedMetrics = {
5858
* @returns Promise array with each metric in an object
5959
*/
6060

61-
healthHelpers.collectHealthData = () => {
61+
healthHelpers.collectHealthData = async() => {
62+
6263
const healthDataCollection = [];
6364
const time = Date.now();
6465

6566
/** obtains core CPU metrics and creates and pushes object with
6667
* metric name and value to the healthDataCollection array
6768
*/
68-
si.cpu()
69+
await si.cpu()
6970
.then(data => {
71+
// console.log(data)
7072
const siMethodName = 'cpu';
7173
for (let metricName in collectedMetrics[siMethodName]) {
7274
healthDataCollection.push({
@@ -76,6 +78,7 @@ healthHelpers.collectHealthData = () => {
7678
time,
7779
});
7880
}
81+
// console.log('CPU HEALTH METRICS',healthDataCollection)
7982
})
8083
.catch(err => {
8184
if (err) {
@@ -86,7 +89,7 @@ healthHelpers.collectHealthData = () => {
8689
/** obtains CPU speed metrics and creates and pushes object with
8790
* metric name and value to the healthDataCollection array
8891
*/
89-
si.cpuCurrentSpeed()
92+
await si.cpuCurrentSpeed()
9093
.then(data => {
9194
const siMethodName = 'cpuCurrentSpeed';
9295
for (let metricName in collectedMetrics[siMethodName]) {
@@ -108,7 +111,7 @@ healthHelpers.collectHealthData = () => {
108111
* metric name and value to the healthDataCollection array
109112
*/
110113

111-
si.cpuTemperature()
114+
await si.cpuTemperature()
112115
.then(data => {
113116
const siMethodName = 'cpuTemperature';
114117
for (let metricName in collectedMetrics[siMethodName]) {
@@ -130,7 +133,7 @@ healthHelpers.collectHealthData = () => {
130133
* obtains metrics relating to current load and creates and pushes object with
131134
* metric name and value to the healthDataCollection array
132135
*/
133-
si.currentLoad()
136+
await si.currentLoad()
134137
.then(data => {
135138
const siMethodName = 'currentLoad';
136139
for (let metricName in collectedMetrics[siMethodName]) {
@@ -152,7 +155,7 @@ healthHelpers.collectHealthData = () => {
152155
* obtains metrics relating to memory and creates and pushes object with
153156
* metric name and value to the healthDataCollection array
154157
*/
155-
si.mem()
158+
await si.mem()
156159
.then(data => {
157160
const siMethodName = 'mem';
158161
for (let metricName in collectedMetrics[siMethodName]) {
@@ -173,7 +176,7 @@ healthHelpers.collectHealthData = () => {
173176
/** obtains metrics relating to current processes and creates and pushes object with
174177
* metric name and value to the healthDataCollection array
175178
*/
176-
si.processes()
179+
await si.processes()
177180
.then(data => {
178181
const siMethodName = 'processes';
179182
for (let metricName in collectedMetrics[siMethodName]) {
@@ -194,7 +197,7 @@ healthHelpers.collectHealthData = () => {
194197
/** obtains latency and creates and pushes object with
195198
* metric name and value to the healthDataCollection array
196199
*/
197-
si.inetLatency()
200+
await si.inetLatency()
198201
.then(data => {
199202
const siMethodName = 'inetLatency';
200203
healthDataCollection.push({
@@ -203,6 +206,7 @@ healthHelpers.collectHealthData = () => {
203206
category: 'Latency',
204207
time,
205208
});
209+
206210
})
207211
.catch(err => {
208212
if (err) {
@@ -213,11 +217,13 @@ healthHelpers.collectHealthData = () => {
213217
/** Return a promise that resolves to an array of all of the data points
214218
* and removes any empty strings, NaN, or "NaN" from values prevent database errors
215219
*/
216-
return Promise.all(healthDataCollection).then(array =>
217-
array.filter(metric => {
218-
if (isNaN(metric.value) || metric.value === 'NaN' || metric.value === '') return false;
220+
return Promise.all(healthDataCollection).then(array => {
221+
// console.log("PROMISE ARRAY",array)
222+
return array.filter(metric => {
223+
if (isNaN(metric.value) || metric.value === 'NaN' || metric.value === '' || metric.value === null) return false;
219224
else return true;
220225
})
226+
}
221227
);
222228
};
223229

0 commit comments

Comments
 (0)