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 triggered actions list in task state #146183
Add triggered actions list in task state #146183
Conversation
… 143376-alerts-summary-exec # Conflicts: # x-pack/plugins/alerting/server/task_runner/execution_handler.test.ts # x-pack/plugins/alerting/server/task_runner/execution_handler.ts # x-pack/plugins/alerting/server/task_runner/task_runner.ts
@@ -470,8 +470,7 @@ export class TaskRunner< | |||
); | |||
this.countUsageOfActionExecutionAfterRuleCancellation(); | |||
} else { | |||
await executionHandler.run(activeAlerts); | |||
await executionHandler.run(currentRecoveredAlerts, true); | |||
await executionHandler.run({ ...activeAlerts, ...currentRecoveredAlerts }); |
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 merged these to avoid triggering a summary action twice
I'm curious about this: kibana/x-pack/plugins/alerting/common/alert_instance.ts Lines 15 to 27 in 89baad3
It looks to me like |
Ok i thought actionId is not connectorId, it's a uuid that we generate and it sticks with the action. If it's not, i should replace it with the |
… 143376-alerts-summary-exec
This reverts commit 77b51b0.
# Conflicts: # x-pack/plugins/alerting/server/rules_client/rules_client.ts
@@ -33,13 +33,13 @@ export const bodySchema = schema.object({ | |||
enabled: schema.boolean({ defaultValue: true }), | |||
consumer: schema.string(), | |||
tags: schema.arrayOf(schema.string(), { defaultValue: [] }), | |||
throttle: schema.nullable(schema.maybe(schema.string({ validate: validateDurationSchema }))), | |||
throttle: schema.maybe(schema.nullable(schema.string({ validate: validateDurationSchema }))), |
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 order matters. schema.nullable()
converts undefined to null
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.
Finished reviewing the code, will do some testing tomorrow 👍
if (hasNotifyWhen && hasThrottle) usesRuleLevelFreqParams = true; | ||
// I removed the below ` && hasThrottle` check temporarily. | ||
// Currently the UI sends "throttle" as undefined but schema converts it to null, so they never become both undefined | ||
// I changed the schema too, but as the UI (and tests) sends "notifyWhen" as string and "throttle" as undefined, they never become both defined. | ||
// We should add it back when the UI is changed (https://github.com/elastic/kibana/issues/143369) | ||
if (hasNotifyWhen) usesRuleLevelFreqParams = true; |
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'm not sure I follow why this needs to be done temporarily until the UI changes. Is there an API breaking change introduced in the summarization process?
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.
No there isn't any breaking change. But it's a bit confusing, took me some time to figure out as well...
I want to test the new frequency fields by creating a new rule with notifyWhen
and throttle
in action level.
But as per the above code, both rule level notifyWhen
and throttle
should be undefined.
As the current schema converts undefined
throttle field value to null
(schema.nullable -> schema.maybe order) it was impossible, so i changed it.
Then functional tests started to fail because the current UI sends notifyWhen
as string and throttle
as undefined! So the following if case never returns true if (hasNotifyWhen && hasThrottle) usesRuleLevelFreqParams = true;
Therefore i removed the hasThrottle
part...
Actually, as per our design, when there are notifyWhen
and throttle
on action level, rule level ones should be null, not undefined... but we can tackle that when we implement the UI part of the meta...
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.
Tested locally and LGTM!
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.
Core changes LGTM
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Page load bundle
Saved Objects .kibana field count
Unknown metric groupsAPI count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
@@ -56,6 +56,22 @@ export const alertMappings: SavedObjectsTypeMappingDefinition = { | |||
enabled: false, | |||
type: 'object', | |||
}, | |||
frequency: { |
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.
If we're not querying these fields (index: false
) why are we specifying these fields in the mappings?
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.
We use those fields but not query by them.
I can't create a rule that has those fields without adding them in the mapping, or am i wrong?
i get:
mapping set to strict, dynamic introduction of [frequency] within [alert.actions] is not allowed: strict_dynamic_mapping_exception: [strict_dynamic_mapping_exception] Reason: mapping set to strict, dynamic introduction of [frequency] within [alert.actions] is not allowed
if they are not in the mapping.
Fixes: elastic#146049 This PR adds `actions.date` field to the alertInstances in the Task context, and TaskRunner uses it (and the new `notifyWhen` and `throttle` fields in the actions too) to decide if an action is throttled or not.
Fixes: #146049
This PR adds
actions.date
field to the alertInstances in the Task context, and TaskRunner uses it (and the newnotifyWhen
andthrottle
fields in the actions too) to decide if an action is throttled or not.To verify:
Create a rule with an action and expect it to run as usual,
Then modify the action data in backend to mimic an action that has the new
notifyWhen
andthrottle
fields and expect it to run as expected as well.I usually replace the following code with the below code snippet to mimic an action with the new fields:
kibana/x-pack/plugins/alerting/server/routes/create_rule.ts
Line 129 in 8f790d7