Conversation
- Deleted Cargo.toml, Dockerfile, and all source files including config, dlq, flush, models, ttl_index, tuning, and main logic. - This commit removes the entire codebase, effectively archiving the project.
- Added configuration loading from environment variables with default values. - Created database connection pool and ensured necessary tables exist. - Implemented bulk insert functions for event logs, guardian logs, and join logs. - Developed a dead letter queue (DLQ) reprocessor for handling failed logs. - Introduced flushing mechanism to transfer logs from Redis to PostgreSQL. - Added models for event logs, guardian logs, and join logs with JSON serialization. - Implemented Redis client for interacting with Redis data structures. - Created tuning logic to dynamically adjust batch size and interval based on queue length. - Comprehensive unit tests for all new functionalities to ensure reliability.
There was a problem hiding this comment.
Pull request overview
This PR represents a complete rewrite of the worker service from Rust to Go, transitioning from MongoDB to PostgreSQL as the primary database. The change aims to improve compilation times and maintainability.
Key Changes:
- Language Migration: Full rewrite from Rust to Go
- Database Change: MongoDB replaced with PostgreSQL
- Architecture: Maintains similar worker pattern with Redis queues, batch processing, and DLQ support
- Test Coverage: Comprehensive unit tests added for all major components
Reviewed changes
Copilot reviewed 26 out of 29 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Go module configuration with invalid version 1.25.3 |
| cmd/worker/main.go | New main entry point with graceful shutdown and concurrent log flushing |
| internal/config/config.go | Configuration management with environment variables |
| internal/database/database.go | PostgreSQL implementation replacing MongoDB |
| internal/redis/redis.go | Redis client wrapper for list operations |
| internal/flush/flush.go | Core flush logic for batch processing |
| internal/dlq/dlq.go | Dead letter queue reprocessor |
| internal/tuning/tuning.go | Adaptive batch size and interval tuning |
| internal/models/models.go | Data models for EventLog, GuardianLog, JoinLog |
| Dockerfile | Multi-stage Go build replacing Rust build |
| README.md | Updated documentation for Go implementation |
| Makefile | New build, test, and development targets |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/database/database.go
Outdated
|
|
||
| batch := &pgx.Batch{} | ||
| for _, log := range logs { | ||
| dataJSON, _ := json.Marshal(log["data"]) |
There was a problem hiding this comment.
JSON marshaling errors in bulk insert functions are silently ignored with _. This could lead to data loss. Consider logging these errors or handling them appropriately.
| if config.ConnConfig.TLSConfig == nil { | ||
| config.ConnConfig.TLSConfig = nil // Disable TLS | ||
| } |
There was a problem hiding this comment.
The code setting TLS config to nil when it's already nil is redundant. Consider removing this or adding a proper comment explaining the purpose of this check.
| if config.ConnConfig.TLSConfig == nil { | |
| config.ConnConfig.TLSConfig = nil // Disable TLS | |
| } | |
| // If TLSConfig is nil, TLS is disabled (handled by pgx) |
|
|
||
| ## Prerequisites | ||
|
|
||
| - Go 1.23+ |
There was a problem hiding this comment.
The README states "Go 1.23+" as a prerequisite, but go.mod specifies go 1.25.3 which doesn't exist. These should be consistent and use a valid Go version.
| - Go 1.23+ | |
| - Go 1.22+ |
| @@ -1,30 +1,25 @@ | |||
| # Builder stage | |||
| FROM rust:1.85-slim as builder | |||
| FROM golang:1.23-alpine AS builder | |||
There was a problem hiding this comment.
The Dockerfile uses golang:1.23-alpine which is correct, but this is inconsistent with go.mod which specifies go 1.25.3. Use a valid and consistent Go version across all files.
| FROM golang:1.23-alpine AS builder | |
| FROM golang:1.25.3-alpine AS builder |
| func FlushLogs( | ||
| ctx context.Context, | ||
| redisClient RedisClient, | ||
| db interface{}, |
There was a problem hiding this comment.
The db parameter is declared but never used in the FlushLogs function. Either remove it or document why it's kept for interface compatibility.
| db interface{}, |
| if err != nil { | ||
| // On failure, push to DLQ | ||
| for _, logData := range parsedLogs { | ||
| jsonBytes, _ := json.Marshal(logData) |
There was a problem hiding this comment.
Error handling silently ignores JSON marshaling errors with _. This could hide data corruption issues. Consider logging the error or returning it.
| log.Error().Err(err).Msg("Failed to reprocess DLQ logs, pushing back") | ||
| // Push back to DLQ | ||
| for _, logData := range parsedLogs { | ||
| jsonBytes, _ := json.Marshal(logData) |
There was a problem hiding this comment.
Similarly, JSON marshaling errors are silently ignored with _. Consider logging these errors to track data issues.
|
@copilot import { export const events = pgTable( }, export const actionThreads = pgTable( export const actionThreadsSettings = pgTable( export const loggingSettings = pgTable( export const guardianLogs = pgTable( export const joinLogs = pgTable( export const aggregatedDailyStats = pgTable( export const warnings = pgTable( }, /**
/**
/**
export type ModeratorNote = typeof moderatorNotes.$inferSelect; this is my current version of the drizzle schema as we discussed earily i only want to fetch events from redis and then push into the database in bulk |
This allows for a faster compilation time also this is much better to maintain rather than rust which was overkill.