-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Alerting: Extend server API type AlertType with property actionVariables: string[] #58529
Comments
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
Ya, we need something like this. We currently call them kibana/x-pack/plugins/alerting_builtins/server/alert_types/index_threshold/action_context.ts Lines 12 to 35 in 9bdd23a
The alerting framework itself adds some additional top-level properties available, not under kibana/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts Lines 19 to 25 in 9bdd23a
One issue is that these is the typing. You can basically think of the complete set of variables that we provide being a I'm not sure the best way to represent this type data. I'm not sure the final leaf property value types matter that much - we can stringify them if needed. Arrays seem to be the biggest problem. If you imagine we didn't allow arrays anywhere in the tree of variables, then each alert type could represent it's variables as a list of flattened keys, or perhaps with the object structure, and the property values being a "type" of the data. Eg, from the index threshold alert type, here's a flat list of properties (none are nested):
Here's a "structure" version:
Note that |
I'm currently thinking that alertTypes should probably define an array of strings of context variable names. The values for these, when expanded, would always be strings. So, In the future, instead of array of strings, an element could be an object instead of a string, where the object would define the name, and some kind of typing information that an editor could make use of: is it an array? is it a number? etc. Seems like this is a nice 90% solution, and fairly easy to implement, and keep up to date, perhaps expandable in the future. |
If ever we really want to support nested objects / arrays. I wonder if we could add support for something like Though maybe we want to put pretty names on those so they can also be localized. |
I just did a little mustache test, rendering an array by it's name: $ node
> mustache = require('mustache')
{ ... }
> mustache.render('hi')
'hi'
> mustache.render('hi {{{name}}}', {name: 'bob'})
'hi bob'
> mustache.render('hi {{{name}}}', {name: ['bob']})
'hi bob'
> mustache.render('hi {{{name}}}', {name: ['bob', 'jim']})
'hi bob,jim'
> mustache.render('{{#name}}{{.}}, {{/name}}', {name: ['bob', 'jim']})
'bob, jim, ' That last one is an example of "looping" through an array with mustache sections. So that works as well, but I don't think we need to provide UI help for it, as it could get quite elaborate. I think that may be good enough for now, to deal with arrays. Just make them available as a variable with their name, let mustache do the join on them. |
I'm not sure we want the "names" of the context variables localized, we should allow customers to enter any reasonable mustache-able template, should be the same across localization. However, it probably makes a ton of sense to provide a short description for each variable, that we would localize, that could be used as a tooltip or otherwise. |
This is a pre-cursor to elastic#58529 I realized a bit ago that we weren't making quite enough info available in the action parameter templating that happens when alerts schedule actions to execute. Missing were alert name, tags, and spaceId. For the index threshold alert, I had added them to it's context, but then every other action would have to do the same if they also wanted those values. So I added these as additional top-level variables that can be used in templates, along with the alert id, alert instance id, context, and state. The other bits in RawAlert didn't seem that interesting, to be used as an action parameter.
…59718) This is a pre-cursor to #58529 I realized a bit ago that we weren't making quite enough info available in the action parameter templating that happens when alerts schedule actions to execute. Missing were alert name, tags, and spaceId. For the index threshold alert, I had added them to it's context, but then every other action would have to do the same if they also wanted those values. So I added these as additional top-level variables that can be used in templates, along with the alert id, alert instance id, context, and state. The other bits in RawAlert didn't seem that interesting, to be used as an action parameter.
…lastic#59718) This is a pre-cursor to elastic#58529 I realized a bit ago that we weren't making quite enough info available in the action parameter templating that happens when alerts schedule actions to execute. Missing were alert name, tags, and spaceId. For the index threshold alert, I had added them to it's context, but then every other action would have to do the same if they also wanted those values. So I added these as additional top-level variables that can be used in templates, along with the alert id, alert instance id, context, and state. The other bits in RawAlert didn't seem that interesting, to be used as an action parameter.
…59718) (#59829) This is a pre-cursor to #58529 I realized a bit ago that we weren't making quite enough info available in the action parameter templating that happens when alerts schedule actions to execute. Missing were alert name, tags, and spaceId. For the index threshold alert, I had added them to it's context, but then every other action would have to do the same if they also wanted those values. So I added these as additional top-level variables that can be used in templates, along with the alert id, alert instance id, context, and state. The other bits in RawAlert didn't seem that interesting, to be used as an action parameter.
resolves elastic#58529 This PR extends alertType with an `actionVariables` property, which should be an object with optionial properties `context` and `state`. These properties should be typed as optional `Record<string, string>` values. The keys are the names of the relevant action variables, and the values are the localized descriptions of the variables.
…les (#59756) resolves #58529 This PR extends alertType with an `actionVariables` property, which describes the properties of the context object passed when scheduling actions, and the current state. These property descriptions are used by the web ui for the alert create and edit forms, to allow the properties to be added to action parameters as mustache template variables.
…les (elastic#59756) resolves elastic#58529 This PR extends alertType with an `actionVariables` property, which describes the properties of the context object passed when scheduling actions, and the current state. These property descriptions are used by the web ui for the alert create and edit forms, to allow the properties to be added to action parameters as mustache template variables.
…les (#59756) (#60082) resolves #58529 This PR extends alertType with an `actionVariables` property, which describes the properties of the context object passed when scheduling actions, and the current state. These property descriptions are used by the web ui for the alert create and edit forms, to allow the properties to be added to action parameters as mustache template variables.
Each Alert Type should has a possibility to provide a set of application specific variables, that could be added to the action message in UI.
The text was updated successfully, but these errors were encountered: