This is an event collection project designed to quickly and accurately collect events transmitted from applications.
Events are efficiently managed using channels, multiple parallel threads, and schedulers simultaneously.
Additionally, functionality has been implemented to temporarily store data in consideration of errors or memory limitations.
- Event Collection: Collect event data via HTTP POST requests
- OpenSearch Integration: Bulk register event data to OpenSearch in real-time
- Database Backup: Pending data to database when channels are accumulated with too much data or OpenSearch storage fails
- Authentication Middleware: Maintain API security using Bearer tokens
- Runtime Status Monitoring: Check server status via
/ping
endpoint - Asynchronous Task Processing: Asynchronous communication with OpenSearch and pending database
- Appropriate Resource Configuration: Channels are set to 100,000 as memory storage area, and OpenSearch bulk registration threads are set to 10
This project was developed using Rust. Rust and Cargo must be installed on your system.
git clone https://github.com/lee-lou2/rust-event-collector
cd https://github.com/lee-lou2/rust-event-collector
Before running the project, add the following variables to the .env
file:
OPEN_SEARCH_DNS=http://localhost:9200
SERVER_PORT=3000
JWT_SECRET=
SERVER_ENVIRONMENT=local
DATABASE_URL=sqlite://sqlite3.db
cargo run
sh deploy.sh
Server will run at: http://0.0.0.0:3000
(may vary depending on port set in environment variables)
-
Core Components:
- Axum: HTTP server framework
- OpenSearch: Data storage
- SQLite: Temporary storage for failed event data
- Tokio: Asynchronous task executor
-
Workflow:
-
Client calls
/events
API and sends event data. -
Success:
- Attempts to deliver events to channels.
- By default, 1000 channels are prepared.
- If all channels are full, pending data is stored in the database.
- If not full, data is delivered to the channel.
- Data delivered to channels is bulk registered to OpenSearch in groups of 1000.
- Even if not grouped up to 1000, bulk registers events in channels to OpenSearch every 10 seconds.
- Attempts to deliver events to channels.
-
Failure:
- If channels are full or errors occur during OpenSearch registration, pending data is stored in the database.
- Such stored data is queried at 1-minute intervals and attempts to be re-delivered to channels.
- If channels are full or errors occur during OpenSearch registration, pending data is stored in the database.
-
Scheduler periodically attempts to send pending data to channels.
-
Refer to the image below for system operation flow
All endpoints except /ping
require a Bearer token in the header.
If an invalid token is included or missing, an HTTP 401 response is returned.
- Description: Quickly and securely stores events.
- HTTP Method: POST
- Headers:
Authorization: Bearer <API_KEY>
(required): Authentication token for API accessdevice-uuid
(optional): Unique identifier of the device where the event occurredapp-version
(optional): App version informationos-version
(optional): Operating system version information
- Request Body: JSON
- Fields:
log_id
(required): Unique log identifierpage
(required): Page where the event occurredevent
(required): Event namelabel
(optional): Event labeltarget
(optional): Event targetsection
(optional): Section where the event occurredparam
(optional): Additional parameters(JSON)
- Fields:
- Request Example:
curl -X POST http://0.0.0.0:3000/events \
-H "Authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-H "device-uuid: <DEVICE_UUID>" \
-H "app-version: <APP_VERSION>" \
-H "os-version: <OS_VERSION>" \
-d '{
"page": "/home",
"event": "click",
"label": "button_click",
"target": "#button_id",
"section": "header",
"param": {
"key1": "value1"
}
}'
- Response:
- HTTP 200: Event registration request successful
- Description: Check system status.
- Response:
- HTTP 200: Returns "pong" string
- Optimize event data latency
- Detailed handling of OpenSearch and database connection errors
- Add periodic cleanup functionality for event backup data