Skip to content

Commit 0c00073

Browse files
authored
Merge pull request #9 from oslabs-beta/mergedev
Tested everything, this is final merge into dev with all functioning features
2 parents 76bb3ce + 2ab2c49 commit 0c00073

File tree

12 files changed

+130
-86
lines changed

12 files changed

+130
-86
lines changed

app/components/About.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,34 @@ const About: React.FC = React.memo(() => {
2121
to use and expensive to operate, Chronos was born. Chronos is an all-in-one network and
2222
health monitoring tool for your application or microservice, containerized or not!
2323
</p>
24+
<br>
25+
</br>
2426
<h3 style={currentMode} className="title">
2527
Fantastic Four
2628
</h3>
2729
<div>
2830
<span style={currentMode} className="text">
29-
Nachiket
31+
<p>Josh</p>
3032
</span>
31-
<br />
3233
<span style={currentMode} className="text">
33-
Tiffany
34+
<p>Elisa</p>
3435
</span>
35-
<br />
3636
<span style={currentMode} className="text">
37-
Bruno
37+
<p>Troy</p>
3838
</span>
39-
<br />
4039
<span style={currentMode} className="text">
41-
Danny
40+
<p>Gahl</p>
4241
</span>
4342
<br />
44-
<br />
4543
</div>
4644
<h3 style={currentMode} className="title">
4745
Contributors
4846
</h3>
4947
<p style={currentMode} className="text">
50-
Vince, Matt, Derek, Kit, Grace, Jen, Patty, Stella, Michael, Ronelle, Todd, Greg, Brianna,
48+
Nachiket, Tiffany, Bruno, Danny, Vince, Matt, Derek, Kit, Grace, Jen, Patty, Stella, Michael, Ronelle, Todd, Greg, Brianna,
5149
Brian, Alon, Alan, Ousman, Ben, Chris, Jenae, Tim, Kirk, Jess, William, Alexander
5250
</p>
5351
<br />
54-
<p style={currentMode}>Copyright © Team Chronos 2021.</p>
5552
</div>
5653
</div>
5754
);

app/components/TransferColumns.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const TransferColumns = React.memo(() => {
129129
// setSelectedMetrics
130130
const temp: any[] = [];
131131
const categorySet = new Set();
132+
console.log('targetKeys is: ', targetKeys)
132133
for (let i = 0; i < targetKeys.length; i++) {
133134
const str: string = targetKeys[i];
134135
const strArr: string[] = str.split(' | ');
@@ -148,6 +149,7 @@ const TransferColumns = React.memo(() => {
148149
temp.push(newCategory);
149150
}
150151
}
152+
console.log('temp is: ', temp);
151153
setSelectedMetrics(temp);
152154
};
153155

app/stylesheets/About.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@
6969
animation: none;
7070
}
7171
}
72+
73+
p {
74+
padding-left: 10px;
75+
}

app/stylesheets/Contact.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
flex-direction: column;
2323
justify-content: center;
2424
font-size: 18px;
25-
2625
border-radius: 10px;
2726
border: none;
2827
box-shadow: $boxshadow2;
@@ -65,6 +64,8 @@
6564
flex-direction: column;
6665
width: 100%;
6766
input {
67+
border: 1px solid transparent;
68+
border-radius: 5px;
6869
width: 100%;
6970
color: $header;
7071
font-size: 16px;
@@ -75,6 +76,7 @@
7576
}
7677
}
7778
textarea {
79+
border-radius: 5px;
7880
font-size: 16px;
7981
width: 100%;
8082
min-width: 100%;
@@ -109,6 +111,7 @@
109111

110112
&:hover {
111113
border: none;
114+
cursor: pointer;
112115
}
113116

114117
&:focus {
@@ -122,6 +125,7 @@
122125

123126
input[type='file'] {
124127
border: none;
128+
border-radius: 5px;
125129

126130
&:hover {
127131
border: none;

chronos_npm_package/controllers/mongo.js

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,18 @@ mongo.communications = ({ microservice, slack, email }) => {
108108
* @param {string} microservice Microservice name
109109
* @param {number} interval Interval for continuous data collection
110110
*/
111-
mongo.health = ({ microservice, interval }) => {
111+
mongo.health = async ({ microservice, interval, mode }) => {
112+
let l = 0;
113+
const currentMetricNames = {};
114+
115+
l = await mongo.getSavedMetricsLength(mode, currentMetricNames);
116+
112117
setInterval(() => {
113118
collectHealthData()
114-
.then(healthMetrics => {
119+
.then(async (healthMetrics) => {
120+
if (l !== healthMetrics.length) {
121+
l = await mongo.addMetrics(healthMetrics, mode, currentMetricNames);
122+
}
115123
const HealthModel = HealthModelFunc(`${microservice}`);
116124
return HealthModel.insertMany(healthMetrics);
117125
})
@@ -126,7 +134,8 @@ mongo.health = ({ microservice, interval }) => {
126134
* Runs instead of health if dockerized is true
127135
* Collects information on the docker container
128136
*/
129-
mongo.docker = ({ microservice, interval }) => {
137+
mongo.docker = ({ microservice, interval, mode }) => {
138+
130139
// Create collection using name of microservice
131140
const containerInfo = ContainerInfoFunc(`${microservice}-containerinfo`);
132141
dockerHelper.getDockerContainer(microservice)
@@ -182,7 +191,7 @@ mongo.saveService = (config) => {
182191
mongo.setQueryOnInterval = async (config) => {
183192
let model;
184193
let metricsQuery;
185-
let currentMetrics;
194+
186195
let l = 0;
187196
const currentMetricNames = {};
188197

@@ -198,39 +207,18 @@ mongo.setQueryOnInterval = async (config) => {
198207
// When querying for currentMetrics, we narrow down the result to only include metrics for the current service being used.
199208
// This way, when we go to compare parsedArray to currentMetricNames, the length of the arrays should match up unless there are new metrics available to view
200209

201-
currentMetrics = await MetricsModel.find({mode: config.mode});
202-
if (currentMetrics.length > 0) {
203-
currentMetrics.forEach(el => {
204-
const { metric, selected } = el;
205-
currentMetricNames[metric] = selected;
206-
l = currentMetrics.length;
207-
})
208-
}
210+
l = await mongo.getSavedMetricsLength(config.mode, currentMetricNames);
211+
212+
console.log('currentMetricNames is: ', Object.keys(currentMetricNames).length)
209213
// Use setInterval to send queries to metrics server and then pipe responses to database
210214
setInterval(() => {
211215
metricsQuery(config)
212216
// This updates the Metrics Model with all chosen metrics. If there are no chosen metrics it sets all available metrics as chosen metrics within the metrics model.
213217
.then(async (parsedArray) => {
214218
// This conditional would be used if new metrics are available to be tracked.
215219
if (l !== parsedArray.length) {
216-
console.log('currentMetricNames is less than parsedArray length, new metrics available to track');
217-
console.log('currentMetricNames has a length of: ', l, ' and parsedArray.length is: ', parsedArray.length);
218-
const newMets = [];
219-
parsedArray.forEach(el => {
220-
if (!(el.metric in currentMetricNames)) {
221-
const { metric } = el;
222-
newMets.push(MetricsModel({metric: metric, mode: config.mode}))
223-
currentMetricNames[el.metric] = true;
224-
}
225-
})
226-
await MetricsModel.insertMany(newMets, (err) => {
227-
if (err) console.error(err)
228-
})
229-
l = parsedArray.length;
220+
l = await mongo.addMetrics(parsedArray, config.mode, currentMetricNames);
230221
}
231-
return parsedArray;
232-
})
233-
.then(parsedArray => {
234222
const documents = [];
235223
for (const metric of parsedArray) {
236224
// This will check if the current metric in the parsed array evaluates to true within the currentMetricNames object.
@@ -247,8 +235,33 @@ mongo.setQueryOnInterval = async (config) => {
247235
}, config.interval);
248236
}
249237

238+
mongo.getSavedMetricsLength = async (mode, currentMetricNames) => {
239+
let currentMetrics = await MetricsModel.find({mode: mode});
240+
if (currentMetrics.length > 0) {
241+
currentMetrics.forEach(el => {
242+
const { metric, selected } = el;
243+
currentMetricNames[metric] = selected;
244+
})
245+
}
246+
return currentMetrics.length ? currentMetrics.length : 0;
247+
}
250248

251-
// This middleware could be used if the user would like to update their chronos data, but they would have to expose a URL/port to be queried for the Electron front end.
249+
mongo.addMetrics = async (arr, mode, obj) => {
250+
const newMets = [];
251+
arr.forEach(el => {
252+
if (!(el.metric in obj)) {
253+
const { metric } = el;
254+
newMets.push({metric: metric, mode: mode})
255+
obj[el.metric] = true;
256+
}
257+
})
258+
await MetricsModel.insertMany(newMets, (err) => {
259+
if (err) console.error(err)
260+
})
261+
return arr.length;
262+
}
263+
264+
// This middleware could be used if the user would like to update their chronos data in real time (immediately after updating saved metrics on the Chronos desktop app), but they would have to expose a URL/port to be queried for the Electron front end.
252265
//
253266
// mongo.modifyMetrics = (config) => {
254267
// return function (req, res, next) {
@@ -262,5 +275,4 @@ mongo.setQueryOnInterval = async (config) => {
262275
// };
263276
// }
264277

265-
266278
module.exports = mongo;

chronos_npm_package/controllers/postgres.js

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ postgres.connect = async ({ database }) => {
3535
postgres.services = ({ microservice, interval }) => {
3636
// Create services table if does not exist
3737
client.query(
38-
`CREATE TABLE IF NOT EXISTS services (
38+
`CREATE TABLE IF NOT EXISTS services (
3939
_id SERIAL PRIMARY KEY NOT NULL,
4040
microservice VARCHAR(248) NOT NULL UNIQUE,
4141
interval INTEGER NOT NULL)`,
@@ -46,8 +46,8 @@ postgres.services = ({ microservice, interval }) => {
4646
}
4747
);
4848

49-
client.query(`
50-
CREATE TABLE IF NOT EXISTS metrics (
49+
client.query(
50+
`CREATE TABLE IF NOT EXISTS metrics (
5151
_id SERIAL PRIMARY KEY NOT NULL,
5252
metric TEXT NOT NULL UNIQUE,
5353
selected BOOLEAN,
@@ -163,13 +163,14 @@ function createQueryString(numRows, serviceName) {
163163

164164
// Places the values being inserted into postgres into an array that will eventually
165165
// hydrate the parameterized query
166-
function createQueryArray(dataPointsArray) {
166+
function createQueryArray(dataPointsArray, currentMetricNames) {
167167
const queryArray = [];
168168
for (const element of dataPointsArray) {
169-
queryArray.push(element.metric);
170-
queryArray.push(element.value);
171-
queryArray.push(element.category);
172-
queryArray.push(element.time / 1000); // Converts milliseconds to seconds to work with postgres
169+
queryArray.push(element.metric);
170+
queryArray.push(element.value);
171+
queryArray.push(element.category);
172+
queryArray.push(element.time / 1000);
173+
// Converts milliseconds to seconds to work with postgres
173174
}
174175
return queryArray;
175176
}
@@ -179,7 +180,12 @@ function createQueryArray(dataPointsArray) {
179180
* @param {string} microservice Microservice name
180181
* @param {number} interval Interval for continuous data collection
181182
*/
182-
postgres.health = ({ microservice, interval }) => {
183+
postgres.health = async ({ microservice, interval, mode }) => {
184+
let l = 0;
185+
const currentMetricNames = {};
186+
187+
l = await postgres.getSavedMetricsLength(mode, currentMetricNames);
188+
183189
// Create table for the microservice if it doesn't exist yet
184190
const createTableQuery = `
185191
CREATE TABLE IF NOT EXISTS ${microservice} (
@@ -197,10 +203,14 @@ postgres.health = ({ microservice, interval }) => {
197203
// Save data point at every interval (ms)
198204
setInterval(() => {
199205
collectHealthData()
200-
.then(data => {
201-
const numRows = data.length;
206+
.then(async (data) => {
207+
if (l !== data.length) {
208+
l = await postgres.addMetrics(data, mode, currentMetricNames);
209+
}
210+
const documents = data.filter(el => (el.metric in currentMetricNames));
211+
const numRows = documents.length;
202212
const queryString = createQueryString(numRows, microservice);
203-
const queryArray = createQueryArray(data);
213+
const queryArray = createQueryArray(documents);
204214
// console.log('POSTGRES QUERY STRING: ', queryString);
205215
// console.log('POSTGRES QUERY ARRAY', queryArray);
206216
return client.query(queryString, queryArray);
@@ -357,22 +367,8 @@ postgres.setQueryOnInterval = async (config) => {
357367
metricsQuery(config)
358368
.then(async (parsedArray) => {
359369
if (l !== parsedArray.length) {
360-
console.log('currentMetricNames is less than parsedArray length, new metrics available to track');
361-
console.log('currentMetricNames has a length of: ', l, ' and parsedArray.length is: ', parsedArray.length);
362-
let metricsQueryString = 'INSERT INTO metrics (metric, selected, mode) VALUES ';
363-
parsedArray.forEach(el => {
364-
if (!(el.metric in currentMetricNames)) {
365-
currentMetricNames[el.metric] = true;
366-
metricsQueryString = metricsQueryString.concat(`('${el.metric}', true, '${config.mode}'), `);
367-
}
368-
})
369-
metricsQueryString = metricsQueryString.slice(0, metricsQueryString.lastIndexOf(', ')).concat(';');
370-
await client.query(metricsQueryString);
371-
l = parsedArray.length;
370+
l = await postgres.addMetrics(parsedArray, config.mode, currentMetricNames);
372371
}
373-
return parsedArray;
374-
})
375-
.then(parsedArray => {
376372
const documents = [];
377373
for (const metric of parsedArray) {
378374
if (currentMetricNames[metric.metric]) documents.push(metric)
@@ -387,4 +383,28 @@ postgres.setQueryOnInterval = async (config) => {
387383
}, config.interval);
388384
}
389385

386+
postgres.getSavedMetricsLength = async (mode, currentMetricNames) => {
387+
let currentMetrics = await client.query(`SELECT * FROM metrics WHERE mode='${mode}';`);
388+
if (currentMetrics.rows.length > 0) {
389+
currentMetrics.rows.forEach(el => {
390+
const { metric, selected } = el;
391+
currentMetricNames[metric] = selected;
392+
})
393+
}
394+
return currentMetrics.rows.length ? currentMetrics.rows.length : 0;
395+
}
396+
397+
postgres.addMetrics = async (arr, mode, currentMetricNames) => {
398+
let metricsQueryString = 'INSERT INTO metrics (metric, selected, mode) VALUES ';
399+
arr.forEach(el => {
400+
if (!(el.metric in currentMetricNames)) {
401+
currentMetricNames[el.metric] = true;
402+
metricsQueryString = metricsQueryString.concat(`('${el.metric}', true, '${mode}'), `);
403+
}
404+
})
405+
metricsQueryString = metricsQueryString.slice(0, metricsQueryString.lastIndexOf(', ')).concat(';');
406+
await client.query(metricsQueryString);
407+
return arr.length;
408+
}
409+
390410
module.exports = postgres;

electron/routes/data.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ ipcMain.on('updateSavedMetrics', async (message: Electron.IpcMainEvent, args: Ob
229229
})
230230
// let result = await MetricsModel.update();
231231
}
232+
if (currentDatabaseType === 'SQL' && args.length) {
233+
args.forEach(async (el: any) => {
234+
await pool.query(`UPDATE metrics SET selected=${el.selected} WHERE metric='${el.metric}'`)
235+
})
236+
}
232237
}
233238

234239
catch (err) {

0 commit comments

Comments
 (0)