Skip to content

RHINENG-33526: always sync template advisories from kafka advisory_ids - #2381

Open
MichaelMraka wants to merge 4 commits into
RedHatInsights:masterfrom
MichaelMraka:pr3
Open

MichaelMraka wants to merge 4 commits into
RedHatInsights:masterfrom
MichaelMraka:pr3

Conversation

@MichaelMraka

@MichaelMraka MichaelMraka commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Secure Coding Practices Checklist GitHub Link

Secure Coding Checklist

  • Input Validation
  • Output Encoding
  • Authentication and Password Management
  • Session Management
  • Access Control
  • Cryptographic Practices
  • Error Handling and Logging
  • Data Protection
  • Communication Security
  • System Configuration
  • Database Security
  • File Management
  • Memory Management
  • General Coding Practices

Summary by Sourcery

Always synchronize template advisories from advisory_ids in Content Sources Kafka events and remove the legacy HTTP lookup path.

New Features:

  • Always synchronize template advisory associations from advisory_ids included in template-created and template-updated Kafka events.

Bug Fixes:

  • Ensure advisory snapshots are applied consistently on both template creation and update, including removing associations when advisory_ids is absent or empty.

Enhancements:

  • Remove the Content Sources HTTP advisory lookup path and its related configuration, client code, and deployment dependency.

Deployment:

  • Remove the optional Content Sources backend dependency and obsolete Content Sources environment settings from the deployment configuration.

Documentation:

  • Update architecture and database documentation to describe Kafka-based template advisory synchronization.

Tests:

  • Update end-to-end and integration coverage for advisory synchronization from Kafka event data.

Chores:

  • Remove unused Content Sources integration and identity helper code.

@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Apply template advisory snapshots from Kafka event advisory_ids on both template creation and update, including empty snapshots, while preserving diff and re-evaluation behavior.

  • listener/templates.go L4 (removed lines), L17 (removed lines), L152-154
  • listener/template_advisories.go L4-239 (5 small edits)

Remove the Content Sources advisory HTTP client and its platform mock now that template advisory synchronization no longer calls them.

  • base/content_sources/content_sources.go (deleted)
  • platform/content_sources.go (deleted)
  • platform/platform.go L188 (removed lines)

Remove identity encoding and template-identity helpers that were used only to authenticate Content Sources API requests.

  • base/utils/identity.go L26 (removed lines)

Remove listener state and setup for the Content Sources client and the templates_with_advisories mode switch.

  • listener/listener.go L5-82 (6 small edits)

Configuration

Remove obsolete Content Sources address and user settings, listener environment values, and the optional deployment dependency.

  • base/utils/config.go L85-442 (4 small edits)
  • conf/common.env L29 (removed lines)
  • conf/listener.env L6 (removed lines)
  • conf/local.env L18 (removed lines)
  • deploy/clowdapp.yaml L201 (removed lines), L1068 (removed lines), L1269 (removed lines)

Documentation

Revise architecture and database guidance to state that advisory associations are sourced from Kafka event snapshots, with missing or empty IDs clearing associations.

  • docs/md/architecture.md L23-25, L86-91
  • docs/md/database.md L17-18

Tests

Update tests to cover Kafka-provided advisory snapshots and remove tests that exercised the retired Content Sources HTTP path.

  • evaluator/template_advisory_e2e_test.go L84
  • listener/template_advisories_test.go L5-241 (8 small edits)
  • listener/testutil.go L4 (removed lines), L12 (removed lines)

Delete unit tests and imports dedicated to the removed identity encoding and helper functions.

  • base/utils/identity_test.go L6 (removed lines), L25 (removed lines)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov-commenter

codecov-commenter commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.76%. Comparing base (632ad02) to head (945120a).

Files with missing lines Patch % Lines
listener/templates.go 66.66% 1 Missing ⚠️
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              
Flag Coverage Δ
unittests 66.76% <66.66%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
@MichaelMraka
MichaelMraka marked this pull request as ready for review November 24, 2026 12:45
@MichaelMraka
MichaelMraka requested a review from a team as a code owner November 24, 2026 12:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread listener/templates.go
if err != nil {
return errors.Wrap(err, "syncing template advisories")
}
err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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`.

Comment thread listener/templates.go
if err != nil {
return errors.Wrap(err, "syncing template advisories")
}
err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

Comment thread listener/templates.go
if err != nil {
return errors.Wrap(err, "syncing template advisories")
}
err = applyTemplateAdvisories(ctx, accountID, row.ID, template.UUID, template.OrgID, template.AdvisoryIDs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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`.

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.

2 participants