Skip to content

fix: missing Kafka message deserialization in aggregator#2275

Merged
katarinazaprazna merged 1 commit into
RedHatInsights:masterfrom
katarinazaprazna:fix-aggregator-event-deserialization
Jul 22, 2026
Merged

fix: missing Kafka message deserialization in aggregator#2275
katarinazaprazna merged 1 commit into
RedHatInsights:masterfrom
katarinazaprazna:fix-aggregator-event-deserialization

Conversation

@katarinazaprazna

@katarinazaprazna katarinazaprazna commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Add MakeAdvisoryUpdateHandler to deserialize raw Kafka messages into AdvisoryUpdateEvent objects, mirroring the existing MakeMessageHandler pattern.

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

Add a dedicated advisory update event handler that deserializes Kafka messages before processing and wire it into the aggregator subscription flow.

New Features:

  • Introduce MakeAdvisoryUpdateHandler to convert raw Kafka messages into AdvisoryUpdateEvent objects for downstream handlers.

Bug Fixes:

  • Ensure advisory update Kafka messages are properly deserialized before being handled in the aggregator.

Enhancements:

  • Refine advisory update handling API so aggregator logic operates on typed AdvisoryUpdateEvent instances instead of raw Kafka messages.

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR introduces a typed handler and factory for advisory update Kafka messages, ensuring they are deserialized into AdvisoryUpdateEvent objects before being processed in the aggregator, and updates the advisory subscription pipeline to use the new handler signature.

File-Level Changes

Change Details Files
Introduce a typed AdvisoryUpdateEvent handler and factory that deserialize Kafka messages before invoking business logic.
  • Add AdvisoryUpdateEventHandler function type that operates on AdvisoryUpdateEvent objects instead of raw Kafka messages.
  • Implement MakeAdvisoryUpdateHandler to wrap a MessageHandler, deserialize Kafka message values with sonic.Unmarshal, log deserialization errors via utils.LogError, and forward successfully parsed events to the underlying handler.
base/mqueue/advisory_update_event.go
Wire the new AdvisoryUpdateEvent handler into the aggregator advisory updates subscription pipeline and adjust the handler signature.
  • Update subscribeToAdvisoryUpdates to wrap advisoryUpdateHandler with MakeAdvisoryUpdateHandler inside MakeRetryingHandler so advisory messages are deserialized before retry logic.
  • Change advisoryUpdateHandler to accept an AdvisoryUpdateEvent instead of a KafkaMessage, preparing it for typed event processing.
aggregator/aggregator.go
aggregator/events.go

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

@katarinazaprazna
katarinazaprazna marked this pull request as ready for review July 21, 2026 23:09
@katarinazaprazna
katarinazaprazna requested a review from a team as a code owner July 21, 2026 23:09

@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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="base/mqueue/advisory_update_event.go" line_range="18-19" />
<code_context>
+func MakeAdvisoryUpdateHandler(handler AdvisoryUpdateEventHandler) MessageHandler {
+	return func(m KafkaMessage) error {
+		var event AdvisoryUpdateEvent
+		err := sonic.Unmarshal(m.Value, &event)
+		if err != nil {
+			utils.LogError("err", err, "Could not deserialize advisory update event")
+			return nil
</code_context>
<issue_to_address>
**issue (bug_risk):** Swallowing deserialization errors may hide malformed messages and mark them as successfully processed.

Because nil is returned on deserialization failure, the retrying handler will treat the message as successfully processed and never retry or reroute it. If malformed messages should be retried or sent to a dead-letter topic, return an error here (ideally a wrapped, typed error that the retry logic or higher-level handler can interpret) instead of nil.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +18 to +19
err := sonic.Unmarshal(m.Value, &event)
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Swallowing deserialization errors may hide malformed messages and mark them as successfully processed.

Because nil is returned on deserialization failure, the retrying handler will treat the message as successfully processed and never retry or reroute it. If malformed messages should be retried or sent to a dead-letter topic, return an error here (ideally a wrapped, typed error that the retry logic or higher-level handler can interpret) instead of nil.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.92%. Comparing base (9c9c35f) to head (0dc6840).

Files with missing lines Patch % Lines
base/mqueue/advisory_update_event.go 0.00% 8 Missing ⚠️
aggregator/aggregator.go 0.00% 1 Missing ⚠️
aggregator/events.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2275      +/-   ##
==========================================
- Coverage   58.97%   58.92%   -0.06%     
==========================================
  Files         147      147              
  Lines        9293     9301       +8     
==========================================
  Hits         5481     5481              
- Misses       3238     3246       +8     
  Partials      574      574              
Flag Coverage Δ
unittests 58.92% <0.00%> (-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.

@TenSt TenSt self-assigned this Jul 22, 2026
@katarinazaprazna
katarinazaprazna merged commit 6cd1450 into RedHatInsights:master Jul 22, 2026
8 checks passed
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.

3 participants