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

Pass metadata from an EmsEvent to an alert #14136

Merged
merged 2 commits into from
Mar 8, 2017

Conversation

moolitayer
Copy link

@moolitayer moolitayer commented Mar 2, 2017

Allow passing some additional metadata from an EmsEvent to the MiqAlertStatus it generates.

extracted from #12773

@@ -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])
Copy link
Author

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

Copy link

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?

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
Copy link
Author

@moolitayer moolitayer Mar 2, 2017

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)

Copy link

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.

Copy link
Author

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?

Copy link
Member

@durandom durandom Mar 3, 2017

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?

Copy link
Author

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)

Copy link
Member

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)

Copy link
Author

Choose a reason for hiding this comment

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

ok will do

Copy link

@cfcosta cfcosta left a 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])
Copy link

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?

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
Copy link

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.

@moolitayer moolitayer changed the title Pass metadata from an EmsEvent to a new alert Pass metadata from an EmsEvent to an alert Mar 3, 2017
@moolitayer
Copy link
Author

Addressed comment

@moolitayer
Copy link
Author

The same spec fails on master

$ git fetch upstream
$ git checkout upstream/master -B master
$ bundle exec bin/setup
$ bundle exec rspec spec/lib/miq_automation_engine/miq_ae_service_spec.rb
undefined method `attribute_names' for #<Module:0x00000017c4fba0>

@moolitayer moolitayer closed this Mar 3, 2017
@moolitayer moolitayer reopened this Mar 3, 2017
@moolitayer moolitayer force-pushed the alert_meta branch 2 times, most recently from f9ab18e to e34ad70 Compare March 5, 2017 11:47
Copy link
Member

@durandom durandom left a 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?

@moolitayer
Copy link
Author

moolitayer commented Mar 6, 2017

@durandom @gtanzillo we could potentially go for a different approach -
event.try(:full_data).try(:[], :miq_alert_status) # {:url => 'a', :description => 'b'}
and then override what ever is there.

Benefits:

  • not having provider specifics in EmsEvent
  • more extensive (can override all fields)

Drawbacks:

  • storing the same data twice

I have a feeling the current approach will require more PRs of this nature in the future.

@@ -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"
Copy link
Member

@gmcculloug gmcculloug Mar 6, 2017

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)

Copy link
Member

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
Copy link
Author

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.

@moolitayer
Copy link
Author

moolitayer commented Mar 7, 2017

Addressed comments. @gmcculloug please take a look

@moolitayer
Copy link
Author

I just added an override for another field: result.
That would be needed for #14121

status = miq_alert_statuses.find_or_initialize_by(:resource => target)
status.result = result
status.result = status_result.nil? ? result : status_result
Copy link
Member

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

Copy link
Author

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)

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 =
Copy link
Member

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)

@moolitayer
Copy link
Author

@durandom @gmcculloug reverted to a previous version since I don't think overriding result is a good idea.

@miq-bot
Copy link
Member

miq-bot commented Mar 8, 2017

Checked commits moolitayer/manageiq@3e2e70f~...0fbf598 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. ⭐

@gmcculloug gmcculloug merged commit e910b42 into ManageIQ:master Mar 8, 2017
@gmcculloug gmcculloug added this to the Sprint 56 Ending Mar 13, 2017 milestone Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants