Skip to content

RHINENG-26348: add skip notifications for platform events - #2286

Open
TenSt wants to merge 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/RHINENG-26348-add-skip-notifications-on-recalc
Open

RHINENG-26348: add skip notifications for platform events#2286
TenSt wants to merge 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/RHINENG-26348-add-skip-notifications-on-recalc

Conversation

@TenSt

@TenSt TenSt commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

This PR:

  • add skip_notifications on PlatformEvent for recovery recalc
  • skip Kafka notify publish when set; still mark advisory_account_data.notified
  • add unit tests for JSON round-trip and skip-publish behavior

Summary by Sourcery

Add support for per-event skipping of instant advisory notifications while still marking advisories as notified.

New Features:

  • Introduce a SkipNotifications flag on PlatformEvent to control advisory notification publishing behavior per event.

Enhancements:

  • Refactor advisory notification publishing to share logic for marking advisories as notified and to support a skip-publish mode used for recovery recalculation workflows.

Tests:

  • Add evaluator tests to verify skip_notifications events store advisories, mark them notified, and avoid Kafka notification publishing.
  • Add platform event JSON serialization tests to ensure skip_notifications is omitted when false and round-trips correctly when true.

@TenSt
TenSt requested a review from a team as a code owner July 30, 2026 11:38
@sourcery-ai

sourcery-ai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a skip_notifications flag to PlatformEvent and evaluator advisory notification flow, allowing advisory_account_data.notified to be marked without publishing Kafka notifications, and introduces tests covering JSON round-trip and skip-publish behavior.

File-Level Changes

Change Details Files
Introduce skip_notifications on PlatformEvent and wire it into evaluator advisory notification logic so events can opt out of Kafka publishing while still marking advisories as notified.
  • Add SkipNotifications boolean field with json:"skip_notifications,omitempty" to PlatformEvent and document its semantics
  • Update evaluateAndStore to call publishNewAdvisoriesNotification whenever instant notifications are enabled or SkipNotifications is set, passing SkipNotifications through as a skipPublish flag
  • Add tests validating PlatformEvent SkipNotifications JSON behavior (true serialized, false omitted, default false on unmarshal) and full evaluateHandler path with SkipNotifications set to ensure advisories are stored, marked notified, and Kafka publishing is skipped
base/mqueue/platform_event.go
base/mqueue/platform_event_test.go
evaluator/evaluate.go
evaluator/notifications_test.go
Refactor advisory notification publishing to support a skip-publish mode that only marks advisories as notified without sending Kafka messages.
  • Extract advisory_account_data.notified update into a reusable markAdvisoriesNotified helper with proper error wrapping
  • Extend publishNewAdvisoriesNotification with a skipPublish boolean parameter and early-return path that logs and calls markAdvisoriesNotified when publishing is skipped
  • Retain existing behavior when skipPublish is false, but reuse markAdvisoriesNotified instead of duplicating the update code
  • Update existing tests to pass the new skipPublish parameter and add a dedicated test to verify skipPublish=true marks advisories as notified while producing no Kafka messages
evaluator/notifications.go
evaluator/notifications_test.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

@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, and left some high level feedback:

  • In publishNewAdvisoriesNotification, when notificationsPublisher is nil you now return before calling markAdvisoriesNotified, which means advisories remain unmarked and can still flood later; consider either calling markAdvisoriesNotified in this branch or restoring the early nil check before doing the DB work so behavior is explicit.
  • Since markAdvisoriesNotified encapsulates the advisory_account_data update, consider reusing it in any other paths that directly manipulate notified to keep the update logic centralized and consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `publishNewAdvisoriesNotification`, when `notificationsPublisher` is nil you now return before calling `markAdvisoriesNotified`, which means advisories remain unmarked and can still flood later; consider either calling `markAdvisoriesNotified` in this branch or restoring the early nil check before doing the DB work so behavior is explicit.
- Since `markAdvisoriesNotified` encapsulates the `advisory_account_data` update, consider reusing it in any other paths that directly manipulate `notified` to keep the update logic centralized and consistent.

## Individual Comments

### Comment 1
<location path="base/mqueue/platform_event_test.go" line_range="27-34" />
<code_context>
+	assert.True(t, parsed.SkipNotifications)
+
+	// omitempty: false must not appear in JSON; fresh unmarshal defaults to false
+	event.SkipNotifications = false
+	data, err = sonic.Marshal(event)
+	assert.NoError(t, err)
+	assert.NotContains(t, string(data), "skip_notifications")
+
+	var parsedFalse PlatformEvent
+	assert.NoError(t, sonic.Unmarshal(data, &parsedFalse))
+	assert.False(t, parsedFalse.SkipNotifications)
+}
+
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid brittle string-based assertion for omitting skip_notifications in JSON

The test currently checks `omitempty` by searching the marshaled JSON string for `"skip_notifications"`, which is fragile if formatting or encoding changes. Instead, unmarshal into a `map[string]any` and assert the key is absent:

```go
var m map[string]any
assert.NoError(t, sonic.Unmarshal(data, &m))
assert.NotContains(t, m, "skip_notifications")
```
This validates the JSON structure rather than relying on string content.

Suggested implementation:

```golang
	// omitempty: false must not appear in JSON; fresh unmarshal defaults to false
+
+	event.SkipNotifications = false
+	data, err = sonic.Marshal(event)
+	assert.NoError(t, err)
+
+	var m map[string]any
+	assert.NoError(t, sonic.Unmarshal(data, &m))
+	assert.NotContains(t, m, "skip_notifications")
+
+	var parsedFalse PlatformEvent
+	assert.NoError(t, sonic.Unmarshal(data, &parsedFalse))
+	assert.False(t, parsedFalse.SkipNotifications)

```

If this test function currently ends immediately after the snippet you provided, no further changes are required. If there are other assertions that depend on the raw JSON string, consider converting them similarly to structure-based checks (using maps or strongly typed structs) to keep tests robust against formatting/serialization changes.
</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 thread base/mqueue/platform_event_test.go
@codecov-commenter

codecov-commenter commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.29%. Comparing base (7ae4e4b) to head (19394a1).

Files with missing lines Patch % Lines
evaluator/notifications.go 73.68% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2286      +/-   ##
==========================================
+ Coverage   59.27%   59.29%   +0.01%     
==========================================
  Files         148      148              
  Lines        9488     9497       +9     
==========================================
+ Hits         5624     5631       +7     
- Misses       3276     3277       +1     
- Partials      588      589       +1     
Flag Coverage Δ
unittests 59.29% <77.27%> (+0.01%) ⬆️

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 force-pushed the stepan/RHINENG-26348-add-skip-notifications-on-recalc branch from af8c0bf to 19394a1 Compare July 30, 2026 17:25
@MichaelMraka MichaelMraka self-assigned this Jul 31, 2026
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