-
Notifications
You must be signed in to change notification settings - Fork 900
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
Conversation
27fc133
to
83678da
Compare
<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush. |
83678da
to
36de491
Compare
a7f5076
to
7548b17
Compare
@simon3z @lucasponce please review |
5ca8055
to
792f659
Compare
@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) |
@simon3z we should never get the same alert since we always curl for alerts after the latest one we met. |
792f659
to
38b0a99
Compare
@durandom rubocop is pissed off on my usage of loggers since they are global variables. Should that be ignored/resolved ? |
38b0a99
to
ccc8a33
Compare
Add |
ccc8a33
to
60fe3e4
Compare
@moolitayer "after" time-wise? Meaning that you use a timestamp? |
60fe3e4
to
42164eb
Compare
Yes @simon3z |
831ee7c
to
b807a42
Compare
b807a42
to
ee719e6
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.
LGTM 👍
cc @chessbyte
@cben can you review? |
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.
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
|
klass = case type | ||
def self.raw_connect(options) | ||
options[:type] ||= :alerts | ||
options[:tenant] ||= '_system' |
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.
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.
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.
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( |
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.
Very nice 😃
:value_tag_name => 'nodename', | ||
) | ||
else | ||
$datawarehouse_log.error("unexpected target: [#{tags[TAG_TYPE]}]") |
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.
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 |
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 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?
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 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] |
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.
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(...)
dbb461f
to
5b3ea33
Compare
@cben thanks, addressed comments (and tested) can you give this another quick look? I'm hoping to be done with this soon |
@blomquisg assigning to per #12773 (review), Please review/merge @miq-bot assign @blomquisg |
@@ -0,0 +1,30 @@ | |||
module ManageIQ::Providers::Hawkular::Common::RunnerMixin |
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.
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 |
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.
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 |
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 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' |
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.
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.
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.
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 |
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.
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) |
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.
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.
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 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' |
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.
What impact does severity have? Does it make more sense to just use "unknown"
?
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.
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.
5b3ea33
to
d9d2d03
Compare
Checked commits moolitayer/manageiq@cd0659a~...d9d2d03 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@moolitayer 🏆 you did it 👏 |
Thanks @durandom 🍺 |
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.