Prerequisites for running the projects are
- Docker
- MongoDb database connection URL
- Clone the repo
git clone https://github.com/h3mantD/log-ingestor.git
- Go in project directory
cd log-ingestor
- Create .env file using .env.sample
cp .env.sample .env
- Add your mongodb connection url in .env
DB_URL=<your-mongodb-connection-string>
- Run the docker
docker compose up -d
- Open the docker containers shell to install the dependency packages
docker exec -it log-ingestor-laravel.test-1 sh
- Once you are in container shell then execute following commands to install dependencies
composer install npm install npm run build
- Exit the container shell
exit
- Restart the docker container
docker restart log-ingestor-laravel.test-1
The purpose of this API is to ingest logs into the database.
No authentication is required.
The base URL for the API is http://localhost:3000/api/v1
.
Ingests logs into the database.
curl -X POST -H "Accept: application/vnd.api+json" -H "Content-Type: application/vnd.api+json" -d '{
"logs": {
"level": "error",
"message": "Failed to connect to DB",
"resourceId": "server-1234",
"timestamp": "2023-09-15T08:00:00Z",
"traceId": "abc-xyz-123",
"spanId": "span-456",
"commit": "5e5342f",
"metadata": {
"parentResourceId": "server-0987"
}
}
}' http://localhost:3000/api/v1/ingest-logs
Retrieve logs with optional pagination and filtering.
# Retrieve logs, default page size (10 logs per page)
curl -X GET http://localhost:3000/api/v1/logs
# Retrieve logs of page 2
curl -X GET http://localhost:3000/api/v1/logs?page=2
# Retrieve logs of page 2 with page size 1
curl -X GET http://localhost:3000/api/v1/logs?page=2&page_size=1
# Filtering level with error
Curl -X GET http://localhost:3000/api/v1/logs?level=error
# Nesting filtering with level and message
Curl -X GET http://localhost:3000/api/v1/logs?level=error&message=Failed%20to%20connect%20to%20DB
# Filtering with metadata.parentResourceId
Curl -X GET http://localhost:3000/api/v1/logs?metadata.parentResourceId=server-0987
Visit localhost:3000 to view the UI
- Register a new user
- Login with the registered user
- Now you can see the the logs in the UI and also you can filter them
h3mantd - @h3mant_d