Skip to content

Commit aa619d4

Browse files
authored
Merge pull request #2 from HEET-Group/devDocker_v2
Dev docker v2
2 parents 5934a03 + 03803b7 commit aa619d4

File tree

6 files changed

+107
-18
lines changed

6 files changed

+107
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Chronos is a comprehensive developer tool that monitors the health and web traff
2727

2828
### With Chronos 12.0:
2929

30-
- Enhanced metrics visualization by integrating more interactive and adaptable Grafana charts, particularly for Docker and Kubernetes use cases.
30+
- Enhanced metrics visualization by integrating more interactive and adaptable Grafana charts for Docker and Kubernetes use cases.
3131
- Achieved an 80% boost in test coverage by formulating comprehensive unit, integration, and end-to-end tests employing Jest and Selenium.
32-
- Rectified issues with the Docker example, ensuring accurate metric display.
32+
- Implemented Prometheus data scraping functionality for Docker containers, facilitating seamless metric collection and monitoring.
3333
- Devised an immersive 3D visualization that effectively illustrates the Kubernetes cluster infrastructure, encompassing Namespace, Service, and Pod entities. This dynamic visualization provides developers and users with heightened insights into intricate resource allocation and configuration within the cluster.
3434
- Streamlined operational effectiveness by coordinating CI/CD pipelines, automating testing workflows, and establishing deployment protocols, ultimately leading to accelerated development cycles and heightened dependability.
3535
- Expanded Typescript coverage to enhance code quality and bolster application resilience.

__tests__/README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Testing
22

33
### Preparation
4+
###
5+
### Frontend Testing
6+
7+
For frontend testing, ensure you've prepared your environment as follows:
48

59
1. React Testing Library versions 13+ require React v18. If your project uses an older version of React, be sure to install version 12
610
```
@@ -18,7 +22,7 @@ npm i @types/node
1822
npm install -D ts-node
1923
```
2024
3. create jest.config.js
21-
```
25+
```js
2226
module.exports = {
2327
verbose: true,
2428
setupFilesAfterEnv: ['./jest_setup/windowMock.js'],
@@ -34,13 +38,16 @@ module.exports = {
3438
};
3539
```
3640
4. make sure jest_setup folder is at root directory of Chronos with styleMock.js and windowMock.js
37-
41+
```js
3842
styleMock.js
3943
```
44+
```js
4045
module.exports = {};
4146
```
47+
```js
4248
windowMock.js
4349
```
50+
```js
4451
// Mock window environment
4552
window.require = require;
4653

@@ -50,9 +57,45 @@ module.exports = {
5057
// Mock get context
5158
HTMLCanvasElement.prototype.getContext = () => {};
5259
```
53-
5. update database info inside test_settings.json
60+
5. update database info inside `test_settings.json`
5461

5562
6. use `npm run test` to run jest tests
63+
###
64+
### Backend Testing
65+
66+
For backend testing, ensure you've prepared your environment as follows:
67+
68+
1. create `jest.config.js`
69+
```js
70+
module.exports = {
71+
roots: ['<rootDir>'], // Set the root directory for test files (adjust this path to your test folder)
72+
testRegex: '(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
73+
collectCoverage: true,
74+
coverageDirectory: 'coverage',
75+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/'],
76+
};
77+
```
78+
2. install additional packages
79+
```
80+
npm i mongodb-memory-server
81+
```
82+
6. use `npm run backend-test` to run jest tests
83+
84+
### End-to-End Testing
85+
86+
Perform end-to-end testing with the following steps:
87+
88+
1. install the following packages
89+
```
90+
npm i selenium-webdriver
91+
npm i chromedriver
92+
```
93+
94+
2. use `npm run dev:app` to start the app
95+
96+
3. use `./node_modules/.bin/chromedriver` to run the Chromedriver executable
97+
98+
4. use `npm run start:e2e` to run the end-to-end tests
5699

57100
## Contributing
58101

app/containers/DockerHealthContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const DockerHealthContainer: React.FC<HealthContainerProps> = React.memo(props =
116116

117117
console.log("plotting grafana")
118118
grafanaChartsArray.push(
119-
<GrafanaEventChart metricName={metricName} token={token} />);
119+
<GrafanaEventChart metricName={metricName} token={token} label={'name'} value={service} />);
120120

121121
}
122122
}

chronos_npm_package/README.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
## What's New?
2+
- Enhanced Metrics Collection: Docker now supports Prometheus metrics scraping, offering improved monitoring capabilities
3+
- Streamlined Visualization: Docker and Kubernetes integrate with Grafana to provide dynamic visualization of collected metrics
4+
- Kubernetes graph type customization and resource data processing
25
- Bug Fixes
36
- Refactored code for additional modularity and customization
4-
- Ability for developers to increase number of metrics monitored for microservices
5-
- Connected to Grafana interface.
6-
- Ability to select graph type and process kubernetes resource data
7+
78
#
89

910
## Features
@@ -12,7 +13,7 @@
1213
- Displays real-time temperature, speed, latency, and memory statistics
1314
- Display and compare multiple microservice metrics in a single graph
1415
- Monitor an Apache Kafka cluster via the JMX Prometheus Exporter
15-
- Monitor Docker and Kubernetes cluster via a Prometheus monitoring server and display charts using Grafana
16+
- Monitor Docker and Kubernetes clusters via a Prometheus monitoring server and display charts using Grafana
1617

1718
#
1819

@@ -54,10 +55,18 @@ module.exports = {
5455
mode: 'kubernetes',
5556
promService: 'prometheus-service',
5657
promPort: 8080,
58+
grafanaAPIKey: process.env.CHRONOS_GRAFANA_API_KEY,
5759

5860
// (c) Apache Kafka
5961
mode: 'kafka',
6062
jmxuri: '<insert URI>',
63+
64+
// (d) Docker
65+
mode: 'docker',
66+
promService: 'docker.for.mac.localhost',
67+
promPort: 9090,
68+
grafanaAPIKey: process.env.CHRONOS_GRAFANA_API_KEY,
69+
6170
/* USE ONE OF THE MODE-SPECIFIC CONFIGURATIONS ABOVE */
6271

6372
// Notifications
@@ -87,7 +96,7 @@ The `database` property is required and takes in the following:
8796
- `type` should be a string and only supports 'MongoDB' and 'PostgreSQL' at this time
8897
- `URI` should be a connection string to the database where you intend Chronos to write and record data regarding health, HTTP route tracing, and container infomation
8998

90-
The `mode` property accepts a string that can either be 'microservices', 'kubernetes', or 'kafka'. There are other settings that depend on the mode choice, so these are broken down in the "Chronos Tracker for Microservices" section.
99+
The `mode` property accepts a string that can either be 'microservices', 'kubernetes', 'kafka', or 'docker'. There are other settings that depend on the mode choice, so these are broken down in the "Chronos Tracker for Microservices" section.
91100

92101
The `notifications` property is an array that can be optionally left empty. It allows developers to be alerted when the server responds to requests with status codes >= 400. To set up notifications, set the value of the `notifications` property to an array of objects, each with a `type` and `settings` property.
93102

@@ -135,6 +144,7 @@ Chronos provides the option to send emails. The properties that should be provi
135144

136145

137146
**NOTE: Email notification settings may require alternative security settings to work**
147+
#
138148

139149
### Chronos Tracker for "Microservices" Mode
140150
The mode `microservices` uses the additional setting `dockerized`, which indicates whether or not the microservice has been containerized with Docker. If omitted, Chronos will assume this server is not running in a container, i.e. `dockerized` will default to _false_.
@@ -269,6 +279,42 @@ When viewing your information in the Chronos Electron application the data will
269279

270280
**NOTE:** We provide a jmx_config.yaml file in the Chronos root folder for use with JMX prometheus that provides some useful baseline metrics to monitor.
271281

282+
#
283+
### Chronos Tracker for "Docker" Mode
284+
Chronos monitors Docker containers by storing metric data through instant Prometheus queries within your Docker container environment.
285+
286+
In `chronos-config.js`, configure the `mode` parameter to `docker`. Additionally, provide the name of the port where the Prometheus server is actively listening inside the container, and specify the name of the Prometheus service to enable DNS-based resolution of its IP address.
287+
288+
Also add a `grafanaAPIKey` section, this API key will authorize Chronos for dashboard creation and updates in Grafana.
289+
290+
```js
291+
// Excerpt from a chronos-config.js
292+
293+
module.exports = {
294+
// ...
295+
296+
mode: 'docker',
297+
promService: 'docker.for.mac.localhost',
298+
promPort: 8080,
299+
300+
grafanaAPIKey: process.env.CHRONOS_GRAFANA_API_KEY,
301+
302+
// ...
303+
}
304+
305+
```
306+
307+
Then, implement the subsequent code snippet within a **SINGLE** microservice that will be deployed only as a **SINGLE** container, and call `Chronos.docker`:
308+
309+
```js
310+
const chronosConfig = require('./chronos-config.js');
311+
const Chronos = require('@chronosmicro/tracker');
312+
const chronos = new Chronos(chronosConfig);
313+
314+
chronos.docker();
315+
```
316+
317+
272318
### Chronos Tracker for gRPC
273319

274320
To monitor your gRPC server, setup `chronos-config.js` as if it was a standard microservices example, but be sure to set the `connection` type to `gRPC`.

chronos_npm_package/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/docker/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ For additional details on how Chronos works this example, please review the Dock
2727

2828
## Grafana API KEY
2929

30-
1. Run docker compose command below (LN 61) to start your Grafana container before you can access your service account token.
30+
1. To initiate your Grafana container and prepare for accessing your service account token, execute the following command: `docker-compose -f docker-compose.yml up`
3131

32-
2. In your browser, go to `localhost:32000`, which will be the login page of grafana. Use `admin` as both username and password to login. You can change the password after login.
32+
2. In your browser, go to `localhost:32000`, which will be the login page of Grafana. Use `admin` as both username and password to login. You can change the password after login.
3333

34-
3. Navigate to `Home -> Administration -> Service accounts`, then click `Add service account` to create an service account. Be sure to choose `Admin` as the role. Then click `Add service account token`, hit `generate`, you are done! Remember this token, you will be using this token to access Grafana HTTP API programmatically.
34+
3. Navigate to `Home -> Administration -> Service accounts`, then click `Add service account` to create a service account. Be sure to choose `Admin` as the role. Then click `Add service account token`, hit `generate`, you are done! Remember this token, you will be using this token to access Grafana HTTP API programmatically.
3535

3636
## Steps to Run Example
3737
Peform the following steps in each of the _books_, _customers_, _frontend_, and _orders_ directories
@@ -55,7 +55,7 @@ CHRONOS_GRAFANA_API_KEY = Bearer [the access token you created in above section
5555

5656
- If you have the dependency as `"@chronosmicro/tracker": "file:./chronos_npm_package"`, which is a **local** file, make sure to change the version from `"file:./chronos_npm_package"` to `"^12.0.1"` and run npm install. **Unless you are wanting to test local copies of the "Chronos_npm_package" file**
5757

58-
3. With the terminal navigated to the the _examples/docker_ folder, run the command:
58+
3. With the terminal navigated to the _examples/docker_ folder, run the command:
5959

6060
```
6161
docker-compose -f docker-compose.yml up

0 commit comments

Comments
 (0)