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

Fix group level and names for miq event #21569

Merged

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Nov 19, 2021

I was noticing that ManageIQ/manageiq-api#1099 OPTIONS for event_streams was missing "other" and "detail" after #21552 was merged.

Part of ManageIQ/manageiq-api#1090

I realized this is because we had defaults for "other" and "detail" buried in code and didn't have defaults in the base class with overrides in the subclasses. This PR fixes some of this.

Here's an example of the JSON diff for OPTIONS on event_streams before and after this PR:

joerafaniello@Joes-MBP-2 manageiq % diff -u before.txt after.txt
--- before.txt	2021-11-19 15:17:47.000000000 -0500
+++ after.txt	2021-11-19 15:10:50.000000000 -0500
@@ -86,6 +86,7 @@
             "EmsEvent": {
                 "description": "Management Events",
                 "group_names": {
+                    "other": "Other",
                     "addition": "Creation/Addition",
                     "configuration": "Configuration/Reconfiguration",
                     "console": "Console Activity",
@@ -113,6 +114,7 @@
             "MiqEvent": {
                 "description": "Policy Events",
                 "group_names": {
+                    "other": "Other",
                     "ems_operations": "Provider Operation",
                     "host_operations": "Host Operation",
                     "compliance": "Compliance",
@@ -132,7 +134,8 @@
                 },
                 "group_levels": {
                     "success": "Success",
-                    "failure": "Failure"
+                    "failure": "Failure",
+                    "detail": "Detail"
                 }
             }
         }

@@ -35,13 +35,21 @@ class EventStream < ApplicationRecord

after_commit :emit_notifications, :on => :create

# TODO: Consider moving since this is EmsEvent specific. group, group_level and group_name exposed as a virtual columns for reports/api.
GROUP_LEVELS = %i(critical detail warning).freeze
Copy link
Member Author

Choose a reason for hiding this comment

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

☝️ This was mixing EmsEvent group levels with EventStream. Critical and warning were moved to EmsEvent, detail remains as a default here.

Push down the constants into the correct classes.  We had lots of EmsEvent data
hardcoded in the EventStream and that needs to be split apart.
@jrafanie jrafanie force-pushed the fix_group_level_and_names_for_miq_event branch from a0f93e2 to c62c27d Compare November 19, 2021 21:00
@miq-bot
Copy link
Member

miq-bot commented Nov 19, 2021

Checked commits jrafanie/manageiq@660aeda~...c62c27d with ruby 2.6.3, rubocop 1.13.0, haml-lint 0.35.0, and yamllint
4 files checked, 0 offenses detected
Everything looks fine. 🍪

return group, level
end

def self.group_name(group)
return if group.nil?
group = event_groups[group.to_sym]
group.nil? ? 'Other' : group[:name]
group.nil? ? DEFAULT_GROUP_NAME.to_s.capitalize : group[:name]
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this will break I18N - we may have to figure that out in a follow up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I don't know how to test it. I can ask around and do it in a followup.

hash = default_group_names_and_levels
hash[:group_names].merge!(MiqEventDefinitionSet.all.pluck(:name, :description).to_h.symbolize_keys)
group_levels.each do |level|
hash[:group_levels][level] ||= level.to_s.capitalize
Copy link
Member

Choose a reason for hiding this comment

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

Similar here - this may cause i18n issues unless the target string is already in the .po.

@Fryguy
Copy link
Member

Fryguy commented Nov 19, 2021

LGTM - my concerns are mostly around i18n but I'm not certain that was working prior to this, so don't want to hold it up...we can fix i18n afterwards.

@@ -10,14 +10,18 @@ class EmsEvent < EventStream
'Rename_Task',
]

CLASS_GROUP_LEVELS = %i[critical warning].freeze
Copy link
Member

Choose a reason for hiding this comment

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

For i18n, I think the better way to do this might be to make this:

Suggested change
CLASS_GROUP_LEVELS = %i[critical warning].freeze
CLASS_GROUP_LEVELS = [
N_("Critical"),
N_("Warning")
].freeze

Then later, or perhaps in another constant, do CLASS_GROUP_LEVELS.map { |l| l.downcase.to_sym }

This way, the strings are in the translation catalog, but the code can still use symbols.

Comment on lines +38 to +39
DEFAULT_GROUP_NAME = :other
DEFAULT_GROUP_LEVEL = :detail
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, for i18n here, you'd do something like:

Suggested change
DEFAULT_GROUP_NAME = :other
DEFAULT_GROUP_LEVEL = :detail
DEFAULT_GROUP_NAME = N_("Other")
DEFAULT_GROUP_LEVEL = N_("Detail")

Then later or perhaps in another constant you'd do DEFAULT_GROUP_NAME.downcase.to_sym

@Fryguy Fryguy merged commit f7a98cb into ManageIQ:master Nov 22, 2021
@Fryguy
Copy link
Member

Fryguy commented Nov 22, 2021

Merging without the i18n stuff - we can fix that in a follow up

@agrare
Copy link
Member

agrare commented Nov 22, 2021

Looks like ui-classic is failing on missing EmsEvent::GROUP_LEVELS

Really weird that it doesn't show up in org code search: https://github.com/search?q=org%3AManageIQ+EmsEvent%3A%3AGROUP_LEVELS&type=code
But it is there: https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/controllers/application_controller/timelines/options.rb#L83-L85

jrafanie added a commit to jrafanie/manageiq-ui-classic that referenced this pull request Nov 22, 2021
Broken by ManageIQ/manageiq#21569

The constant was defined in the base class, but was actually an EmsEvent concern
so this was moved to a method for subclasses to override.
@jrafanie
Copy link
Member Author

Opened ManageIQ/manageiq-ui-classic#7972 to fix the "oops, didn't cross repo test with ui-classic"

@jrafanie jrafanie deleted the fix_group_level_and_names_for_miq_event branch November 22, 2021 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants