Skip to content

HMS-10723: add endpoint to return template advisory IDs#1536

Open
xbhouse wants to merge 1 commit into
content-services:mainfrom
xbhouse:10723
Open

HMS-10723: add endpoint to return template advisory IDs#1536
xbhouse wants to merge 1 commit into
content-services:mainfrom
xbhouse:10723

Conversation

@xbhouse

@xbhouse xbhouse commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an endpoint that returns a template's advisory IDs
  • Sends template update events whenever a template is updated

Testing steps

  1. Create a template with snapshots that have advisories.
  2. Send a GET request to /templates/:uuid/advisories/ids. This should return all the advisory IDs in the template.
  3. Run make kafka-topic-consume KAFKA_TOPIC=platform.content-sources.template
  4. Update the template. There should be 2 messages in the consumer output, one when the update request is sent and one during the update-template-content task.
  5. Add a custom repo to a template that's using the latest snapshots. Triggering a new snapshot for that repo should enqueue the update-latest-snapshot task, and a message should be sent in the consumer output during that task.
  6. Change the template to a date before the latest custom repo snapshot. Delete the custom repo snapshot used by the template, this should enqueue a delete-snapshots task and a message should be sent in the consumer output.
  7. Delete the custom repository used by the template. This should enqueue a delete-repository-snapshots task and a message should be sent during this task too.

@xbhouse xbhouse force-pushed the 10723 branch 2 times, most recently from c20e13b to 2129e33 Compare June 10, 2026 18:41
@xbhouse

xbhouse commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@xbhouse xbhouse force-pushed the 10723 branch 6 times, most recently from 53e9dce to ef2b48a Compare June 11, 2026 21:19
@xbhouse xbhouse marked this pull request as ready for review June 11, 2026 21:46
@xbhouse xbhouse requested a review from a team as a code owner June 11, 2026 21:46
Comment thread pkg/dao/rpms.go
@TenSt TenSt self-assigned this Jun 12, 2026
Comment thread pkg/tasks/template_event_helper.go Outdated
TenSt
TenSt previously approved these changes Jun 12, 2026

@TenSt TenSt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!
There are a couple comments, but feel free to merge as is or I'll re-approve if you decide to do the changes.

Comment thread pkg/dao/templates.go
respTemplate.RepositoryUUIDS = reqTemplate.RepositoryUUIDS

event.SendTemplateEvent(*reqTemplate.OrgID, event.TemplateCreated, []event.TemplateEvent{event.MapTemplateResponse(respTemplate, nil, nil)})

@rverdile rverdile Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm concerned about removing these events from here because they keep the patch database in sync with our database. If we move them only to the task (which can take some time to start, or fail), I think we might start seeing situations where the databases get out of sync.

What if we left these here, and changed the task to just send TemplateUpdate events for the advisories?

What do you guys think? @xbhouse @TenSt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm good point :) keeping the create here makes sense so template data gets sent asap instead of waiting on the task. and i can change the event name for events emitted from the task for new templates to TemplateUpdated

i removed the update event from the dao too, would it make sense to restore that as well for consistency?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, let's restore both

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm okay with both approaches. We're usually going for the "eventual consistency", so some delay is okay. Depends on the delay. But if we can keep updating right away without loosing any performance or spending too much resources then let's do it.

PoolID *string // Add during task runtime
TemplateUUID string
RepoConfigUUIDs []string
PreviousSnapshotUUIDs []string

@rverdile rverdile Jun 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should previousSnapshotUUIDs be found at runtime within the task? If the tasks fail or run in a different order than expected, I think this might cause some incorrect errata diffs. Thoughts?

@xbhouse xbhouse Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i see what you mean. if 2 update tasks are running for the same template, and one finishes first or fails halfway through, the other would have the wrong prev snapshot uuids.

in cases of out of order tasks or retries, wouldn't checking the prev snapshots inside the task also result in wrong errata diffs? i'll try to test these scenarios with prev snapshots in the payload vs the task to understand more clearly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm so the task takes the repositories that should be in the template in the payload, and when the task is complete the template is in that state. So I think the diff would be okay? But maybe there's still a race condition in there somewhere

Not sure what other options would be except to do this in the handler, and not use a task (maybe too slow?). Or send the whole list to patch and let patch calculate the changes against the system (maybe too many events?).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we run the tasks sequentially for the same template? This will create some delay, but will solve these issues. As we're having here async tasks, some delay is inevitable and we can use it to make sure consistency of the data.

@xbhouse xbhouse Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the previous snapshots are sent in the payload because these are updated in the db via insertTemplateRepoConfigsAndSnapshots and lost before the task starts. but you're right that this could produce wrong diffs when tasks finish out of order :/ i don't see a way to retrieve or recompute this previous state in the task without storing it somewhere else first, i might have overlooked something though.

doing this in the handler would be slower and maybe too optimistic, meaning we send a diff to patch even if a step afterward fails. sending everything to patch would mean more events, and maybe too many, but it might make sense to have the diff logic where the template-advisory relationships are stored.

if storing the previous snapshots for a template somewhere makes sense or if there's another way to fetch the previous snapshot in the task, i can switch to that. or if we can ensure tasks are run sequentially (maybe this can be done with task dependencies?), that's another option :) otherwise, sending the full set to patch seems like a reasonable approach, but that would be a big design shift so we should talk through it with the team.

@xbhouse xbhouse Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

discussed a different approach in slack, we're going to add an endpoint patch can use to fetch the current advisories in a template. in patch, whenever there's an event that a template has been updated, we'll query this endpoint and calculate the diff. moving this back to draft while i update this :)

thank you both for your input @rverdile @TenSt!

@xbhouse xbhouse force-pushed the 10723 branch 2 times, most recently from 6a0e43f to b5cc428 Compare June 12, 2026 17:26
@xbhouse xbhouse marked this pull request as draft June 15, 2026 19:38
@xbhouse xbhouse force-pushed the 10723 branch 2 times, most recently from e8d6e23 to 6331274 Compare June 15, 2026 22:01
@xbhouse xbhouse changed the title HMS-10723: add errata to template message HMS-10723: add endpoint to return template advisory IDs Jun 15, 2026
@xbhouse xbhouse marked this pull request as ready for review June 15, 2026 22:44
TenSt
TenSt previously approved these changes Jun 16, 2026

@TenSt TenSt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm! great work 👍

@rverdile rverdile left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

delete-snapshots and delete-repository-snapshots also modify templates, so those need to send an update event too

@xbhouse

xbhouse commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

delete-snapshots and delete-repository-snapshots also modify templates, so those need to send an update event too

thank you! was about to ask which other 2 tasks needed to send an event :) will add that in

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