Skip to content

Commit

Permalink
Merge pull request #3 from felipe-loka/feature/fluentbit
Browse files Browse the repository at this point in the history
add fluentbit
  • Loading branch information
felipe-loka authored Nov 20, 2023
2 parents faffbe9 + 9a96da0 commit 3d1f260
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 20 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ pnpm install
You can check all the environment variables in the `src/config/environments.ts` file. Here is an example of a valid `.env` file:

```shell
PORT="3000"
NODE_ENV="development"
DB_USERNAME="user"
DB_PASSWORD="password123"
DB_NAME="api"
DB_HOST="localhost"
DB_PORT="3306"
DATABASE_URL="mysql://user:password123@localhost:3306/api"
PORT=3000
NODE_ENV=development
DB_USERNAME=user
DB_PASSWORD=password123
DB_NAME=api
DB_HOST=localhost
DB_PORT=3306
DATABASE_URL=mysql://user:password123@localhost:3306/api
LOGGER_FILENAME=poll.log
```

5. Setup database infrastructure

In order to setup the infrastructure the following steps are executed: MySQL Docker container is created, migrations are execute, database is seeded. In order to simplify all these steps a script was created for you, so you can simply run:
In order to setup the infrastructure the following steps are executed: MySQL Docker container is created, migrations are execute, database is seeded, observability stack is created. In order to simplify all these steps a script was created for you, so you can simply run:

```
pnpm infra:up
Expand Down Expand Up @@ -104,10 +105,18 @@ This project fullfills the following requirements:
- User should be able to vote in a given poll
- User should be able to see the vote results of a given poll after voting

## Observability

It's beeing implemented a whole observability stack to monitor the application correctly.

- **Logs**: are being collected by [FluentBit](https://fluentbit.io/) and forwarded to Loki.

In order to fully test this locally you will need to build the local application using Docker. To make it easier a script was created and added in `package.json`, so you can simply run `pnpm container`

## Next Steps

The following requirements should be implemented in next versions:

- Add observability to the application: logs, metrics, traces
- Add observability to the application: metrics, traces
- Add cache layer (e.g. Redis) to minimize latency time
- Validate the need of using a pool of connections to manage the connection to the database
9 changes: 9 additions & 0 deletions config/fluent-bit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pipeline:
inputs:
- name: forward
listen: 0.0.0.0
port: 24224

outputs:
- name: stdout
match: "*"
15 changes: 13 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
mysql:
Expand All @@ -16,7 +16,18 @@ services:
restart: always
command: --default-authentication-plugin=mysql_native_password

fluent-bit:
image: fluent/fluent-bit:2.2.0
container_name: fluent-bit
networks:
- pollNetwork
volumes:
- ./config/fluent-bit.yaml:/fluent-bit/etc/fluent-bit.yaml
ports:
- "24224:24224/tcp"
- "24224:24224/udp"
command: -c /fluent-bit/etc/fluent-bit.yaml

networks:
pollNetwork:
name: pollNetwork
name: pollNetwork
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "pnpm tsc",
"build": "tsc",
"test": " NODE_ENV=test pnpm exec jest --runInBand --forceExit",
"infra:up": "docker compose up -d && sleep 10 && pnpm exec dbmate --migrations-dir ./src/config/database/migrations up && sleep 2 && pnpm exec dbmate --migrations-dir ./src/config/database/seeds up",
"infra:down": "docker compose down",
"db:migrate:up": "pnpm exec dbmate --migrations-dir ./src/config/database/migrations up",
"db:migrate:down": "pnpm exec dbmate --migrations-dir ./src/config/database/migrations down",
"db:seed": "pnpm exec dbmate --migrations-dir ./src/config/database/seeds up",
"start": "ts-node src/index.ts",
"start:dev": "nodemon src/index.ts"
"start:dev": "nodemon src/index.ts",
"container:up": "docker build -t poll-api . && docker container run -d -p 3000:3000 --name poll --env-file .env -e DB_HOST='mysql' --network pollNetwork --log-driver fluentd --log-opt fluentd-address=127.0.0.1:24224 --log-opt fluentd-async-connect=true --log-opt tag=poll-api poll-api",
"container:down": "docker rm -f poll"
},
"keywords": [],
"author": "",
Expand Down Expand Up @@ -52,6 +54,7 @@
"mysql2": "^3.6.3",
"supertest": "^6.3.3",
"uuid": "^9.0.1",
"winston": "^3.11.0",
"zod": "^3.22.4"
}
}
Loading

0 comments on commit 3d1f260

Please sign in to comment.