Skip to content

Commit 9ca2f83

Browse files
authored
Merge pull request #24 from HEET-Group/eisha/dockerGrafana
Eisha/docker grafana
2 parents 49f1a07 + 344e858 commit 9ca2f83

File tree

20 files changed

+148
-263
lines changed

20 files changed

+148
-263
lines changed

__backend-tests__/jest.config.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
module.exports = {
2-
// testEnvironment: 'node', // Use the Node.js environment for testing
3-
// roots: ['<rootDir>/controllers'], // Set the root directory for test files
42

5-
// testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
6-
7-
// // Code coverage settings
8-
// collectCoverage: true,
9-
// coverageDirectory: 'coverage',
10-
11-
// // Specify the test path patterns to ignore frontend tests
12-
// testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
13-
// };
14-
15-
// =======
163
roots: ['<rootDir>'], // Set the root directory for test files (adjust this path to your test folder)
174

185
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',

__backend-tests__/mockdbsetup.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ const mongoose = require("mongoose");
22
const { MongoMemoryServer } = require("mongodb-memory-server");
33

44
let mongo = null;
5+
let uri;
56

67
const connectDB = async () => {
78
mongo = await MongoMemoryServer.create();
8-
const uri = mongo.getUri();
9+
uri = await mongo.getUri();
910

1011
await mongoose.connect(uri, {
1112
useNewUrlParser: true,
1213
useUnifiedTopology: true,
14+
}).then((result) => {
15+
console.log(result.connection.readyState)
16+
console.log(result.connection.host)
17+
}).catch((err) => {
18+
console.log('Unable to connect to MongoMemoryServer')
1319
});
1420
};
1521

@@ -31,4 +37,4 @@ const dropCollections = async () => {
3137
};
3238

3339

34-
module.exports = { connectDB, dropDB, dropCollections}
40+
module.exports = { connectDB, dropDB, dropCollections, uri }

__backend-tests__/mongo.test.js

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,13 @@ const mongoose = require('mongoose');
55
const mongo = require('../chronos_npm_package/controllers/mongo');
66
const ServicesModel = require('../chronos_npm_package/models/ServicesModel');
77
const CommunicationModel = require('../chronos_npm_package/models/CommunicationModel');
8-
const { connectDB, dropDB, dropCollections } = require('./mockdbsetup');
8+
const { connectDB, dropDB, dropCollections, uri } = require('./mockdbsetup');
99
const alert = require('../chronos_npm_package/controllers/alert');
10-
const ContainerInfoFunc = require('../chronos_npm_package/models/ContainerInfo');
1110
const dockerHelper = require('../chronos_npm_package/controllers/dockerHelper');
1211

13-
require('dotenv').config();
14-
15-
const db = 'mongodb+srv://Ok:[email protected]/?retryWrites=true&w=majority';
16-
17-
beforeAll(async () => {
18-
await connectDB();
19-
});
20-
21-
afterAll(async () => {
22-
await dropDB();
23-
});
24-
2512
jest.spyOn(console, 'log').mockImplementation(() => {});
26-
2713
jest.mock('../chronos_npm_package/controllers/alert');
28-
2914
jest.useFakeTimers();
30-
3115
jest.spyOn(global, 'setInterval');
3216

3317
jest.mock('../chronos_npm_package/controllers/healthHelpers', () => {
@@ -56,34 +40,25 @@ jest.mock('../chronos_npm_package/controllers/mongo', () => ({
5640
const HealthModel = {
5741
insertMany: jest.fn(() => Promise.resolve()),
5842
};
43+
const HealthModelFunc = jest.fn(() => HealthModel);
5944

6045
jest.mock('../chronos_npm_package/controllers/dockerHelper', () => ({
6146
...jest.requireActual('../chronos_npm_package/controllers/dockerHelper'),
6247
getDockerContainer: jest.fn(),
6348
readDockerContainer: jest.fn(),
6449
}));
6550

66-
// jest.mock('../../chronos_npm_package/models/ContainerInfo', () => {
67-
// const mockContainerInfoInstance = {
68-
// create: jest.fn(),
69-
// };
70-
// return jest.fn(() => mockContainerInfoInstance);
71-
// });
72-
73-
const HealthModelFunc = jest.fn(() => HealthModel);
74-
7551
describe('mongo.connect', () => {
7652
beforeEach(() => {
7753
jest.clearAllMocks();
7854
});
7955

8056
test('should connect to MongoDB database', async () => {
81-
await mongo.connect({ database: { URI: db } });
57+
await mongo.connect({ database: { URI: uri } });
8258

83-
expect(mongoose.connect).toHaveBeenCalledWith(db);
84-
// expect(console.log).toHaveBeenCalledWith(
85-
// expect.stringContaining('MongoDB database connected at')
86-
// );
59+
expect(console.log).toHaveBeenCalledWith(
60+
expect.stringContaining('MongoDB database connected at')
61+
);
8762
});
8863

8964
test('should handle connection errors', async () => {
@@ -98,12 +73,14 @@ describe('mongo.connect', () => {
9873
});
9974

10075
describe('mongo.services', () => {
101-
beforeEach(() => {
76+
beforeEach(async () => {
10277
jest.clearAllMocks();
78+
await connectDB();
10379
});
10480

10581
afterEach(async () => {
10682
await dropCollections();
83+
await dropDB();
10784
});
10885

10986
test('should create a new document', async () => {
@@ -114,12 +91,14 @@ describe('mongo.services', () => {
11491
});
11592

11693
describe('mongo.communications', () => {
117-
beforeEach(() => {
94+
beforeEach(async () => {
11895
jest.clearAllMocks();
96+
await connectDB();
11997
});
12098

12199
afterEach(async () => {
122100
await dropCollections();
101+
await dropDB();
123102
});
124103

125104
test('should record request cycle and save communication to the database', async () => {
@@ -137,7 +116,7 @@ describe('mongo.communications', () => {
137116
const middleware = mongo.communications({ microservice: 'test3', slack: null, email: null });
138117
await middleware(req, res, () => {});
139118
const savedCommunication = await CommunicationModel.findOne({ microservice: 'test3' });
140-
expect(savedCommunication).toBeDefined(); // The document should be defined if it exists
119+
expect(savedCommunication).toBeDefined();
141120
});
142121

143122
test('should send an alert', async () => {
@@ -166,13 +145,16 @@ describe('mongo.communications', () => {
166145
});
167146

168147
describe('mongo.health', () => {
169-
beforeEach(() => {
148+
beforeEach(async () => {
170149
jest.clearAllMocks();
171150
jest.useFakeTimers();
151+
await connectDB();
172152
});
173153

174-
afterEach(() => {
154+
afterEach(async () => {
175155
jest.clearAllTimers();
156+
await dropCollections();
157+
await dropDB();
176158
});
177159

178160
test('should collect data after the set interval', async () => {
@@ -209,11 +191,12 @@ describe('mongo.docker', () => {
209191
beforeEach(async () => {
210192
jest.clearAllMocks();
211193
jest.useFakeTimers();
194+
await connectDB();
212195
});
213196

214197
afterEach(async () => {
215198
await dropCollections();
216-
jest.clearAllTimers();
199+
await dropDB();
217200
});
218201

219202
test('should collect docker container information', async () => {
@@ -244,6 +227,5 @@ describe('mongo.docker', () => {
244227
expect(dockerHelper.getDockerContainer).toHaveBeenCalledWith(microservice);
245228
jest.advanceTimersByTime(1000);
246229
expect(dockerHelper.readDockerContainer).toHaveBeenCalledWith(mockContainerData);
247-
//expect(mockContainerInfoInstance.create).toHaveBeenCalledWith(mockReadDockerContainerData);
248230
});
249231
});

app/charts/DockerChart.tsx

Lines changed: 0 additions & 66 deletions
This file was deleted.

app/charts/GrafanaEventChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type TimeFrame = '5m' | '15m' | '30m' | '1h' | '2h' | '1d' | '2d';
1414

1515
/**
1616
* @params {EventChartProps} props - the props object containing relevant data.
17-
* @desc Handles k8s metrics. Memoized component to generate event chart with formatted data
17+
* @desc Handles k8s and container metrics. Memoized component to generate event chart with formatted data
1818
* @returns {JSX.Element} The JSX element with the event chart.
1919
*/
2020
const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {

app/charts/RouteChart.jsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/** From Version 5.2 Team:
2-
* This file does not seem to be showing any data.
3-
* Hope a future team figures it out.
4-
* Best of luck!
5-
*/
6-
71
import { makeStyles } from '@material-ui/core/styles';
82
import React, { useContext } from 'react';
93
import Graph from 'react-graph-vis';
@@ -154,12 +148,6 @@ const RouteChart = React.memo(() => {
154148
},
155149
};
156150

157-
// const events = {
158-
// select(event) {
159-
// const { nodes, edges } = event;
160-
// },
161-
// };
162-
163151
if (communicationsData.length > 0 && communicationsData[0].endpoint !== '/') {
164152
return (
165153
<div className="traceContainer">
@@ -168,7 +156,6 @@ const RouteChart = React.memo(() => {
168156
className={classes.paper}
169157
graph={graph}
170158
options={options}
171-
// events={events}
172159
style={{
173160
fontFamily: 'Roboto',
174161
boxShadow: '3px 3px 6px 1px rgb(175, 175, 175)',

app/components/About.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const About: React.FC = React.memo(() => {
1414
* Feel free to change the header for the list of names.
1515
*
1616
*/
17-
const nameArray: JSX.Element[] = ['Haoyu', 'Edwin', 'Tyler', 'Eisha'].map(name => {
17+
const nameArray: JSX.Element[] = ['Haoyu', 'Eisha', 'Edwin', 'Tyler'].map(name => {
1818
return (
1919
<span style={currentMode} className="text">
2020
<p>{`${name}`}</p>
@@ -49,7 +49,7 @@ const About: React.FC = React.memo(() => {
4949
<p style={currentMode} className="text">
5050
Snow, Taylor, Tim, Roberto, Nachiket, Tiffany, Bruno, Danny, Vince, Matt, Derek, Kit,
5151
Grace, Jen, Patty, Stella, Michael, Ronelle, Todd, Greg, Brianna, Brian, Alon, Alan,
52-
Ousman, Ben, Chris, Jenae, Tim, Kirk, Jess, William, Alexander, Elisa, Josh, Troy, Gahl,
52+
Ousman, Ben, Chris, Jenae, Tim, Kirk, Jess, William, Alexander, Elisa, Josh, Troy, Gahl,
5353
Brisa, Kelsi, Lucie, Jeffrey, Justin
5454
</p>
5555
<br />

app/components/Occupied.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** From Version 5.2 Team:
22
* We only fixed linting issues regarding Notifications.
33
* Otherwise, Notifications still does not function properly.
4-
* Good luck!
54
*/
65

76
/* eslint-disable jsx-a11y/label-has-associated-control */

0 commit comments

Comments
 (0)