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

Miq Alert Status model changes for resolved alerts #14295

Merged
merged 3 commits into from
Mar 16, 2017

Conversation

moolitayer
Copy link

@moolitayer moolitayer commented Mar 13, 2017

  • ancestry was added in Model changes for alerts #13233 to model resolved alerts
    the intention was to link an open alert with a resolved one and figure out using ancestry which alerts to show in the screen (only opening ones, the have no resolving mas). It became apparent it would be more straight forward to represent that using one MAS with a new field(see next commit) and that would also make retrival more performant (save an N+1 issue).
  • resolved means the problem represented by the alerts has gone away
  • ems_ref is a reference in the provider to the event that created the alert and allows to find the opening alert when the resolving one comes into the system

@moolitayer
Copy link
Author

@miq-bot add_label enhancement, providers/containers

@simon3z
Copy link
Contributor

simon3z commented Mar 14, 2017

@moolitayer it seems that there are Travis failures to fix.
@miq-bot assign moolitayer

class AddAlertEmsRef < ActiveRecord::Migration[5.0]
def change
add_column :miq_alert_statuses, :ems_ref, :string
add_index :miq_alert_statuses, :ems_ref
Copy link
Author

@moolitayer moolitayer Mar 14, 2017

Choose a reason for hiding this comment

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

@kbrock I'm pretty sure this isn't the index I need, here is the query using it:
https://github.com/moolitayer/manageiq/blob/f423f61dbc0485eee72f2bb153ce1303e70a96dd/app/models/miq_alert.rb#L217
An explain of that query:

                                                                                                                        QUERY PLAN                                                                                 
                                        
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------
 Limit  (cost=0.00..1.04 rows=1 width=239)
   ->  Seq Scan on miq_alert_statuses  (cost=0.00..1.04 rows=1 width=239)
         Filter: ((miq_alert_id = '1000000000028'::bigint) AND ((resource_type)::text = 'ContainerNode'::text) AND (resource_id = '1000000000001'::bigint) AND ((ems_ref)::text = 'ops-example-1489487734309-58f1aa
1c-dafe-4285-bbae-ec7a788de50d'::text))
(3 rows)

Copy link
Author

Choose a reason for hiding this comment

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

@kbrock I think a good solution might be to have an index on event_ems_ref and remove the resource part from the query. WDYT?

https://github.com/moolitayer/manageiq/blob/f423f61dbc0485eee72f2bb153ce1303e70a96dd/app/models/miq_alert.rb#L217

@moolitayer
Copy link
Author

moolitayer commented Mar 14, 2017

@simon3z please review, this is the most pressing PR for me ATM, as many others depend on it.

@moolitayer
Copy link
Author

@simon3z This is the most urgent PR for me ATM, most others are dependent on it

@simon3z
Copy link
Contributor

simon3z commented Mar 15, 2017

@simon3z This is the most urgent PR for me ATM, most others are dependent on it

@moolitayer then I think you should seek some code reviews; who is familiar with this part?
When you introduced this in #13233 @cben @zeari and @Fryguy reviewed/commented (not sure but you may have also mentioned some help from @kbrock).
Involving them would be a good starting point.

@cben
Copy link
Contributor

cben commented Mar 15, 2017

The PR itself is straightforward 👍 but I'd like to better understand what ems_ref means here.
If I understand #14300 right:

  • MAS ems_ref will be set from the EmsEvent ems_ref set from the hawkular alert id.
  • when an alert gets resolved in hawkular, it's modified in-place, retaining same id, and we'll get a second EmsEvent with same ems_ref, and second MAS with same ems_ref
  • and then you'd be able to relate resolved MAS to previous MAS by looking for same ems_ref

Assuming that's right: Having several records with same ems_ref feels weird, normally this field name is a unique identifier. I don't have a better suggestion for EmsEvent — we do want 2 events for one hawkular alert — but for MAS what do you think of calling it event_ems_ref?
(Although the event is just a transport detail. Conceptually the interesting relation is between MASes and a hawkular alert.)

@miq-bot
Copy link
Member

miq-bot commented Mar 16, 2017

Checked commits moolitayer/manageiq@6851d68~...5ef9392 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks good. 🏆

@moolitayer
Copy link
Author

@cben a nicer solution model wise would be to link the MAS to the EmsEvent that caused it and use that to do the join. Unfortunately that would produce complex queries on the join for an incoming EmsEvent. I chose this way for practicality.

I've changed the name to event_ems_ref as suggested

@moolitayer
Copy link
Author

@miq-bot assign @simon3z

@miq-bot miq-bot assigned simon3z and unassigned moolitayer Mar 16, 2017
@moolitayer
Copy link
Author

@cben please review

@moolitayer
Copy link
Author

Thanks @cben @zeari. @simon3z Please review.

@simon3z
Copy link
Contributor

simon3z commented Mar 16, 2017

LGTM 👍

@miq-bot assign Fryguy

@miq-bot miq-bot assigned Fryguy and unassigned simon3z Mar 16, 2017
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

This is great!
Can feel the performance improvements already ;)

Think the only thing missing here is the data migration

class MiqAlertStatus < ApplicationRecord
SEVERITY_LEVELS = %w(error warning info).freeze

has_ancestry
Copy link
Member

Choose a reason for hiding this comment

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

yay!

@@ -0,0 +1,5 @@
class AddResolvedToAlerts < ActiveRecord::Migration[5.0]
def change
add_column :miq_alert_statuses, :resolved, :boolean
Copy link
Member

Choose a reason for hiding this comment

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

think we want to populate in a data migration

Copy link
Author

Choose a reason for hiding this comment

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

We do not need that since resolved alerts are only used in the datawarehouse provider which is prototype and hidden in the product. Also resolved alerts are not yet collected (that pr is being reviewed as well #14299)

class AddAlertEmsRef < ActiveRecord::Migration[5.0]
def change
add_column :miq_alert_statuses, :event_ems_ref, :string
add_index :miq_alert_statuses, :event_ems_ref
Copy link
Member

Choose a reason for hiding this comment

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

Is this ems_ref related to the manageiq events table at all? If not, then this name might be confusing.

Copy link
Member

Choose a reason for hiding this comment

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

Or I can just read back in the thread 😄

@Fryguy
Copy link
Member

Fryguy commented Mar 16, 2017

Having several records with same ems_ref feels weird

It's worse than weird, it's a potential problem. In the future we are considering making ems_id, ems_ref a unique index to help with some refresh issues, so that will be a problem in the future if there are duplicates.

@Fryguy Fryguy merged commit a9e013d into ManageIQ:master Mar 16, 2017
@Fryguy Fryguy added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 16, 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.

7 participants