Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Prefer these sources over guessing when behavior or schema matters.
| HTTP REST API | `manager/` |
| External messages | `listener/`, topic names in code and `conf/` |
| Evaluation | `evaluator/`, topic names in code and `conf/` |
| Advisory aggregation | `aggregator/` |
| Advisory sync | `tasks/vmaas_sync/` |
| Migrations | `database_admin/migrations/` (verify naming against existing migrations) |
| Migration flow, session flags, ops runbook | `database_admin/update.go`, [docs/md/database.md#migrations](docs/md/database.md#migrations), [docs/md/major-migration-runbook.md](docs/md/major-migration-runbook.md) |
Expand All @@ -55,11 +56,17 @@ Listener Component
Evaluator-Upload Component
↓ (calls VMaaS /updates)
↓ (updates system_advisories, advisory_account_data)
↓ (updates system_advisories)
↓ (updates advisory_account_data — legacy table, to be removed)
[platform.notifications.ingress] (optional)
[platform.remediation-updates.patch] (optional)
[platform.inventory.host-apps] (optional)
[patchman.advisory.update] Kafka Topic (changed advisory IDs)
Aggregator Component
↓ (recounts from system_advisories, writes aggregates to account_advisory — new workspace-scoped table)
[platform.notifications.ingress] (optional)
```

### Advisory Sync Flow
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ADD --chown=insights:insights scripts /go/src/app/scripts
ADD --chown=insights:insights database_admin /go/src/app/database_admin
ADD --chown=insights:insights docs /go/src/app/docs
ADD --chown=insights:insights evaluator /go/src/app/evaluator
ADD --chown=insights:insights aggregator /go/src/app/aggregator
ADD --chown=insights:insights listener /go/src/app/listener
ADD --chown=insights:insights tasks /go/src/app/tasks
ADD --chown=insights:insights base /go/src/app/base
Expand Down
64 changes: 64 additions & 0 deletions aggregator/aggregator.go
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)
Comment on lines +19 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider validating consumer_count to avoid silently running with zero consumers

If consumer_count is 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 <= 0 to 1 and log a warning) to guard against misconfiguration.

Suggested implementation:

import (
	"app/base"
	"app/base/core"
	"app/base/mqueue"
	"app/base/utils"
	"log"
	"sync"

	"github.com/gin-gonic/gin"
)
func readPodConfig() {
	consumerCount = utils.PodConfig.GetInt("consumer_count", 1)
	if consumerCount <= 0 {
		log.Printf("invalid consumer_count=%d, defaulting to 1", consumerCount)
		consumerCount = 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")
}
10 changes: 10 additions & 0 deletions aggregator/events.go
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
}
14 changes: 14 additions & 0 deletions aggregator/notifications.go
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Align instant_notifications config with notifications writer initialization

configureNotifications still creates a writer whenever NotificationsTopic is set, ignoring instant_notifications. If that flag is intended to control whether notifications are produced, also check enableNotifications before initializing the writer; otherwise, remove the unused flag to avoid misleading config.

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 instant_notifications with writer initialization, ensure:

  1. enableNotifications is derived from the instant_notifications config (or equivalent) in your configuration bootstrap code, e.g.:
    • enableNotifications = utils.CoreCfg.InstantNotifications (or similar).
  2. Any code path that toggles instant_notifications updates enableNotifications before configureNotifications() is called.
  3. If enableNotifications is not yet defined in this package, declare it (likely as a bool at package scope) and initialize it alongside other feature flags, respecting existing conventions in the aggregator package.

}
}
1 change: 1 addition & 0 deletions conf/aggregator.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POD_CONFIG=label=aggregator
2 changes: 2 additions & 0 deletions conf/aggregator_common.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_USER=evaluator
DB_PASSWD=evaluator
57 changes: 57 additions & 0 deletions deploy/clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,51 @@ objects:
limits: {cpu: '${CPU_LIMIT_EVALUATOR_USER_EVALUATION}', memory: '${MEM_LIMIT_EVALUATOR_USER_EVALUATION}'}
requests: {cpu: '${CPU_REQUEST_EVALUATOR_USER_EVALUATION}', memory: '${MEM_REQUEST_EVALUATOR_USER_EVALUATION}'}

- name: aggregator
replicas: ${{REPLICAS_AGGREGATOR}}
webServices:
public:
enabled: true
private:
enabled: true
metrics:
enabled: true
podSpec:
image: ${IMAGE}:${IMAGE_TAG}
initContainers:
- name: check-for-db
image: ${IMAGE}:${IMAGE_TAG}
command:
- ./database_admin/check-upgraded.sh
env:
- {name: POD_CONFIG, value: '${DATABASE_ADMIN_CONFIG}'}
command:
- ./scripts/entrypoint.sh
- aggregator
env:
- {name: LOG_LEVEL, value: '${LOG_LEVEL_AGGREGATOR}'}
- {name: GIN_MODE, value: '${GIN_MODE}'}
- {name: SENTRY_DSN, valueFrom: {secretKeyRef: {name: patchman-sentry, key: sentry-dsn}}}
- {name: SHOW_CLOWDER_VARS, value: ''}
- {name: DB_DEBUG, value: '${DB_DEBUG_AGGREGATOR}'}
- {name: DB_USER, value: evaluator}
- {name: DB_PASSWD, valueFrom: {secretKeyRef: {name: patchman-engine-database-passwords,
key: evaluator-database-password}}}
- {name: KAFKA_GROUP, value: patchman}
- {name: KAFKA_READER_MAX_ATTEMPTS, value: '${KAFKA_READER_MAX_ATTEMPTS}'}
- {name: KAFKA_WRITER_MAX_ATTEMPTS, value: '${KAFKA_WRITER_MAX_ATTEMPTS}'}
- {name: NOTIFICATIONS_TOPIC, value: 'platform.notifications.ingress'}
- {name: ADVISORY_UPDATE_TOPIC, value: 'patchman.advisory.update'}
- {name: SSL_CERT_DIR, value: '${SSL_CERT_DIR}'}
- {name: GOGC, value: '${GOGC}'}
- {name: ENABLE_PROFILER, value: '${ENABLE_PROFILER_AGGREGATOR}'}
- {name: GOMEMLIMIT, value: '${GOMEMLIMIT_AGGREGATOR}'}
- {name: POD_CONFIG, value: 'label=aggregator;${AGGREGATOR_CONFIG}'}
- {name: CONSOLEDOT_HOSTNAME, value: '${CONSOLEDOT_HOSTNAME}'}
resources:
limits: {cpu: '${CPU_LIMIT_AGGREGATOR}', memory: '${MEM_LIMIT_AGGREGATOR}'}
requests: {cpu: '${CPU_REQUEST_AGGREGATOR}', memory: '${MEM_REQUEST_AGGREGATOR}'}

jobs:
- name: db-migration
completions: 1
Expand Down Expand Up @@ -785,6 +830,18 @@ parameters:
- {name: ENABLE_PROFILER_EVALUATOR_USER_EVALUATION, value: 'false'}
- {name: EVALUATOR_USER_EVALUATION_CONFIG, value: ''}

# Aggregator
- {name: REPLICAS_AGGREGATOR, value: '0'}
- {name: LOG_LEVEL_AGGREGATOR, value: debug}
- {name: DB_DEBUG_AGGREGATOR, value: 'false'}
- {name: CPU_LIMIT_AGGREGATOR, value: 500m}
- {name: MEM_LIMIT_AGGREGATOR, value: 512Mi}
- {name: CPU_REQUEST_AGGREGATOR, value: 250m}
- {name: MEM_REQUEST_AGGREGATOR, value: 256Mi}
- {name: ENABLE_PROFILER_AGGREGATOR, value: 'false'}
- {name: GOMEMLIMIT_AGGREGATOR, value: '460MiB'}
- {name: AGGREGATOR_CONFIG, value: ''}

# JOBS
- {name: LOG_LEVEL_JOBS, value: debug}
- {name: DB_DEBUG_JOBS, value: 'false'}
Expand Down
21 changes: 21 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ services:
security_opt:
- label=disable

aggregator:
container_name: aggregator
image: patchman-engine-app
env_file:
- ./conf/common.env
- ./conf/aggregator_common.env
- ./conf/aggregator.env
command: ./dev/scripts/docker-compose-entrypoint.sh aggregator
ports:
- 8087:8080
- 9007:9000 # private port - pprof
depends_on:
- db
- platform
volumes:
- ./dev:/go/src/app/dev
- ./dev/database/secrets:/opt/postgresql
- ./dev/kafka/secrets:/opt/kafka
security_opt:
- label=disable

vmaas_sync:
container_name: vmaas_sync
image: patchman-engine-app
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ services:
security_opt:
- label=disable

aggregator:
container_name: aggregator
image: patchman-engine-app
env_file:
- ./conf/common.env
- ./conf/aggregator_common.env
- ./conf/aggregator.env
- ./conf/gorun.env
command: ./dev/scripts/docker-compose-entrypoint.sh aggregator
ports:
- 8087:8080
- 9007:9000 # private port - pprof
depends_on:
- db
- platform
volumes:
- ./:/go/src/app
security_opt:
- label=disable

vmaas_sync:
container_name: vmaas_sync
image: patchman-engine-app
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"app/aggregator"
"app/base"
"app/base/utils"
"app/database_admin"
Expand Down Expand Up @@ -38,6 +39,9 @@ func main() {
case "evaluator":
evaluator.RunEvaluator()
return
case "aggregator":
aggregator.RunAggregator()
return
case "migrate":
database_admin.UpdateDB(os.Args[2])
return
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-dockercomposes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sed \
-e "s|INSTALL_TOOLS=yes|INSTALL_TOOLS=no|" \
-e "s|target: buildimg|target: runtimeimg|" \
-e "/ - \.\/conf\/gorun.env/ d" \
-e "/ \(db_admin\|db_feed\|manager\|listener\|evaluator_recalc\|evaluator_upload\|evaluator_user_evaluation\|vmaas_sync\|admin\|migrate_system_package2\):/,/^$/ {
-e "/ \(db_admin\|db_feed\|manager\|listener\|evaluator_recalc\|evaluator_upload\|evaluator_user_evaluation\|aggregator\|vmaas_sync\|admin\|migrate_system_package2\):/,/^$/ {
s/- \.\/:\/go\/src\/app/- \.\/dev:\/go\/src\/app\/dev\n\
- .\/dev\/database\/secrets:\/opt\/postgresql\n\
- \.\/dev\/kafka\/secrets:\/opt\/kafka/
Expand Down
Loading