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

Add muting support for alerts #43712

Merged
merged 33 commits into from
Sep 30, 2019
Merged

Conversation

mikecote
Copy link
Contributor

@mikecote mikecote commented Aug 21, 2019

Resolves #46034.

In this PR, I'm adding muting support for alerts and alert instances.

Four new API endpoints have been created:

  • /api/alert/{id}/_mute_all
  • /api/alert/{id}/_unmute_all
  • /api/alert/{alertId}/alert_instance/{alertInstanceId}/_mute
  • /api/alert/{alertId}/alert_instance/{alertInstanceId}/_unmute

This will stop scheduling actions for a given alert or alert instance when muted.

Other changes include:

  • Changes in alertsClient to pass the existing attributes to any savedObjectsClient.update(...) calls when changing the apiKey (to avoid breaking AAD)

@mikecote mikecote self-assigned this Aug 21, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

Looking good, just a couple of missing tests I think.

@mikecote mikecote added v7.5.0 and removed v7.4.0 labels Aug 28, 2019
@mikecote mikecote mentioned this pull request Sep 18, 2019
@elasticmachine

This comment has been minimized.

@mikecote mikecote marked this pull request as ready for review September 23, 2019 20:26
@mikecote mikecote requested a review from a team September 23, 2019 20:26
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

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

Code LGTM

);
});

test('skips muting when alert already muted', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there room to consider not skipping but rather making it explicit that the action failed and why?
Obviously if in other places we skip then we should keep the behaviour uniform, but I'm not a fan of No-Ops tha appear to be successful as they can often obscure an underlying problem (such as UI not updating relative to retrieved data etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is to keep it uniform with the design of enable / disable which also skips if ever the alert is already in that state. Returning error isn't a bad idea but I guess it comes down to what behaviour we prefer our APIs to have.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair.
I guess, broadly, I tend to bias for explicitness and would prefer that we did return an error, but definitely only if it was done that way in all cases, and definitely isn't a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moving @bmcconaghy's comment (#43712 (comment)) here:

To me if I call an API to put something a state, and it's already in that state, that's not an error, so it makes sense to just say "OK" in that case. What value would returning an error response give? The client would then have to figure out what state things are in, and oh yeah, they're in the state the client wanted anyway. Seems like a distinction without a difference to me.

x-pack/legacy/plugins/alerting/server/alerts_client.ts Outdated Show resolved Hide resolved
groupsToScheduleActionsInSeries: ['default', null, 'default'],
},
},
});

switch (scenario.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise this isn't a new pattern, as there was already a preexisting switch like this above, but this pattern feels a little dangerous to me.

It feels like we're packing multiple tests into one and I can't help but wonder if we're stretching the scenario pattern here too much.
As a person new to this test suite, following this is hard and confusing and defeats one of the purposes of testing which is providing a clear documentation of how an API is meant to be used and what the expected behaviour is.

I wonder if perhaps we can have the tests with the Switch case explicit for each scenario, and only use the for loop for tests that are the same for each scenario and don't require a switch?

This isn't a blocker for me, but I can't shale the feeling this should be rethought.

Copy link
Contributor

Choose a reason for hiding this comment

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

To me if I call an API to put something a state, and it's already in that state, that's not an error, so it makes sense to just say "OK" in that case. What value would returning an error response give? The client would then have to figure out what state things are in, and oh yeah, they're in the state the client wanted anyway. Seems like a distinction without a difference to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To provide a bit of background on the tests. These were inspired from https://github.com/elastic/kibana/tree/master/x-pack/test/ui_capabilities as suggested by the security team. We need some coverage when security is enabled / disabled as well as spaces enabled / disabled. In order to just have coverage we opted to follow the approach they did and defer until later a look at how we want our test suite to work (https://github.com/elastic/kibana/projects/26#card-26655072).

There will be room to propose different approaches but yeah I would say lets talk then.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bmcconaghy From my perspective that would be an issue in how the error response is communicated, not with whether an error response is valid. 🤷‍♂️

I dislike No-ops, it's subjective, but they often cause invalid states to be missed so I try to avoid them when possible.
But like I said, by no means a blocker.

Copy link
Contributor

@gmmorris gmmorris left a comment

Choose a reason for hiding this comment

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

Made a few comments, but none are blockers, mostly just subjective preferences, so feel free to skip them if you disagree. :)

My one caveat is that I don't know enough about SavedObjects to catch something that's invalid in this PR, so hopefully someone with a bit more context can review too.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mikecote
Copy link
Contributor Author

@gmmorris I'm going to merge this PR and handle the API behaviour as a separate request. If we want to keep the conversation alive, lets create a card within the Make it Action project https://github.com/elastic/kibana/projects/26. We'll be able to discuss when everyone is around.

@mikecote mikecote merged commit e27b65f into elastic:master Sep 30, 2019
mikecote added a commit to mikecote/kibana that referenced this pull request Sep 30, 2019
* Create supporting API

* Rename mute terminology to mute instance to allow alert level muting

* Add alert mute and unmute APIs

* Add logic to handle alert muting

* Add integration tests + fix AAD breaking the object

* Fix failing jest tests

* Fix test failures

* Clear out mutedInstanceIds when muting / unmuting an alert

* Skip muting / unmuting instances when alert is muted

* Rename interface for alert instance

* Rename functional tests to alert instance terminology

* Add API integration tests for alert muting / unmuting

* Apply PR feedback pt1

* Create single index record action

* Function to create always firing alerts and function to generate reference

* Make tests use alert utils

* Rename mute / unmute alert routes

* Make alerts.ts integration test use alertUtils for both spaces_only and security_and_spaces

* Re-use alert utils where possible

* Change muted in mapping to muteAll

* Rename alert client methods to muteAll and unmuteAll

* Rename files

* Rename alert utils function muteAll and unmuteAll

* Rename variable in task runner

* Cleanup

* Destructure instead of using existingObject variable
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

mikecote added a commit that referenced this pull request Sep 30, 2019
* Create supporting API

* Rename mute terminology to mute instance to allow alert level muting

* Add alert mute and unmute APIs

* Add logic to handle alert muting

* Add integration tests + fix AAD breaking the object

* Fix failing jest tests

* Fix test failures

* Clear out mutedInstanceIds when muting / unmuting an alert

* Skip muting / unmuting instances when alert is muted

* Rename interface for alert instance

* Rename functional tests to alert instance terminology

* Add API integration tests for alert muting / unmuting

* Apply PR feedback pt1

* Create single index record action

* Function to create always firing alerts and function to generate reference

* Make tests use alert utils

* Rename mute / unmute alert routes

* Make alerts.ts integration test use alertUtils for both spaces_only and security_and_spaces

* Re-use alert utils where possible

* Change muted in mapping to muteAll

* Rename alert client methods to muteAll and unmuteAll

* Rename files

* Rename alert utils function muteAll and unmuteAll

* Rename variable in task runner

* Cleanup

* Destructure instead of using existingObject variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes review v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert muting
4 participants