Skip to content

Consumer - #1

Merged
Ret2Hell merged 8 commits into
mainfrom
dev
Mar 21, 2026
Merged

Ret2Hell merged 8 commits into
mainfrom
dev

Conversation

@Ret2Hell

@Ret2Hell Ret2Hell commented Mar 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Event consumer for processing incoming events
    • Health endpoints for liveness and readiness
    • Structured logging with configurable levels
    • OpenTelemetry tracing support
    • Formalized event data schema for ingestion and processing
  • Chores

    • Updated build and container startup configuration and healthcheck
    • Expanded environment configuration for broker, auth, caching, telemetry, and consumer group
    • CI workflow and linter added
  • Tests

    • New unit tests for consumer and event parsing behaviors

@coderabbitai

coderabbitai Bot commented Mar 21, 2026 •

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 013681e2-8553-478a-bd76-4ab71cbb0d1c

📥 Commits

Reviewing files that changed from the base of the PR and between f20f040 and 3d85867.

📒 Files selected for processing (1)
  • internal/consumer/consumer_test.go

📝 Walkthrough

Walkthrough

Relocates the application entrypoint to cmd/processor, adds a Redpanda-backed event consumer with optional SASL, introduces observability (logger + OTLP tracing), formalizes configuration and event models, adds HTTP health/readiness endpoints, updates build/Docker/mise, and adds CI and linting configs.

Changes

Cohort / File(s) Summary
Build & Runtime
\.air\.toml, Dockerfile, mise\.toml, go\.mod, \.env\.example
Switch build/start targets to cmd/processor; Docker now builds /cmd/processor -> /bin/processor, adds HEALTHCHECK, pins base image; go.mod updated (module path casing, Go 1.26), expanded env vars in .env.example.
CI & Lint
.github/workflows/ci.yml, .golangci.yml
Add CI workflow with test and lint jobs; introduce golangci-lint config enabling errcheck, govet, staticcheck.
Entrypoint & Orchestration
cmd/processor/main.go, main.go
Add new processor main at cmd/processor that loads config, logger, tracer, HTTP server, and event consumer with graceful shutdown and signal handling; remove old main.go root entrypoint.
Configuration
internal/config/config.go
Add ProcessorConfig and LoadProcessorConfig() that reads required env vars (port, Redpanda, Redis, logging, OTEL, consumer group) and fail-fast on missing values.
Event Models
internal/models/event.go
Add typed EventType enum, ValidEventTypes, and structs: SessionContext, EventBatch, RawEvent, InternalEvent, ProcessedEvent.
Consumer Implementation & Tests
internal/consumer/consumer.go, internal/consumer/consumer_test.go
Add EventConsumer using franz-go (kgo.Client) with optional SASL SCRAM (SHA-256/512), manual commits, subscription to raw-events; include tests for auth variants, JSON unmarshalling, and Run/Close behaviors.
Observability
internal/observability/logger.go, internal/observability/tracing.go
Add NewLogger() returning JSON slog logger and InitTracer() configuring OTLP HTTP exporter and tracer provider with batch processor and service resource.
HTTP Server & Health
internal/server/server.go, internal/server/health.go
Add NewServer(addr) wiring /healthz and /readyz; readiness managed via atomic boolean with SetReady()/SetNotReady(); JSON responses and appropriate HTTP statuses implemented.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Processor Main
    participant Config as Config Loader
    participant Logger as Logger
    participant Tracer as Tracer
    participant Server as HTTP Server
    participant Consumer as Event Consumer
    participant Redpanda as Redpanda
    participant Signals as OS Signals

    Main->>Config: LoadProcessorConfig()
    Config-->>Main: ProcessorConfig
    Main->>Logger: NewLogger(service, level)
    Logger-->>Main: slog.Logger
    Main->>Tracer: InitTracer(ctx, name, endpoint)
    Tracer-->>Main: shutdown func / err
    Main->>Server: NewServer(addr)
    Server-->>Main: *http.Server
    Main->>Consumer: NewEventConsumer(brokers,...)
    Consumer->>Redpanda: Connect & Subscribe(raw-events)
    Main->>Server: Start (goroutine)
    Main->>Consumer: Run(ctx) (goroutine)
    Redpanda-->>Consumer: Event batches
    Consumer->>Consumer: Unmarshal & process
    Consumer->>Redpanda: Commit offsets
    Signals->>Main: SIGTERM/SIGINT
    Main->>Server: Graceful shutdown (SetNotReady, Shutdown)
    Main->>Consumer: Close()
    Main->>Tracer: Call shutdown()
    Main-->>Main: Exit
Loading
sequenceDiagram
    participant Client as HTTP Client
    participant Server as HTTP Server
    participant Health as Health Module
    participant Ready as Ready State (atomic.Bool)

    Client->>Server: GET /healthz
    Server->>Health: Healthz()
    Health-->>Client: 200 {"status":"ok"}

    Client->>Server: GET /readyz
    Server->>Health: Readyz()
    Health->>Ready: check
    Ready-->>Health: false
    Health-->>Client: 503 {"status":"not ready"}
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 I hopped from root to tidy grove,

Built a processor, traced each trove,
Events buzzed from Redpanda's hive,
Health checks beat so services thrive,
Logs and traces — all alive! 🥕✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@Ret2Hell
Ret2Hell merged commit a8c3f2e into main Mar 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant