Skip to content

Commit 9523d92

Browse files
committed
replace old microservice and docker examples
1 parent 8dabc51 commit 9523d92

File tree

295 files changed

+12095
-45678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+12095
-45678
lines changed

examples/docker/README.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
This sample microservices architecture allows developers to explore the functionality of Chronos but with one docker compose command. This consists of four microservices, which are contained within the directories:
44

5-
- books
6-
- customers
7-
- frontend
8-
- orders
5+
- Auth
6+
- Items
7+
- Inventory
8+
- Orders
9+
- Event-Bus
10+
- Client
911

10-
Each microservice has its own server, which receives requests from both the client and from other microservices.
12+
Each microservice has its own server, which receives requests from both the `Client` and from other microservices by using `Event-bus`.
1113

12-
- _books_, _customers_, and _orders_ also have their own databases, which they can query to respond to those requests.
14+
- _Auth_, _Items_, _Inventory_, and _Orders_ also have their own databases, which they can query to respond to those requests.
1315

14-
The frontend has a reverse proxy set up for proxying requests to the appropriate service (individual application) in the microservice network.
16+
The `Client` is set up to send requests to the appropriate service (individual application) in the microservice network.
1517

1618
In development they're all run separately on different ports, with said ports listening out for requests. This is for demonstration and testing purposes.
1719

@@ -23,66 +25,70 @@ Docker also ensures that the versions that worked well on dev are bundled up and
2325

2426
For additional details on how Chronos works this example, please review the Docker section in the [Chronos NPM Package README](../../chronos_npm_package/README.md).
2527

26-
27-
2828
## Grafana API KEY
2929

3030
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

3232
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 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.
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, which is defined in `chronos-config.ts` file in each microservices application.
3535

3636
4. Stop all containers and delete all images (except Grafana).
3737

3838
## Steps to Run Example
39-
Peform the following steps in each of the _books_, _customers_, _frontend_, and _orders_ directories
4039

41-
1. Add a `.env` file to each of _books_, _customers_, _frontend_, and _orders_ folders with the following key/value pairs:
40+
Peform the following steps in each of the _Auth_, _Items_, _Inventory_, _Orders_, _Client_, and _Event-Bus_ directories
41+
42+
1. Add a `.env` file to each of _Auth_, _Items_, _Inventory_, _Orders_, _Event-Bus_, and _Client_ folders with the following key/value pairs (a `sample.env` file is provided in the `/examples/docker` directory):
4243

4344
- **NOTE**: Ensure that there are no quotes surrounding any of the keys and values.
4445

4546
```
4647
CHRONOS_DB = MongoDB or PostgreSQL
4748
CHRONOS_URI = The URI to the desired MongoDB or PostgreSQL database to save health metrics via Chronos
48-
BOOK_URI = A MongoDB URI for the bookserver microservice to use
49-
CUSTOMER_URI = A MongoDB URI for the customerserver microservice to use
50-
ORDER_URI = A MongoDB URI for the orderserver microservice to use
5149
CHRONOS_GRAFANA_API_KEY = Bearer [the access token you created in above section (Grafana API Key)]
50+
51+
MONGO_URI_AUTH = A MongoDB URI for the auth server microservice to use
52+
MONGO_URI_ITEMS = A MongoDB URI for the items server microservice to use
53+
MONGO_URI_INVENTORY = A MongoDB URI for the inventory server microservice to use
54+
MONGO_URI_ORDERS = A MongoDB URI for the orders server microservice to use
55+
56+
JWT_KEY = A random string used to sign and verify JSON Web Tokens used by the auth service - the random string provided in **sample.env** will work
57+
JWT_LIFETIME = The time-to-expiration of the JSON Web Token used by the auth service - this is set to `1d` in `sample.env` meaning user authentication is valid for 1 day
5258
```
5359

54-
2. Verify that `@chronosmicro/tracker` is a dependency in each of the _books_, _customers_, _frontend_, and _orders_ folders (see the `package.json` in each folder).
60+
2. Verify that `@chronosmicro/tracker` is a dependency in each of the _Auth_, _Items_, _Inventory_, _Orders_, and _Event-Bus_ folders (see the `package.json` in each folder).
5561

56-
- If the @chronosmicro/tracker dependency is listed as a **remote** npm package (i.e. `"@chronosmicro/tracker": "^12.0.1"`) and you've ran `npm install`, no further work is needed continue to step 3. **However, confirm that the "@chronosmicro/tracker" you've installed from npm has the correct information which you will query later because the database automation will build from the npm installed version NOT the root directory level "chronos_npm_package"**
62+
- If the @chronosmicro/tracker dependency is listed as a **remote** npm package (i.e. `"@chronosmicro/tracker": "^12.0.1"`) and you've ran `npm install`, no further work is needed continue to step 3. **However, confirm that the "@chronosmicro/tracker" you've installed from npm has the correct information which you will query later because the database automation will build from the npm installed version NOT the root directory level "chronos_npm_package"**
5763

58-
- 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**
64+
- 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**
5965

6066
3. With the terminal navigated to the _examples/docker_ folder, run the command:
6167

6268
```
6369
docker-compose -f docker-compose.yml up
6470
```
6571

66-
4. If you run into any issues regarding `linux/amd64,linux/arm/v7,linux/arm64/v8` for cadvisor, navigate to the docker-compose.yml and find the cadvisor dictionary and try the below solutions.
67-
1. Change `platform` to `linux/arm64/v8` for M1 Chips and `linux/amd64` for Intel Chips.
68-
2. Change "image" to `image: gcr.io/cadvisor/cadvisor:latest` to `image: gcr.io/cadvisor/cadvisor:v0.47.0`
69-
3. Alternatively, use Docker Buildx to specify multi-platform.
72+
4. If you run into any issues regarding `linux/amd64/v8,linux/arm/v7,linux/arm64/v8` for cadvisor, navigate to the docker-compose.yml and find the cadvisor dictionary and try the below solutions.
73+
1. Change `platform` to `linux/arm64/v8` for M1 Chips and `linux/amd64/v8` for Intel Chips.
74+
1. Change "image" to `image: gcr.io/cadvisor/cadvisor:latest` to `image: gcr.io/cadvisor/cadvisor:v0.47.0`
75+
1. Alternatively, use Docker Buildx to specify multi-platform.
7076

7177
###
7278

7379
You should now see the containers running in your terminal, each reporting `"docker metrics recorded in..."`.
7480

7581
<p align="center">
76-
<img alt="docker data being recorded" src="../../assets/examples_docker_data.png" width="600" height="100">
82+
<img alt="docker data being recorded" src="../../assets/docker_example_logs.png" width="450">
7783
</p>
7884

79-
If this is being displayed for the books, customers, frontend, and orders microservices then the example is successfully saving health metrics to your database of choice!
85+
If this is being displayed for the `Auth`, `Items`, `Inventory`, `Orders` microservices then the example is successfully saving health metrics to your database of choice!
8086

8187
If there is any error when running the applications and the underlying files for a microservice were changed, be sure to delete the previous image before calling `docker-compose -f docker-compose.yml up` again.
8288

8389
- If you do not, the above docker compose command will not know to rebuild the image and the code changes meant to fix any issues will not be rolled into the existing Docker image!
8490

85-
Your microservice health metrics can now be viewed at the given `CHRONOS_URI` or, preferrably, in the Electron.js desktop application.
91+
Your microservice health metrics can now be viewed at the given `CHRONOS_URI` or, preferrably, in the Electron.js desktop application. You can go to `http://localhost:5000/` to log into `Client` to create item, inventory, orders and these requests will be tracked by Chronos.
8692

8793
## To stop and remove containers
8894

@@ -99,18 +105,21 @@ Use `docker compose down` to remove.
99105
</p>
100106

101107
## Insight for how to migrate this example to your own app
108+
102109
To configure Prometheus and Grafana, you can simply copy the below yaml files to your own app.
103-
```
104110

111+
```
105112
prometheus.yml
106113
datasource.yml
107114
dashboard.yml
108-
10619_rev1.json
115+
10619_rev1.json
109116
**(Please note dashboard.yml and 10619_rev1.json is just one of many dashboards available on https://grafana.com/grafana/dashboards/)**
110117
```
118+
111119
Then configure Prometheus and Grafana with your own application's deployments using images.
112120

113121
## License
114122

115123
[MIT](https://github.com/oslabs-beta/Chronos/blob/master/LICENSE.md)
116-
...
124+
125+
...
File renamed without changes.

examples_new/docker/auth/src/__test__/current-user.test.ts renamed to examples/docker/auth/src/__test__/current-user.test.ts

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)