Skip to content
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

[Watcher] Support for adding actions to threshold watch #35175

Merged

Conversation

alisonelizabeth
Copy link
Contributor

@alisonelizabeth alisonelizabeth commented Apr 16, 2019

This PR adds support for adding actions via threshold alert.

  • Logging support
  • Slack support
  • Jira support
  • Webhook support
  • Email support
  • Index support
  • PagerDuty support

Other action items:

  • Field validation for each action
  • Remove hipchat support
  • Server-side support for missing actions (Jira, PagerDuty, Index & Webhook)

Instructions

Instructions for setting up accounts to test actions.

Index, webhook and logging actions can be tested without any configuration in ES.

All other actions need at least one configured account to work.

Slack

Follow documentation here.

I used my own account and created a dummy channel: #alison-watcher-test. I plan on archiving after testing is complete.

PagerDuty

Follow documentation here.

Jira

Follow documentation here.

Please DM me for details on a Jira account to use.

Email

Follow documentation here.


Screenshots

Actions panel with no actions selected:
Screen Shot 2019-04-24 at 2 15 00 PM

Actions dropdown:
Screen Shot 2019-04-23 at 2 25 24 PM

Email action:
Screen Shot 2019-04-29 at 11 50 23 AM

Logging action:
Screen Shot 2019-04-29 at 11 50 32 AM

Slack action:
Screen Shot 2019-04-29 at 11 50 40 AM

Webhook action:
Screen Shot 2019-04-29 at 11 51 02 AM

Index action:
Screen Shot 2019-04-29 at 11 51 19 AM

PagerDuty action:
Screen Shot 2019-04-29 at 11 51 35 AM

Jira action:
Screen Shot 2019-05-01 at 9 08 24 AM

Action with field error:
Screen Shot 2019-04-29 at 11 54 15 AM

Advanced watch with invalid action:
Screen Shot 2019-04-24 at 2 00 33 PM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@alisonelizabeth alisonelizabeth changed the title Threshold watch actions [Watcher] Support for adding actions to threshold watch Apr 23, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@alisonelizabeth alisonelizabeth added the non-issue Indicates to automation that a pull request should not appear in the release notes label Apr 24, 2019
@alisonelizabeth alisonelizabeth added the Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more label Apr 24, 2019
@alisonelizabeth
Copy link
Contributor Author

@cjcenizal I pushed some changes based on your review and a couple other bugs I noticed while testing.

Re:

The action_defaults files were responsible for adding some default values to the action fields, e.g., for logging, the default logging text is: "Watch [{{ctx.metadata.name}}] has exceeded the threshold." I thought it was all hard-coded text, so I moved it to each action’s model. However, now that I’m looking at the files again, I need to go back and verify the email action. It looks like it is also setting the “to” email address if xPack:defaultAdminEmail is set.

I fixed this by calling chrome.getUiSettingsClient() in the email-action model to check if there is a default email address set.

I definitely agree on the folder structure being hard to follow. What do you think about this? Note: I also moved watch_context out of the components dir.

I went ahead and made changes to the folder structure as shown in my above comment. Let me know what you think.


FYI: I need to do more thorough testing for Jira and PagerDuty actions, but I think logging, index, email and Slack are in good shape now.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@alisonelizabeth
Copy link
Contributor Author

@bmcconaghy / @cjcenizal Something else I came across while testing…

The current code was calling the cluster settings API to determine if an action was enabled or not for this dropdown menu.

Screen Shot 2019-04-23 at 2 31 43 PM

However, I don’t think this really achieves what we want, especially now that we have added support for Jira and PagerDuty. Technically, for Jira and PagerDuty (and Slack), a user only has to set some values via the keystore to configure. In this scenario, there would not be any values under the xpack.notificaton property in elasticsearch.yml that we’re checking against. Therefore, it would be marked as “not enabled” even though it is.

It looks like this may have come up before with Slack, and as a workaround, Slack is “enabled” by default in the code. I supposed we could do the same for Jira and PagerDuty, but in that case, the only thing this code is really checking for is email. Thoughts?

Code in question: https://github.com/alisonelizabeth/kibana/blob/threshold-watch-actions/x-pack/plugins/watcher/server/models/settings/settings.js

@yaronp68
Copy link

@alisonelizabeth Great work. I find the action combo too much to the right (compared to other fields)
image

@alisonelizabeth
Copy link
Contributor Author

Thanks, @yaronp68! It's currently right-aligned. I tried to replicate what existing previously, but I'm not sold on it either. Do you have any suggestions?

I wonder if it would help if there was more separation between the different sections? Another idea might be to just show the actions dropdown initially, and only render the text if an action has been added rather than having Will perform 0 actions... as a default. Then, maybe the text could sit underneath the dropdown, or something to that effect. Thoughts?

@alisonelizabeth
Copy link
Contributor Author

Had a conversation with @bmcconaghy about the actions dropdown. Updated the code to work as follows:

  • We will continue to check the yml file to attempt to determine if an action is enabled or not.
  • For actions that can technically be set up through the keystore only (Slack, Jira and PagerDuty), we will not disable it in the dropdown and instead render a warning callout indicating that the account may not be set up, with a link to the configuration docs.

Screen Shot 2019-04-26 at 4 10 06 PM


Screen Shot 2019-04-26 at 4 10 14 PM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@sebelga
Copy link
Contributor

sebelga commented Apr 29, 2019

Great job @alisonelizabeth ! For now, I only did a local test of the UI (haven't reviewed the code yet), but here are some comments on the UI.

  • I get a EUI ComboBoxOptionsList warning in the Chrome console when type the index name, has this bug been raised to them?

Screen Shot 2019-04-29 at 16 49 08

  • In other apps we've decided to only show validation after the user has submitted the form so we don't "bother" him too early while he sets the form correctly. Would it be something easy to add here?

  • I wonder if we shouldn't change the "Add an action" to a primary button with a "+" icon in it. When clicking on it, the dropdown that is currently in place would replace the button, and there would be "cancel" link button right next to it to revert. What do you think? (cc @cjcenizal )

  • For the Webhook action, do we need to separate the URL in 3 fields? Couldn't we let the user simply enter

http://www.mydomain.com:7000/some-path
// or
https://mydomain.com:7000/some-path

and extract the fields from there? If it's complex we could leave it for a second pass but, as a user, I would expect to be able to copy paste a URL in one field.

One last thing, could you add in the PR description how we can test the integration (email, Slack, Jira, Pager duty)? I'm sure I would find it in the docs somewhere but it would be much easier to copy paste your elasticsearch.yml file 😊

@alisonelizabeth
Copy link
Contributor Author

alisonelizabeth commented Apr 29, 2019

Thanks, @sebelga!

I updated the PR with links to some setup instructions. You can reach out to me regarding Jira, and of course if you have any other questions!

@cjcenizal
Copy link
Contributor

I wonder if we shouldn't change the "Add an action" to a primary button with a "+" icon in it. When clicking on it, the dropdown that is currently in place would replace the button, and there would be "cancel" link button right next to it to revert.

I think the idea of using a button is a good one. I'd suggest using the same pattern Jen used for rollup index pattern creation.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and made changes to the folder structure as shown in my above comment. Let me know what you think.

Looks much better! Thank you for doing that.

Great work on this @alisonelizabeth. This code LGTM. At a later point I think we should create a test plan for this, based on the original Watcher behavior. For this test plan, I'd expect:

  1. Explicit steps on how to get set up, e.g. a copy-pasteable elasticsearch.yml file as Seb suggested.
  2. Step-by-step instructions for testing each action, with notes on what the tester should expect to happen in the UI in response to different input (e.g. callouts, validation states).
  3. Notes on any special behaviors, e.g. setting the admin email will pre-populate the Email action's to field.

These are my just initial thoughts. @silne30 owns testing and QA so once we get to that point we'll look to him for guidance.

@cjcenizal
Copy link
Contributor

Retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I added a few comments about code style, look if you can address them.

About the client side validation that you removed, can you double checked that you went in "create advanced watch" and made sure we don't need them any more there?

Make sure we don't reintroduced the bug from #23887. where a badly formatted watch could be created in the console, and then could not be editted in the Watcher UI.

Cheers!

if (!this.to || !this.to.length) {
errors.to.push(
i18n.translate('xpack.watcher.watchActions.email.emailRecipientIsRequiredValidationMessage', {
defaultMessage: 'To email address is required.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not native speaker, but shouldn't we quote the "to"? "To" email property is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Updated, but also plan on doing a copy review with gail.

}

validate() {
const errors = [];

if (!this.to.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the validation that was added in #23887 was that we can't validate the "to" field as it is not mandatory in the UI if it has been set in elasticsearch.yml. Why do you think it is not necessary anymore to warn the user of a possible error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment regarding this above. if you still have concerns, please let me know!

* Client validation of the Watch.
* Currently we are *only* validating the Watch "Actions"
*/
validate() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remind me why we don't do any more validation client side? This is both used in Threshold alert and advanced watch.

Copy link
Contributor Author

@alisonelizabeth alisonelizabeth May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still validation, but it was added as part of the specific watch (see: models/watch/threshold_watch.js, models/watch/json_watch.js). Each action model also has its own validation.

}) => {
const { index } = action;
return (
<Fragment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to wrap a Fragment here

}) => {
const { text } = action;
return (
<Fragment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to wrap with Fragment here.

name: string;
iconClass: 'loggingApp' | 'logoWebhook' | 'logoSlack' | 'apps' | 'email' | 'indexOpen';
}) => (
<Fragment>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Fragment is not needed here. You're like @jen-huang , you love Fragments! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha. thanks for the catch - fixed. i originally had this set up a little differently where it was necessary and forgot to remove.

buttonContentClassName="euiAccordionForm__button"
buttonContent={<ButtonContent name={action.typeName} iconClass={action.iconClass} />}
extraAction={
<DeleteIcon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not directly use the <EuiButtonIcon /> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, fixed.

const { watch, setWatchProperty } = useContext(WatchContext);
const { actions } = watch;

const ButtonContent = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we declare the component outside the WatchActionsAccordion? It seems strange to me to declare a component from inside another one. It would then name it EuiAccordionButton probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. i decided to directly declare this for the buttonContent prop

const allActionTypes = Action.getActionTypes();

const actions = Object.keys(allActionTypes).map(actionKey => {
const { typeName, iconClass, selectMessage } = allActionTypes[actionKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could simplify with Object.entries

const allActionTypes = Action.getActionTypes() as Record<string, any>;

const actions = Object.entries(allActionTypes).map(([type, { typeName, iconClass, selectMessage }]) => ({
  type,
  typeName,
  iconClass,
  selectMessage,
  isEnabled: settings ? settings.actionTypes[type].enabled : true,
}));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - updated

@@ -75,21 +75,30 @@ export async function saveWatch(watch: BaseWatch, licenseService: any) {
}

export async function validateActionsAndSaveWatch(watch: BaseWatch, licenseService: any) {
const { warning } = watch.validate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is correct. From the comment

The way I setup my Slack Webhook for this watch, it has a default "to" on the slack side.

So a "to" is required. The thing is, the user can set it multiple ways. The warning that was put in place is: "we can't validate that you have set properly a "to" field, be aware that the watch might not work if you haven't specified it outside our UI".

This validation was useful if the user enters "Create advanced watch", add a JSON payload of the watch with a Slack action, but without a "to" field.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@alisonelizabeth
Copy link
Contributor Author

alisonelizabeth commented May 1, 2019

@sebelga, thanks for your review! I believe I addressed all of your comments. Also, fixed a couple bugs I came across while making changes. Can you take another look when you get a chance?

I’d like to address the design issues in a follow-up PR if that works for you (changing the actions dropdown to a button, and updating the webhook form to have one field for host/port/path)

I opened an issue against EUI regarding the ComboBox, but realized that it is working as intended. We might need to rethink how we’re using it. See: elastic/eui#1901.

I tested the scenario mentioned in #23887. It works as expected in edit mode. However, it looks like we are missing the error column and corresponding modal on the details pages (see screenshots of old UI below). This is unrelated to my changes, so I think this should be addressed in a separate PR. FYI @cjcenizal

Screen Shot 2019-04-29 at 4 40 20 PM

Screen Shot 2019-04-29 at 4 40 12 PM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@alisonelizabeth
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@alisonelizabeth alisonelizabeth merged commit 0835f38 into elastic:watcher-port May 3, 2019
@alisonelizabeth alisonelizabeth deleted the threshold-watch-actions branch May 3, 2019 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Watcher non-issue Indicates to automation that a pull request should not appear in the release notes Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants