-
Notifications
You must be signed in to change notification settings - Fork 44
RHINENG-26118: add patchman.advisory.update Kafka topic
#2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TenSt
merged 4 commits into
RedHatInsights:master
from
katarinazaprazna:add-advisory-update-topic
May 18, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f4aaa5c
feat: add `patchman.advisory.update` Kafka topic config
katarinazaprazna 781567c
chore: remove legacy kafkaTopics definition from ClowdApp
katarinazaprazna c62a807
feat: add AdvisoryUpdateEvent with tests
katarinazaprazna 3f89fa1
Merge branch 'master' into add-advisory-update-topic
katarinazaprazna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package mqueue | ||
|
|
||
| import ( | ||
| "app/base/types" | ||
| "context" | ||
|
|
||
| "github.com/bytedance/sonic" | ||
| "github.com/google/uuid" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| type AdvisoryUpdateEvent struct { | ||
| RhAccountID int `json:"rh_account_id"` | ||
| WorkspaceID uuid.UUID `json:"workspace_id"` | ||
| InventoryID uuid.UUID `json:"inventory_id"` | ||
| AdvisoryIDs []int64 `json:"advisory_ids"` | ||
| ProducedAt types.Rfc3339Timestamp `json:"produced_at"` | ||
| } | ||
|
|
||
| type AdvisoryUpdateEvents []AdvisoryUpdateEvent | ||
|
|
||
| func (event *AdvisoryUpdateEvent) createKafkaMessage() (KafkaMessage, error) { | ||
| data, err := sonic.Marshal(event) | ||
| if err != nil { | ||
| return KafkaMessage{}, errors.Wrap(err, "Serializing advisory update event") | ||
| } | ||
| return KafkaMessage{Value: data}, nil | ||
| } | ||
|
|
||
| func (events AdvisoryUpdateEvents) WriteEvents(ctx context.Context, w Writer) error { | ||
| msgs := make([]KafkaMessage, 0, len(events)) | ||
| for i := range events { | ||
| msg, err := events[i].createKafkaMessage() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| msgs = append(msgs, msg) | ||
| } | ||
| return w.WriteMessages(ctx, msgs...) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package mqueue | ||
|
|
||
| import ( | ||
| "app/base/types" | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/bytedance/sonic" | ||
| "github.com/google/uuid" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var ( | ||
| testWorkspaceID = uuid.New() | ||
| testNow = types.Rfc3339Timestamp(time.Now()) | ||
| ) | ||
|
|
||
| func TestAdvisoryUpdateEventMarshal(t *testing.T) { | ||
| event := AdvisoryUpdateEvent{ | ||
| RhAccountID: 1, | ||
| WorkspaceID: testWorkspaceID, | ||
| InventoryID: uuid.New(), | ||
| AdvisoryIDs: []int64{101, 202, 303}, | ||
| ProducedAt: testNow, | ||
| } | ||
|
|
||
| data, err := sonic.Marshal(&event) | ||
| assert.NoError(t, err) | ||
|
|
||
| var parsed AdvisoryUpdateEvent | ||
| err = sonic.Unmarshal(data, &parsed) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, event.RhAccountID, parsed.RhAccountID) | ||
| assert.Equal(t, event.WorkspaceID, parsed.WorkspaceID) | ||
| assert.Equal(t, event.InventoryID, parsed.InventoryID) | ||
| assert.Equal(t, event.AdvisoryIDs, parsed.AdvisoryIDs) | ||
| assert.NotNil(t, parsed.ProducedAt) | ||
| } | ||
|
|
||
| func TestAdvisoryUpdateEventsWriteEvents(t *testing.T) { | ||
| var writer Writer = &MockKafkaWriter{} | ||
|
|
||
| events := AdvisoryUpdateEvents{ | ||
| { | ||
| RhAccountID: 1, | ||
| WorkspaceID: testWorkspaceID, | ||
| InventoryID: uuid.New(), | ||
| AdvisoryIDs: []int64{100, 200}, | ||
| ProducedAt: testNow, | ||
| }, | ||
| { | ||
| RhAccountID: 2, | ||
| WorkspaceID: testWorkspaceID, | ||
| InventoryID: uuid.New(), | ||
| AdvisoryIDs: []int64{300}, | ||
| ProducedAt: testNow, | ||
| }, | ||
| } | ||
|
|
||
| err := SendMessages(context.Background(), writer, &events) | ||
| assert.NoError(t, err) | ||
|
|
||
| mockWriter := writer.(*MockKafkaWriter) | ||
| assert.Equal(t, 2, len(mockWriter.Messages)) | ||
|
|
||
| var firstEvent AdvisoryUpdateEvent | ||
| err = sonic.Unmarshal(mockWriter.Messages[0].Value, &firstEvent) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, events[0].RhAccountID, firstEvent.RhAccountID) | ||
| assert.Equal(t, events[0].WorkspaceID, firstEvent.WorkspaceID) | ||
| assert.Equal(t, events[0].InventoryID, firstEvent.InventoryID) | ||
| assert.Equal(t, events[0].AdvisoryIDs, firstEvent.AdvisoryIDs) | ||
| assert.NotNil(t, firstEvent.ProducedAt) | ||
|
|
||
| var secondEvent AdvisoryUpdateEvent | ||
| err = sonic.Unmarshal(mockWriter.Messages[1].Value, &secondEvent) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, events[1].RhAccountID, secondEvent.RhAccountID) | ||
| assert.Equal(t, events[1].WorkspaceID, secondEvent.WorkspaceID) | ||
| assert.Equal(t, events[1].InventoryID, secondEvent.InventoryID) | ||
| assert.Equal(t, events[1].AdvisoryIDs, secondEvent.AdvisoryIDs) | ||
| assert.NotNil(t, secondEvent.ProducedAt) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.