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

Event collection for the datawarehouse provider #12773

Merged
merged 7 commits into from
Mar 7, 2017

Conversation

moolitayer
Copy link

@moolitayer moolitayer commented Nov 21, 2016

The Datawarehouse manager added in #12205 collects events that end up belonging to other providers. Those events are passed to the target providers/objects based on metadata they contain. A new field was added to event streams to keep track of the ext_management_system that carried the event in.

@chessbyte chessbyte added the wip label Nov 21, 2016
@moolitayer moolitayer force-pushed the datawarehouse_events branch 4 times, most recently from 27fc133 to 83678da Compare December 4, 2016 19:08
@miq-bot
Copy link
Member

miq-bot commented Dec 9, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@moolitayer moolitayer force-pushed the datawarehouse_events branch 2 times, most recently from a7f5076 to 7548b17 Compare December 11, 2016 19:27
@moolitayer moolitayer changed the title [WIP] Event collection for the datawarehouse provider. Event collection for the datawarehouse provider. Dec 11, 2016
@moolitayer
Copy link
Author

@miq-bot remove_label wip
@miq-bot add_label events

@moolitayer
Copy link
Author

@simon3z @lucasponce please review

@miq-bot miq-bot added core/events and removed wip labels Dec 11, 2016
@moolitayer moolitayer force-pushed the datawarehouse_events branch 2 times, most recently from 5ca8055 to 792f659 Compare December 11, 2016 19:36
@simon3z
Copy link
Contributor

simon3z commented Dec 12, 2016

@moolitayer we poll for alerts right? How do we know if an alert was collected already or not? (You mentioned a timestamp once IIRC, although it would be great if we found something more reliable)

@moolitayer
Copy link
Author

@simon3z we should never get the same alert since we always curl for alerts after the latest one we met.

@moolitayer
Copy link
Author

@durandom rubocop is pissed off on my usage of loggers since they are global variables. Should that be ignored/resolved ?

@durandom
Copy link
Member

loggers since they are global variables.

Add $dwh_log to .rubocop.yml

@simon3z
Copy link
Contributor

simon3z commented Dec 12, 2016

@simon3z we should never get the same alert since we always curl for alerts after the latest one we met.

@moolitayer "after" time-wise? Meaning that you use a timestamp?

@moolitayer
Copy link
Author

@moolitayer "after" time-wise? Meaning that you use a timestamp?

Yes @simon3z

@moolitayer moolitayer force-pushed the datawarehouse_events branch from 831ee7c to b807a42 Compare March 6, 2017 17:08
@moolitayer
Copy link
Author

@durandom @simon3z There are no more outstanding issues with this PR AFAIK. I also tested it just now and made sure it works (and fixed a small problem caused by missing parameter to blacklist?)

@moolitayer moolitayer force-pushed the datawarehouse_events branch from b807a42 to ee719e6 Compare March 6, 2017 18:10
Copy link
Contributor

@simon3z simon3z left a comment

Choose a reason for hiding this comment

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

LGTM 👍
cc @chessbyte

@miq-bot assign durandom
Ready for review/merge @durandom

@simon3z
Copy link
Contributor

simon3z commented Mar 6, 2017

@cben can you review?

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.

This has come a loooong way :)

LGTM

@cben if you are ok with the changes in the connect logic please assign it to @blomquisg to merge

@moolitayer
Copy link
Author

  • bring missing settings section back
  • unite to use one settings section for event catching related properties

klass = case type
def self.raw_connect(options)
options[:type] ||= :alerts
options[:tenant] ||= '_system'
Copy link
Contributor

Choose a reason for hiding this comment

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

This mutates the hash passed in. No immediate bug but IMO better avoided, e.g.

type = options[:type] || :alerts
tenant = options[:tenant] || '_system'

and then use type, tenant below.

Copy link

Choose a reason for hiding this comment

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

type = options.fetch(:type) { :alerts }
tenant = options.fetch(:tenant) { '_system' }

This is the "more correct" way of doing this, because if the user sets the key to nil or false they mean it, and we such treat it as such.

options[:type]
memo_options = options.slice(:type, :tenant)
@clients[memo_options.freeze] ||= self.class.raw_connect(
memo_options.merge(
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice 😃

:value_tag_name => 'nodename',
)
else
$datawarehouse_log.error("unexpected target: [#{tags[TAG_TYPE]}]")
Copy link
Contributor

Choose a reason for hiding this comment

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

what value does target take then?
add explicit nil line (if that's what you meant), or an early return.

end
instance = nil
instance = target.klass_name.constantize.find_by(target.find_key => tags[target.value_tag_name]) if target
$datawarehouse_log.error("Could not find hawkular alert target from tags: [#{tags}]") unless instance
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the error logic hard to follow here. Actually all logic.
IIUC there is single happy path: type tag is "node" -> ContainerNode.find_by(:name => tags['nodename']).
Do you need all the indirection via an OpenStruct?

Copy link
Author

Choose a reason for hiding this comment

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

I expect this would get more complicated going forward (we are expecting more targets).
I prefer to express this complexity with data and not code (we can add more data and this code would work)


def event_to_hash(event, current_ems_id)
event.severity = map_severity(event.severity) # gets into event.full_data
event.url = event.tags[TAG_URL]
Copy link
Contributor

Choose a reason for hiding this comment

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

again, consider not mutating argument. I wouldn't expect side effects from a function named foo_to_hash.
can do :full_data => event.to_h.merge(...)

@moolitayer moolitayer force-pushed the datawarehouse_events branch from dbb461f to 5b3ea33 Compare March 7, 2017 13:04
@moolitayer
Copy link
Author

@cben thanks, addressed comments (and tested) can you give this another quick look? I'm hoping to be done with this soon

@moolitayer
Copy link
Author

@blomquisg assigning to per #12773 (review), Please review/merge

@miq-bot assign @blomquisg

@miq-bot miq-bot assigned blomquisg and unassigned simon3z Mar 7, 2017
@@ -0,0 +1,30 @@
module ManageIQ::Providers::Hawkular::Common::RunnerMixin
Copy link

Choose a reason for hiding this comment

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

Naming something *Mixin is poor ruby style. Not a blocker, but definitely something to keep in mind.

@@ -0,0 +1,17 @@
module ManageIQ::Providers::Hawkular::Common::StreamMixin
Copy link

Choose a reason for hiding this comment

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

Why not implement http://ruby-doc.org/core-2.4.0/Enumerable.html into this mixin? That way you get more than just #each for free, while also having the code be idiomatic ruby.

extend ActiveSupport::Concern

def log_handle
self.class.log_handle
Copy link

Choose a reason for hiding this comment

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

I don't like naming things handle. It'd be better to have them as logger and event_monitor. The handle part has no semantic meaning, because you can understand without they are for without that part.

klass = case type
def self.raw_connect(options)
options[:type] ||= :alerts
options[:tenant] ||= '_system'
Copy link

Choose a reason for hiding this comment

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

type = options.fetch(:type) { :alerts }
tenant = options.fetch(:tenant) { '_system' }

This is the "more correct" way of doing this, because if the user sets the key to nil or false they mean it, and we such treat it as such.

Copy link
Member

@blomquisg blomquisg left a comment

Choose a reason for hiding this comment

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

Marking this Approved. I have a few small nitpicks, but generally, I'm fine with it.

@@ -38,38 +39,42 @@ def self.verify_ssl_mode
end

# Hawkular Client
def self.raw_connect(hostname, port, token, type = :alerts)
def self.raw_connect(options)
type = options[:type] || :alerts
Copy link
Member

Choose a reason for hiding this comment

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

In all other providers, this key is called :service. Does this have to be :type? Or, can it be :service instead?


EDIT
I just realized that the type was a preexisting method param. I won't hold up this PR on my comment here. @lucasponce can you take a note here and switch this to :service in a separate PR?

end
end

def blacklist?(event_type)
Copy link
Member

Choose a reason for hiding this comment

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

blacklist? takes an event_type and whitelist? takes an event. Principle of least surprised suggests that these would take the same parameter type.

Also, a small nitpick. Past tense makes the names work better as predicate methods: blacklisted? and whitelisted? I don't really care if you ignore me on this one, just thought I'd point it out.

Copy link
Author

Choose a reason for hiding this comment

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

I addressed the blacklist|whitelist vs blacklisted|whitelisted issue.
As for the blacklist?(event_type) vs whitelist?(event) this stems from hawkular's current implementation. We had a long discussion on whether we can improve that (#12773 (comment) and above). It seems at this point we can not, but I will keep my my open for an opportunity.

The difference between event_type and event is because whitelist checks a raw event where it is a little harder to figure out the type

when "CRITICAL" then 'error'
else
$datawarehouse_log.error("Could not map hawkular severity [#{hwk_severity}], using error")
'error'
Copy link
Member

Choose a reason for hiding this comment

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

What impact does severity have? Does it make more sense to just use "unknown"?

Copy link
Author

@moolitayer moolitayer Mar 7, 2017

Choose a reason for hiding this comment

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

these seventies are carried to the seventies recently added to miq_alert_status (designed with three levels in mind). Since that is what the screen knows to handle, I prefer to go worst case if we cannot determine that.

@moolitayer moolitayer force-pushed the datawarehouse_events branch from 5b3ea33 to d9d2d03 Compare March 7, 2017 15:04
@miq-bot
Copy link
Member

miq-bot commented Mar 7, 2017

Checked commits moolitayer/manageiq@cd0659a~...d9d2d03 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
9 files checked, 0 offenses detected
Everything looks good. 🏆

@blomquisg blomquisg merged commit 36a423e into ManageIQ:master Mar 7, 2017
@blomquisg blomquisg added this to the Sprint 56 Ending Mar 13, 2017 milestone Mar 7, 2017
@durandom
Copy link
Member

durandom commented Mar 8, 2017

@moolitayer 🏆 you did it 👏

@moolitayer
Copy link
Author

Thanks @durandom 🍺

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.