Repository navigation
RHINENG-33526: always sync template advisories from kafka advisory_ids - #2381
MichaelMraka wants to merge 4 commits into
Conversation
Reviewer's GuideImplementationApply template advisory snapshots from Kafka event advisory_ids on both template creation and update, including empty snapshots, while preserving diff and re-evaluation behavior.
Remove the Content Sources advisory HTTP client and its platform mock now that template advisory synchronization no longer calls them.
Remove identity encoding and template-identity helpers that were used only to authenticate Content Sources API requests.
Remove listener state and setup for the Content Sources client and the templates_with_advisories mode switch.
ConfigurationRemove obsolete Content Sources address and user settings, listener environment values, and the optional deployment dependency.
DocumentationRevise architecture and database guidance to state that advisory associations are sourced from Kafka event snapshots, with missing or empty IDs clearing associations.
TestsUpdate tests to cover Kafka-provided advisory snapshots and remove tests that exercised the retired Content Sources HTTP path.
Delete unit tests and imports dedicated to the removed identity encoding and helper functions.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2381 +/- ##
==========================================
- Coverage 66.82% 66.76% -0.06%
==========================================
Files 158 157 -1
Lines 9081 9012 -69
==========================================
- Hits 6068 6017 -51
+ Misses 3011 2993 -18
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Content Sources sends the advisory snapshot on template create and update, so the listener no longer switches on templates_with_advisories.
Template advisory snapshots now come only from the kafka message, so the advisories API client and its platform mock are unused.
…ries The listener no longer calls content-sources for advisory ids, so the address, service user, and request-identity helpers are unused.
The templates_with_advisories flag and the content-sources advisories HTTP fetch are no longer part of the listener flow.
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="listener/templates.go" line_range="152" />
<code_context>
- if err != nil {
- return errors.Wrap(err, "syncing template advisories")
- }
+ err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)
+ if err != nil {
+ return errors.Wrap(err, "syncing template advisories from message")
</code_context>
<issue_to_address>
**Advisory updates are not retried**
When saving a template succeeds but advisory synchronization fails, `TemplatesMessageHandler` logs the error and returns nil, so `MakeRetryingHandler` acknowledges the Kafka message and the saved template keeps stale advisory links until another event arrives.
Propagate template-save and advisory-sync errors from `TemplatesMessageHandler` so the retrying handler retries the message.
Also at `listener/templates.go:153`.
</issue_to_address>
### Comment 2
<location path="listener/templates.go" line_range="152" />
<code_context>
- if err != nil {
- return errors.Wrap(err, "syncing template advisories")
- }
+ err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)
+ if err != nil {
+ return errors.Wrap(err, "syncing template advisories from message")
</code_context>
<issue_to_address>
**Recalculation can be lost after commit**
When template advisory rows change while the recalculation Kafka send fails, `applyTemplateAdvisories` commits the changed rows before requesting system recalculation. If the recalculation message cannot be sent, the send path only logs the failure and returns success, so the Kafka event is acknowledged while affected systems retain evaluations based on the old advisory set.
Make recalculation delivery durable, for example with a transactional outbox or a retryable error that is propagated after commit.
</issue_to_address>
### Comment 3
<location path="listener/templates.go" line_range="152" />
<code_context>
- if err != nil {
- return errors.Wrap(err, "syncing template advisories")
- }
+ err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)
+ if err != nil {
+ return errors.Wrap(err, "syncing template advisories from message")
</code_context>
<issue_to_address>
**Older events restore stale advisories**
When an older template event is delivered after a newer event for the same template, `applyTemplateAdvisories` applies the older snapshot without checking event age or version, replacing the newer advisory set and leaving evaluation based on stale template advisories.
Track event ordering and ignore snapshots older than the latest applied event.
</issue_to_address>
### Comment 4
<location path="listener/template_advisories.go" line_range="31" />
<code_context>
-package content_sources
-
-import (
- "app/base/api"
</code_context>
<issue_to_address>
**Concurrent snapshots leave mixed links**
When two handlers apply different snapshots for the same template concurrently, `applyTemplateAdvisories` reads the stored set and computes each diff before opening its write transaction, so both handlers can diff against the same old set and commit additions from both snapshots; the stored links match neither snapshot.
Serialize advisory updates per template or compute and apply each diff under a transaction that prevents concurrent updates from using the same old set.
Also at `listener/templates.go:152`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 4 findings to address first, and if a template event omits advisory_ids, the handler treats it as an empty snapshot and deletes that template’s stored advisory links, potentially changing later evaluations. Reverting does not restore deleted links, but replaying or re-syncing template events can repair them.
Blocking findings: listener/templates.go:152, listener/templates.go:152, listener/templates.go:152, listener/template_advisories.go:31
| if err != nil { | ||
| return errors.Wrap(err, "syncing template advisories") | ||
| } | ||
| err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs) |
There was a problem hiding this comment.
🟡 Medium · Advisory updates are not retried
When saving a template succeeds but advisory synchronization fails, TemplatesMessageHandler logs the error and returns nil, so MakeRetryingHandler acknowledges the Kafka message and the saved template keeps stale advisory links until another event arrives.
Propagate template-save and advisory-sync errors from TemplatesMessageHandler so the retrying handler retries the message.
Also at listener/templates.go:153.
Prompt for AI agents
In `listener/templates.go` at line 152:
**Advisory updates are not retried**
When saving a template succeeds but advisory synchronization fails, `TemplatesMessageHandler` logs the error and returns nil, so `MakeRetryingHandler` acknowledges the Kafka message and the saved template keeps stale advisory links until another event arrives.
Propagate template-save and advisory-sync errors from `TemplatesMessageHandler` so the retrying handler retries the message.
Also at `listener/templates.go:153`.| if err != nil { | ||
| return errors.Wrap(err, "syncing template advisories") | ||
| } | ||
| err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs) |
There was a problem hiding this comment.
🟡 Medium · Recalculation can be lost after commit
When template advisory rows change while the recalculation Kafka send fails, applyTemplateAdvisories commits the changed rows before requesting system recalculation. If the recalculation message cannot be sent, the send path only logs the failure and returns success, so the Kafka event is acknowledged while affected systems retain evaluations based on the old advisory set.
Make recalculation delivery durable, for example with a transactional outbox or a retryable error that is propagated after commit.
Prompt for AI agents
In `listener/templates.go` at line 152:
**Recalculation can be lost after commit**
When template advisory rows change while the recalculation Kafka send fails, `applyTemplateAdvisories` commits the changed rows before requesting system recalculation. If the recalculation message cannot be sent, the send path only logs the failure and returns success, so the Kafka event is acknowledged while affected systems retain evaluations based on the old advisory set.
Make recalculation delivery durable, for example with a transactional outbox or a retryable error that is propagated after commit.| if err != nil { | ||
| return errors.Wrap(err, "syncing template advisories") | ||
| } | ||
| err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs) |
There was a problem hiding this comment.
🟡 Medium · Older events restore stale advisories
When an older template event is delivered after a newer event for the same template, applyTemplateAdvisories applies the older snapshot without checking event age or version, replacing the newer advisory set and leaving evaluation based on stale template advisories.
Track event ordering and ignore snapshots older than the latest applied event.
Prompt for AI agents
In `listener/templates.go` at line 152:
**Older events restore stale advisories**
When an older template event is delivered after a newer event for the same template, `applyTemplateAdvisories` applies the older snapshot without checking event age or version, replacing the newer advisory set and leaving evaluation based on stale template advisories.
Track event ordering and ignore snapshots older than the latest applied event.| } | ||
| return applyTemplateAdvisories(ctx, accountID, templateID, templateUUID, orgID, current.AdvisoryIDs) | ||
| } | ||
|
|
There was a problem hiding this comment.
🟡 Medium · Concurrent snapshots leave mixed links
When two handlers apply different snapshots for the same template concurrently, applyTemplateAdvisories reads the stored set and computes each diff before opening its write transaction, so both handlers can diff against the same old set and commit additions from both snapshots; the stored links match neither snapshot.
Serialize advisory updates per template or compute and apply each diff under a transaction that prevents concurrent updates from using the same old set.
Also at listener/templates.go:152.
Prompt for AI agents
In `listener/template_advisories.go` at line 31:
**Concurrent snapshots leave mixed links**
When two handlers apply different snapshots for the same template concurrently, `applyTemplateAdvisories` reads the stored set and computes each diff before opening its write transaction, so both handlers can diff against the same old set and commit additions from both snapshots; the stored links match neither snapshot.
Serialize advisory updates per template or compute and apply each diff under a transaction that prevents concurrent updates from using the same old set.
Also at `listener/templates.go:152`.
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist
Summary by Sourcery
Always synchronize template advisories from advisory_ids in Content Sources Kafka events and remove the legacy HTTP lookup path.
New Features:
Bug Fixes:
Enhancements:
Deployment:
Documentation:
Tests:
Chores: