-
Notifications
You must be signed in to change notification settings - Fork 63
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
Prometheus alerts #40
Conversation
e12b8c4
to
497cedf
Compare
497cedf
to
c00f211
Compare
c12f52f
to
566740d
Compare
This pull request is not mergeable. Please rebase and repush. |
566740d
to
a0d2b11
Compare
a0d2b11
to
c48c3bb
Compare
@enoodle please 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.
A few minor naming and privacy nits
target = find_target(labels) | ||
{ | ||
:ems_id => @cfg[:ems_id], | ||
:source => 'DATAWAREHOUSE', |
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 MONITORING
?
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.
Unfortunately that would not work as DATAWAREHOUSE
is our current hook into the event system. I have a PR renaming these two fields to MONITORING/monitoring_alert
. I update here one that has been resolved
:ems_id => @cfg[:ems_id], | ||
:source => 'DATAWAREHOUSE', | ||
:timestamp => timestamp, | ||
: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.
see comment from 2 lines above
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.
see previous response
FactoryGirl.create( | ||
:endpoint, | ||
:role => 'prometheus_alerts', | ||
:hostname => 'alerts-prometheus.10.35.48.141.nip.io', |
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.
maybe replace (here and in recordings) to fake hostname and token
FactoryGirl.create( | ||
:authentication, | ||
:authtype => 'prometheus_alerts', | ||
:auth_key => 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtYW5hZ2VtZW50LWluZnJhIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Im1hbmFnZW1lbnQtYWRtaW4tdG9rZW4tZzRscDciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoibWFuYWdlbWVudC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImQxOWUzMDk4LTZmOGUtMTFlNy04YTQ1LTAwMWE0YTE2MjY4YyIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDptYW5hZ2VtZW50LWluZnJhOm1hbmFnZW1lbnQtYWRtaW4ifQ.m4ckxIoTj__rCFA25V8lurlapNgL6doCpP51Z0JA5VgiU9mRxdk8KGyCe6w_mhrh5xPO9UuiK_pYIIMPQ-lAijRaQrKITZ-smRMEcsqKU0uP10UliJIj7ICGxn7c2zDYQuxMOQwI4ELWPv4xBHVXkF0hBKhVCPWRmdnIwADIfQi4RqoN_1gQf8S2O8C_eDS-A1f5SUf1Bvhexs997NWFBVyKEUQKxdqAlHf59V3Zt2VaE2HUme_ppYvp5L9QSa-CEZU_XxmUwNeCzcgbzts8OMujuHB_8lwKcLy9H0k3_oh-EcOn4CvzVz6pTfh8HPDoFhqpnBHfLB4pnsRkoHbDrA', |
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.
see previous comment
FactoryGirl.create( | ||
:endpoint, | ||
:role => 'prometheus_alerts', | ||
:hostname => 'alerts-prometheus.10.35.48.141.nip.io', |
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.
maybe replace (here and in recordings) to fake hostname and token
@@ -14,7 +14,7 @@ | |||
let(:prometheus_authentication) do | |||
FactoryGirl.create( | |||
:authentication, | |||
:authtype => :prometheus_alerts, | |||
:authtype => 'prometheus_alerts', | |||
:auth_key => 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtYW5hZ2VtZW50LWluZnJhIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Im1hbmFnZW1lbnQtYWRtaW4tdG9rZW4tMnBzZjMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoibWFuYWdlbWVudC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjJiMjg1MmIyLTZjNzAtMTFlNy1hYTlmLTAwMWE0YTE2MjYxOSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDptYW5hZ2VtZW50LWluZnJhOm1hbmFnZW1lbnQtYWRtaW4ifQ.OSh7pgdRXAIUh8hPipfj_me-T3cwI_DsqQUSV1yYo1qvGEd1Aa-oVaBAeKsbwjCDhcNw2nNTWkdeYoy4-MyoTjleZbvdsbtSgs84LCPdLfaVd7NXBiXtNj6o4a2tbcE_GUTBiOEyZfzFh5pwM1n9BbU6qwAvf5B-uiAuGI1VZXyiUWtlspNAEPOy3awFNt9vausNahfMRox9MLB62BYzj2NV36inpNY_UWMNV0X0Q1VnZWO6-v28JAkWhuqaRHgSOUKV1FKJDY6R4rCGxt5BnVS6_81au80vouZmv0oR6kvDPWZo6IVPG8JCIpxK0liJW65pxKIBf7oOkEzhi3wy9w', |
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.
maybe replace (here and in recordings) to fake token
@ilackarms please review |
c48c3bb
to
ad1b9c7
Compare
code climate asks to use safe navigation operator (&.) available since ruby 2.3. |
event = event.dup | ||
|
||
annotations, labels = event["annotations"], event["labels"] | ||
severity, event[:url] = annotations["severity"], annotations["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.
IMHO these are paired randomly and could read better as separate assignments.
event[:url]
write is hiding here in middle of line.labels
and its uses far below could be closer together.
|
||
event[:severity] = parse_severity(severity) | ||
event[:resolved] = event["status"] == 'resolved' | ||
event[:ems_ref] = incident_identifier(event["startsAt"], labels) |
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.
event will contain a mixture of string and symbol keys. intentional?
all the symbol keys are added only so that they appear in full_data
, right?
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.
all the symbol keys are added only so that they appear in full_data, right?
Right
event will contain a mixture of string and symbol keys. intentional?
to be taken into account these should be symbols[1], if we care about all the keys having the same type we can call deep_symbolize_keys (or have the client return symbol keyed objects). WDYT @cben?
def incident_identifier(incident_start, labels) | ||
# When event b resolves event a, they both have the same startAt. | ||
# Labels are added to avoid having two incidents starting at the same time. | ||
"#{incident_start}_#{labels.hash}" |
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.
.hash
is the ruby method returning an integer, right?
It's not stable between ruby runs (randomized seed against DOS)! And obviously not between ruby versions.
You're persisting it, which sounds bad idea.
Can you use some canonic json / yaml serialization (or its SHA if length is a concern)?
@moolitayer we can't yet because we haven't officially dropped 2.2. I haven't gotten getting this ruby 2.4 issue done to completion. Once that is complete, we'd drop support for 2.2 and only support 2.3 and 2.4. If you have feedback on which gems are complete from that list, or ones that are missing, I could use help making sure our gem ecosystem works on 2.4. |
6f12185
to
3ca4123
Compare
tested working based on 4.6 deployment efforts |
This pull request is not mergeable. Please rebase and repush. |
@ilackarms IIUC this still requires some manual activation? |
3ca4123
to
888c40b
Compare
888c40b
to
859efc7
Compare
@simon3z yes, need to manually create alert policy in Control dashboard |
8abe758
to
5b90a58
Compare
This pull request is not mergeable. Please rebase and repush. |
5b90a58
to
e292629
Compare
7d18a37
to
e79c74f
Compare
e79c74f
to
01d1a18
Compare
01d1a18
to
4cd2b3e
Compare
Checked commit moolitayer@4cd2b3e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
event[:resolved] = event["status"] == "resolved" | ||
timestamp = event["timestamp"] | ||
|
||
target = find_target(labels) |
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.
@moolitayer all the target
references below (e.g. target.id
, etc.) are crashing when target is nil
.
cc @ilackarms @joelddiaz
end | ||
|
||
def stop_event_monitor | ||
@event_monitor_handle.stop unless @event_monitor_handle.nil? |
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.
@moolitayer there's a codeclimate comment to remember here for future fixes/refactorings:
Use safe navigation (&.) instead of checking if an object exists before calling the method.
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.
See this comment: #40 (comment)
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.
@moolitayer why can't you use try
meanwhile?
Issue: ManageIQ/manageiq#14238
See issue for setup