Skip to content
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

Fixes #35503 - Notify user only when new errata are added to repo #10328

Merged
merged 1 commit into from Nov 1, 2022

Conversation

wbclark
Copy link
Contributor

@wbclark wbclark commented Oct 27, 2022

Co-authored-by: William Bradford Clark wclark@redhat.com
Co-authored-by: Pavel Moravec pmoravec@redhat.com

What are the changes introduced in this pull request?

Instead of using contents_changed for input (and corresponding middleware) we use new inputs associated_errata_before_syncing and new_associated_errata; in planning, we set the former to the current list of associated errata and initialize the latter as an empty array. Later in the run step (after the repository has synced) we re-calculate the associated errata and set new_associated_errata as the difference -- only sending the notification email when this is non-empty.

Considerations taken when implementing this change?

To avoid keeping potentially large arrays in the database (and to create better UX viewing the action in the dynflow console), after we are done using the new inputs to determine what (if any) emails to send, we truncate them and replace with a message displaying the count of errata rather than the complete list of IDs. More than 3 errata was chosen (somewhat arbitrarily) as a cutoff point, because the full information will be available in the email itself. This prevents us from seeing very large inputs for the action when viewing the action in dynflow console after the action has run.

What are the testing steps for this pull request?

  1. Install sendmail/postfix on development environment
  2. systemctl enable --now postfix
  3. Configure email address and notification subscriptions for user
  4. Enable and sync a repository containing errata
  5. After sync is complete, observe task in dynflow console and validate that we have associated_errata_before_syncing: [] and some number of new_associated_errata
  6. Read mail in /var/spool/mail/$user
  7. Immediately re-sync the repository
  8. This time the inputs are reversed -- we observe some number of existing associated_errata_before_syncing but new_associated_errata is []
  9. There is no additional mail in /var/spool/mail/$user

@theforeman-bot
Copy link

Issues: #35503

@pmoravec
Copy link
Member

Credits / co-author should rather go to @hao-yu than me :)

last_updated = repo.repository_errata.order('updated_at ASC').last.try(:updated_at) || Time.now
plan_self(:repo => repo.id, :contents_changed => contents_changed, :last_updated => last_updated.to_s)
def plan(repo)
plan_self(:repo => repo.id, :associated_errata_before_syncing => repo.repository_errata.pluck(:erratum_id).uniq.sort.reverse, :new_associated_errata => [])
Copy link
Member

@pmoravec pmoravec Oct 27, 2022

Choose a reason for hiding this comment

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

Why the .reverse (dtto for run)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I previously tried a format where the truncated input remains an Array containing the first few IDs, appended with the truncation message. The reversed order made sense because the ordering of the erratum ids corresponds to the order which the erratum records were created, so with a partially truncated output it means we see the most recently created (which in most cases would be the most recently associated) at the top, which provides a "good intuition" for the cutoff between new vs. prior associated errata.

I then leaned towards just replacing the entire Array with a string containing the count, if the length is greater than some number, reasoning that it's simpler for the user to read (the data types were mixed within the Array in the previous way, so the user would see several integers followed by an ugly double-quoted string) and maybe easier to maintain.

But I chose the Array length for truncation to kick in very arbitrarily as 3, and I'm not sure if there is some better value. In particular if we allow the user to see a larger Array then I think the reverse ordering feels more intuitive. Since Array reversal should be cheap (linear complexity) I just left it in.

What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, then it makes sense to me.

@wbclark
Copy link
Contributor Author

wbclark commented Oct 27, 2022

Credits / co-author should rather go to @hao-yu than me :)

I didn't list @hao-yu as co-author because he is the primary author (of the commit itself). If that is confusing or contrary to convention I could add his information in both places (first time using this GH feature, but it seems very useful)

Co-authored-by: William Bradford Clark <wclark@redhat.com>
Co-authored-by: Pavel Moravec <pmoravec@redhat.com>
@wbclark wbclark force-pushed the 35503_new_repository_errata_only branch from 7646f59 to 0a4405a Compare October 27, 2022 10:37
@pmoravec
Copy link
Member

Credits / co-author should rather go to @hao-yu than me :)

I didn't list @hao-yu as co-author because he is the primary author (of the commit itself). If that is confusing or contrary to convention I could add his information in both places (first time using this GH feature, but it seems very useful)

Ah ok then. I am ok with that credits then. I just simply didnt want to get more credit than Hao :)

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

Worked fine for me! I couldn't get Foreman to connect to postfix for some reason, but the emails in the logs show the correct thing. Only the added errata are shown in the email.

I like the way the dynflow input is setup, makes for easy debugging!

@ianballou ianballou merged commit e626c4c into Katello:master Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants