-
Notifications
You must be signed in to change notification settings - Fork 897
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
Pass metadata from an EmsEvent to an alert #14136
Conversation
@@ -193,16 +193,22 @@ def evaluate(target, inputs = {}) | |||
# If we are alerting, invoke the alert actions, then add a status so we can limit how often to alert | |||
# Otherwise, destroy this alert's statuses for our target | |||
invoke_actions(target, inputs) if result | |||
add_status_post_evaluate(target, result, inputs[:description]) | |||
|
|||
add_status_post_evaluate(target, result, inputs[:ems_event]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the inputs[:description]
is a bug I recently introduced in #13653
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this change into a different commit so info is retained on the change?
app/models/miq_alert.rb
Outdated
event.try(:message), | ||
event.try(:full_data).try(:[], :severity), | ||
event.try(:full_data).try(:[], :url), | ||
] | ||
status = miq_alert_statuses.find_or_initialize_by(:resource => target) | ||
status.result = result | ||
status.ems_id = target.try(:ems_id) | ||
status.description = status_description || description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this might interfere with existing alerts (change their message undesirably)
I can
- only set it for events of a specific kind (
datawarehouse_event
) - use some easly distinguishable metadata that won't be there by mistake, e.g
event.try(:full_data).try(:[], :miq_alert_message)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like only using it on datawarehouse_event
. It generates an inconsistency, but it will help prepare migrating the change for other events if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer something like
event.try(:full_data).try(:[], :alert_status_description)
Due to the inconsistency you mentioned. @durandom what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about only setting the message unless description.present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't work for me since we have a generic description on alerts
(might event be mandatory)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think it would be best to go the route of
only set it for events of a specific kind (datawarehouse_event)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@@ -193,16 +193,22 @@ def evaluate(target, inputs = {}) | |||
# If we are alerting, invoke the alert actions, then add a status so we can limit how often to alert | |||
# Otherwise, destroy this alert's statuses for our target | |||
invoke_actions(target, inputs) if result | |||
add_status_post_evaluate(target, result, inputs[:description]) | |||
|
|||
add_status_post_evaluate(target, result, inputs[:ems_event]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this change into a different commit so info is retained on the change?
app/models/miq_alert.rb
Outdated
event.try(:message), | ||
event.try(:full_data).try(:[], :severity), | ||
event.try(:full_data).try(:[], :url), | ||
] | ||
status = miq_alert_statuses.find_or_initialize_by(:resource => target) | ||
status.result = result | ||
status.ems_id = target.try(:ems_id) | ||
status.description = status_description || description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like only using it on datawarehouse_event
. It generates an inconsistency, but it will help prepare migrating the change for other events if necessary.
Addressed comment |
The same spec fails on master
|
f9ab18e
to
e34ad70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm basically 👍 with it, although there are more and more providers specifics crawling into EmsEvent - but it's not the fault of this PR
@miq-bot assign @gtanzillo
@gtanzillo merge?
@durandom @gtanzillo we could potentially go for a different approach - Benefits:
Drawbacks:
I have a feeling the current approach will require more PRs of this nature in the future. |
app/models/ems_event.rb
Outdated
@@ -164,6 +164,16 @@ def self.first_chained_event(ems_id, chain_id) | |||
EmsEvent.where(:ems_id => ems_id, :chain_id => chain_id).order(:id).first | |||
end | |||
|
|||
def self.parse_event_metadata(event) # event might be nil! | |||
status_description = nil | |||
if event.try(:event_type) == "datawarehouse_alert" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be an instance method? Then you do not have to worry about event being nil
and the caller below can change to: event.parse_event_metadata if event.respond_to?(:parse_event_metadata)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great suggestion
result | ||
end | ||
|
||
def add_status_post_evaluate(target, result, status_description) | ||
def add_status_post_evaluate(target, result, event) | ||
status_description, severity, url = event.parse_event_metadata if event.respond_to?(:parse_event_metadata) | ||
status = miq_alert_statuses.find_or_initialize_by(:resource => target) | ||
status.result = result | ||
status.ems_id = target.try(:ems_id) | ||
status.description = status_description || description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth to change the above to
status_description.blank? description : status_description
Prefer to do it in another pr though.
Addressed comments. @gmcculloug please take a look |
I just added an override for another field: result. |
app/models/miq_alert.rb
Outdated
status = miq_alert_statuses.find_or_initialize_by(:resource => target) | ||
status.result = result | ||
status.result = status_result.nil? ? result : status_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't this be just?
status.result = status_result || result
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to override the value, if it is true or false, not if it is nil.
I came to realize that it's not a good idea to override the evaluation result,
and I'll take care of that as part of the evaluation. (removing out of this pr in favor of)
app/models/miq_alert.rb
Outdated
result | ||
end | ||
|
||
def add_status_post_evaluate(target, result, status_description) | ||
def add_status_post_evaluate(target, result, event) | ||
status_description, severity, url, status_result = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be just
status_description, severity, url, status_result = event.try!(:parse_event_metadata)
@durandom @gmcculloug reverted to a previous version since I don't think overriding result is a good idea. |
Checked commits moolitayer/manageiq@3e2e70f~...0fbf598 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Allow passing some additional metadata from an EmsEvent to the MiqAlertStatus it generates.
extracted from #12773