-
Notifications
You must be signed in to change notification settings - Fork 47
feat: add aggregator service with Kafka consumer skeleton #2263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package aggregator | ||
|
|
||
| import ( | ||
| "app/base" | ||
| "app/base/core" | ||
| "app/base/mqueue" | ||
| "app/base/utils" | ||
| "sync" | ||
|
|
||
| "github.com/gin-gonic/gin" | ||
| ) | ||
|
|
||
| var ( | ||
| advisoryUpdateTopic string | ||
| enableNotifications bool | ||
| consumerCount int | ||
| ) | ||
|
|
||
| func readPodConfig() { | ||
| consumerCount = utils.PodConfig.GetInt("consumer_count", 1) | ||
| enableNotifications = utils.PodConfig.GetBool("instant_notifications", false) | ||
| } | ||
|
|
||
| func configure() { | ||
| advisoryUpdateTopic = utils.FailIfEmpty(utils.CoreCfg.AdvisoryUpdateTopic, "ADVISORY_UPDATE_TOPIC") | ||
| configureNotifications() | ||
| } | ||
|
|
||
| func runServer() { | ||
| app := gin.New() | ||
| core.InitProbes(app) | ||
| go base.TryExposeOnMetricsPort(app) | ||
|
|
||
| err := utils.RunServer(base.Context, app, utils.CoreCfg.PublicPort) | ||
| if err != nil { | ||
| utils.LogError("err", err.Error()) | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| func subscribeToAdvisoryUpdates(wg *sync.WaitGroup, readerBuilder mqueue.CreateReader) { | ||
| handler := mqueue.MakeRetryingHandler(advisoryUpdateHandler) | ||
| for i := 0; i < consumerCount; i++ { | ||
| mqueue.SpawnReader(base.Context, wg, advisoryUpdateTopic, readerBuilder, handler) | ||
| utils.LogDebug("spawned advisory update reader", i) | ||
| } | ||
| utils.LogInfo("connected to kafka topics") | ||
| } | ||
|
|
||
| func RunAggregator() { | ||
| var wg sync.WaitGroup | ||
|
|
||
| utils.LogInfo("aggregator starting") | ||
| core.ConfigureApp() | ||
| readPodConfig() | ||
| configure() | ||
|
|
||
| go runServer() | ||
| go utils.RunProfiler() | ||
| subscribeToAdvisoryUpdates(&wg, mqueue.NewKafkaReaderFromEnv) | ||
|
|
||
| wg.Wait() | ||
| utils.LogInfo("aggregator completed") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package aggregator | ||
|
|
||
| import ( | ||
| "app/base/mqueue" | ||
| ) | ||
|
|
||
| // TODO: stub - will process advisory update events in batches and update account_advisory table | ||
| func advisoryUpdateHandler(m mqueue.KafkaMessage) error { | ||
| return nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package aggregator | ||
|
|
||
| import ( | ||
| "app/base/mqueue" | ||
| "app/base/utils" | ||
| ) | ||
|
|
||
| var notificationsPublisher mqueue.Writer | ||
|
|
||
| func configureNotifications() { | ||
| if topic := utils.CoreCfg.NotificationsTopic; topic != "" { | ||
| notificationsPublisher = mqueue.NewKafkaWriterFromEnv(topic) | ||
|
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Align
Suggested implementation: func configureNotifications() {
// Only initialize the notifications writer if notifications are enabled
if !enableNotifications {
return
}
if topic := utils.CoreCfg.NotificationsTopic; topic != "" {
notificationsPublisher = mqueue.NewKafkaWriterFromEnv(topic)
}
}To fully align
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| POD_CONFIG=label=aggregator |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| DB_USER=evaluator | ||
| DB_PASSWD=evaluator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider validating
consumer_countto avoid silently running with zero consumersIf
consumer_countis set to 0 or negative, no readers will be spawned and the service will appear healthy while not consuming messages. Consider enforcing a minimum of 1 (e.g., clamp<= 0to 1 and log a warning) to guard against misconfiguration.Suggested implementation: