testable
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/dedup"
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/handler"
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/kafka"
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/live"
|
||||
mw "github.com/dbiz/cdp/ingestion/ingest/internal/middleware"
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/ratelimit"
|
||||
"github.com/dbiz/cdp/ingestion/ingest/internal/repo"
|
||||
@@ -74,15 +75,19 @@ func run() error {
|
||||
|
||||
authSvc := service.NewAuthService(writeKeyRepo, redisClient, cfg.WriteKeyCacheTTL, logger)
|
||||
ingestSvc := service.NewIngestService(service.IngestDeps{
|
||||
Producer: producer,
|
||||
Limiter: ratelimit.New(redisClient),
|
||||
Dedup: dedup.New(redisClient, time.Duration(cfg.DedupTTLHours)*time.Hour),
|
||||
Schema: schemaRepo,
|
||||
Log: logger,
|
||||
LateAfter: time.Duration(cfg.LateEventHours) * time.Hour,
|
||||
Producer: producer,
|
||||
Limiter: ratelimit.New(redisClient),
|
||||
Dedup: dedup.New(redisClient, time.Duration(cfg.DedupTTLHours)*time.Hour),
|
||||
Schema: schemaRepo,
|
||||
Log: logger,
|
||||
LateAfter: time.Duration(cfg.LateEventHours) * time.Hour,
|
||||
RateLimitRPS: cfg.RateLimitRPS,
|
||||
})
|
||||
evHandler := handler.NewEventHandler(ingestSvc, logger)
|
||||
|
||||
liveStreamer := live.New(cfg.KafkaBrokers, cfg.KafkaTopicIngest, logger)
|
||||
liveHandler := handler.NewLiveHandler(liveStreamer, logger)
|
||||
|
||||
// ---- HTTP router ------------------------------------------------------
|
||||
r := chi.NewRouter()
|
||||
r.Use(mw.RequestID)
|
||||
@@ -95,6 +100,11 @@ func run() error {
|
||||
r.Get("/health", evHandler.Health)
|
||||
r.Get("/ready", evHandler.Ready)
|
||||
|
||||
// SSE stream of events flowing through Kafka. Intentionally outside the
|
||||
// auth group so the console can subscribe without forwarding the write
|
||||
// key; lock this down before production.
|
||||
r.Get("/live/events", liveHandler.Stream)
|
||||
|
||||
// authenticated routes
|
||||
r.Group(func(rr chi.Router) {
|
||||
rr.Use(mw.Auth(authSvc))
|
||||
@@ -121,8 +131,10 @@ func run() error {
|
||||
Handler: r,
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 30 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
// WriteTimeout intentionally 0 (no deadline) -- /live/events is a
|
||||
// long-lived SSE stream. Per-handler deadlines apply via ctx.
|
||||
WriteTimeout: 0,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
}
|
||||
|
||||
// ---- graceful shutdown ------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user