|
1 | 1 | # Horus
|
2 | 2 |
|
3 |
| -Monitoring containerized microservices with a centralized logging architecture. |
| 3 | +A project for learning about microservices observability. |
4 | 4 |
|
5 |
| -## Dependencies |
| 5 | +* Centralized Logging |
| 6 | +* Distributed Tracing |
| 7 | + |
| 8 | +## Development Requirements |
6 | 9 |
|
7 | 10 | - Docker Compose v1.23.2
|
| 11 | +- OSX or GNU/Linux |
| 12 | + |
| 13 | +## Development Setup |
| 14 | + |
| 15 | +1. Clone this repo and open the root folder in an IDE like *Visual Studio Code*. |
| 16 | + |
| 17 | +2. For each microservice, rename `example.env` to `.env` and supply the needed secrets. |
| 18 | + > TODO: Eliminate this friction. |
| 19 | +
|
| 20 | +3. Start all microservices in *development mode*. |
| 21 | + |
| 22 | + docker-compose -f docker-compose.dev.yml \ |
| 23 | + up -d --build |
| 24 | + |
| 25 | + > In Development Mode |
| 26 | + > |
| 27 | + > - You can attach a remote debugger to a running service Docker for seemless debugging like placing breakpoints and watching variables. |
| 28 | + > - Changes to source files will automatically restart the corresponding docker service. |
| 29 | +
|
| 30 | +4. Optionally, attach the IDE's debugger to a service as follows in Visual Studio Code: *shift+cmd+D > Select a debug configuration > F5*. |
| 31 | + > All vscode debug configurations are stored in *.vscode/launch.json*. You can modify configs as you see fit. |
| 32 | +
|
| 33 | +5. Visit http://localhost:16686 to view traces. |
| 34 | + |
| 35 | +### Useful dev commands |
8 | 36 |
|
9 |
| -## Setup |
| 37 | + # list all running services |
| 38 | + docker-compose -f docker-compose.dev.yml ps |
10 | 39 |
|
11 |
| -1. Signup with an ELK SaaS provider like [Logz.io](logz.io) to obtain an authentication token. Then for each microservice, rename `example.env` to `.env` and supply the needed secrets. |
| 40 | + # stop all services |
| 41 | + docker-compose -f docker-compose.dev.yml down |
12 | 42 |
|
13 |
| -2. Run the following commands. |
| 43 | + # restart all [or specific] service |
| 44 | + docker-compose -f docker-compose.dev.yml \ |
| 45 | + up -d --no-deps --build [service-name] |
14 | 46 |
|
15 |
| - docker-compose build --pull |
16 |
| - docker-compose up -d --force-recreate |
17 |
| - |
18 |
| -3. Then log into your ELK SaaS and view your microservices logs. |
| 47 | + # tail logs from all [or specific] service |
| 48 | + docker-compose -f docker-compose.dev.yml \ |
| 49 | + logs -f [service-name] |
| 50 | + |
| 51 | + # see how an image was built |
| 52 | + docker history <image-name> |
19 | 53 |
|
20 |
| -## Project Documentation |
| 54 | +## Project Architecture |
21 | 55 |
|
22 |
| -### System Architecture |
| 56 | +### Logging Infrastructure |
23 | 57 |
|
24 | 58 | 
|
25 | 59 |
|
26 |
| -I wrote an accompanying [article](https://hackernoon.com/monitoring-containerized-microservices-with-a-centralized-logging-architecture-ba6771c1971a) explaining this architecture. |
| 60 | +Read this [article](https://hackernoon.com/monitoring-containerized-microservices-with-a-centralized-logging-architecture-ba6771c1971a) for more details. |
27 | 61 |
|
28 |
| -## Notes |
| 62 | +### Tracing Infrastructure |
29 | 63 |
|
30 |
| -### Docker Networking |
| 64 | + |
| 65 | + |
| 66 | +Read this [article](#todo) for more details. |
| 67 | + |
| 68 | +## Miscellaneous Notes |
| 69 | + |
| 70 | +### TODO (Improvement Considerations) |
| 71 | + |
| 72 | +- Research **jaeger-operator** |
31 | 73 |
|
32 |
| -By default each containerized process runs in an isolated network namespace. For inter-container communication, place them in the same network namespace...as seen in *docker-compose.yml*. |
| 74 | +- Name Duplication: The value of the `API_SERVER_ADDRESS` variable in *user-simulator/.env* depends on the service name `api-server` specified in *docker-compose.yml*. If we rename the service, we must also change the variable. Is there a way to make this DRY? |
| 75 | + |
| 76 | +- In the log-shipper container, I had to install a logz.io-specific plugin. Can't this step be eliminated since fluentd is capable of connecting to https endpoints without plugins? |
| 77 | + |
| 78 | +- Use sub-second precision for fluentd timestamps (probably best to use nanoseconds.) |
33 | 79 |
|
34 | 80 | ### Best practices
|
35 | 81 |
|
36 | 82 | 1. You can pass secrets for a microservice using the `env_file` attribute in *docker-compose.yml*.
|
37 | 83 | 2. Microservices can communicate using their service names if they are in the same docker network.
|
38 | 84 |
|
39 |
| -### Improvement Considerations |
| 85 | +### Docker Networking |
| 86 | + |
| 87 | +By default each containerized process runs in an isolated network namespace. For inter-container communication, place them in the same network namespace. |
40 | 88 |
|
41 |
| -1. **Name Duplication:** The value of the `API_SERVER_ADDRESS` variable in *user-simulator/.env* depends on the service name `api-server` specified in *docker-compose.yml*. If we rename the service, we must also change the variable. Is there a way to make this DRY? |
| 89 | +### References |
42 | 90 |
|
43 |
| -2. In the log-shipper container, I had to install a logz.io-specific plugin. Can't this step be eliminated since fluentd is capable of connecting to https endpoints without plugins? |
| 91 | +- https://medium.com/lucjuggery/docker-in-development-with-nodemon-d500366e74df |
| 92 | +- https://blog.risingstack.com/how-to-debug-a-node-js-app-in-a-docker-container/ |
| 93 | +- https://codefresh.io/docker-tutorial/debug_node_in_docker/ |
| 94 | +- https://code.visualstudio.com/docs/editor/debugging |
0 commit comments