-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add support for correlation periods for alerts #65
Conversation
@sfc-gh-nlele can correlation period be +ve? What would that mean? Do we check for that? |
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. Just a question to cover my gap in knowledge. (re: -ve vs +ve correlation_period)
@sfc-gh-pkommini positive correlation periods can be entered, but they wouldn't really be fruitful I think. The two scenarios I can think of with them are:
|
So Makes sense to me. Please merge. This was not meant to be a blocker. |
So Makes sense to me. Please merge. This was not meant to be a blocker. |
Instead of |
@sfc-gh-afedorov Sure 👍, but maybe positive values could indicate looking back (the usual case I think, it seems implied that we usually look back), and negative values could indicate looking forward? Either way works! Altho it seems like we wouldn't be able to use something like this:
and will have to use |
procedures_js/alert_processor.js
Outdated
AND event_time > DATEADD(minutes, $${CORRELATION_PERIOD_MINUTES}, ?) | ||
AND event_time > | ||
CASE | ||
WHEN REGEXP_SUBSTR(LOWER(COALESCE(alert:CORRELATION_PERIOD, $${CORRELATION_PERIOD_MINUTES})), '[a-z]') = 's' THEN DATEADD(seconds, - TO_NUMBER(REGEXP_SUBSTR(COALESCE(alert:CORRELATION_PERIOD, $${CORRELATION_PERIOD_MINUTES})), '\\d+'),?) |
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 seems like a good place to use the alternative syntax for CASE
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.
Oo right! This will be better 👍
procedures_js/alert_processor.js
Outdated
WHERE alert:EVENT_TIME > DATEADD(minutes, $${CORRELATION_PERIOD_MINUTES}, ?) | ||
WHERE alert:EVENT_TIME > | ||
CASE | ||
WHEN REGEXP_SUBSTR(LOWER(COALESCE(alert:CORRELATION_PERIOD, $${CORRELATION_PERIOD_MINUTES})), '[a-z]') = 's' THEN DATEADD(seconds, - TO_NUMBER(REGEXP_SUBSTR(COALESCE(alert:CORRELATION_PERIOD, $${CORRELATION_PERIOD_MINUTES})), '\\d+'),?) |
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.
ditto
@@ -34,6 +34,21 @@ function fillArray(value, len) { | |||
return arr | |||
} | |||
|
|||
function ifColumnExists(column_name) { |
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.
@sfc-gh-afedorov would something like this be okay for backward compatibility?
Checking if CORRELATION_PERIOD
exists in the rule definition, and then adding it to the insert statement body if it does.
@@ -62,6 +77,7 @@ SELECT '$${RUN_ID}' run_id | |||
'EVENT_DATA', IFNULL(EVENT_DATA::VARIANT, PARSE_JSON('null')), | |||
'SEVERITY', IFNULL(SEVERITY::VARIANT, PARSE_JSON('null')), | |||
'HANDLERS', IFNULL(OBJECT_CONSTRUCT(*):HANDLERS::VARIANT, PARSE_JSON('null')) | |||
$${ifColumnExists('CORRELATION_PERIOD')} |
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.
it seems better to repeat the pattern above --
'CORRELATION_PERIOD', IFNULL(OBJECT_CONSTRUCT(*):CORRELATION_PERIOD::VARIANT, PARSE_JSON('null'))
or break it into a helper that applies this pattern like
'CORRELATION_PERIOD', $${defaultNullReference('CORRELATION_PERIOD::VARIANT')}
procedures_js/alert_processor.js
Outdated
SET correlation_id = COALESCE(:1, UUID_STRING()) | ||
WHERE alert:EVENT_TIME > | ||
CASE REGEXP_SUBSTR(LOWER(COALESCE(alert:CORRELATION_PERIOD, '$${CORRELATION_PERIOD_MINUTES}')), '[a-z]') | ||
WHEN 's' THEN DATEADD(seconds, - TO_NUMBER(REGEXP_SUBSTR(COALESCE(alert:CORRELATION_PERIOD, '$${CORRELATION_PERIOD_MINUTES}'), '\\\\d+')), :2) |
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.
since these are repeated eight times, maybe another approach is better, e.g. putting the number of seconds into JS and then the SQL just uses that variable
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.
two changes pls and then feel free to merge or punt back for re-review
Tested the latest changes. |
This PR adds support for specifying custom correlation periods for individual alerts, extending having a single correlation period for all of the alerts.
This correlation period will be specified in the alert object as a negative number indicating the duration prior to the current time, for which the alerts would be correlated. If it's absent, the default correlation period set for the alert processor will be used.
E.g.
Test: