## Summary
This PR is updating Discover's rule to be created under the
`stackAlerts` consumer and we created an [breaking change
issue](https://github.com/elastic/dev/issues/2344) to explain the
consequences of this update.
We also fix the rule's consumer for all rule types created under the
observability rule management to use their producer instead of `alerts`.
Also, we add the ability for the ES Query and new Generic Threshold
rules type to pick the consumer associated to the rule. The
`ensureAuthorized` and the `filter` functions have modified and
simplified to support this use case please check the newest unit test
added in
`x-pack/plugins/alerting/server/authorization/alerting_authorization.test.ts`.
There is now a dropdown in the rule form to prompt the user when
creating ES Query/Generic threshold rules to select the consumer based
on their authorized consumers (we can no longer use `alerts` for these).
If there is only 1 option, then the dropdown will not be shown and the
option will be chosen automatically.
Generic threshold rules will have the following possible consumers:
- infrastructure
- logs
ES query rules will have the following possible consumers:
- infrastructure
- logs
- stackAlerts (only from the stack management rule page)
## To Test:
### Single Consumer:
1. Create a user with only `logs` feature enabled (ensuring
`stackAlerts` is not enabled).
2. Navigate to the O11Y rule management page
3. Click the create rule button
4. Assert that both ES query and generic threshold rules are available
5. Click ES query and fill out the relevant information and create the
rule
6. Assert that the rule created has `logs` set in the `consumer` field
7. Repeat 5-6 for the generic threshold rule
8. Repeat 2-7 but on the Stack Management rules page
9. Repeat 1-8 for the `infrastructure` feature.
### Multiple Consumers:
1. Create a user with `logs`, `infrastructure` and `apm` features
enabled (ensuring `stackAlerts` is not enabled).
2. Navigate to the O11Y rule management page
3. Click the create rule button
4. Assert that both ES query and generic threshold rules are available
5. Click ES query and fill out the relevant information and create the
rule
6. A dropdown should prompt the user to select between 1 of the 3
consumers, select 1
7. Assert that the rule was created with the selected consumer
8. Repeat 5-7 for the generic threshold rule
9. Repeat 2-8 but on the Stack Management rules page


### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
---------
Co-authored-by: Jiawei Wu <74562234+JiaweiWu@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Resolves https://github.com/elastic/kibana/issues/145929
## Summary
Updates previous flapping tests to use the new flapping settings
configs.
Updates flapping logic to use flapping configs instead of hardcoded
values. Calls the flapping api on every rule execution, and then passes
in the flapping settings to the rule executors so they can be used by
the rule registry.
### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
### To verify
I think it's helpful to hide the whitespace when reviewing this pr.
- The flapping logic should remain the same, and all previous tests
should pass. I only updated them to pass in the flapping settings.
- Create rules, and set flapping settings in the ui and see the flapping
behavior change for your rules.
- Verify that the
`x-pack/test/alerting_api_integration/spaces_only/tests/alerting/event_log.ts`
run with the new flapping configs and output results we would expect
---------
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
We're working on converting all plugins into packages, which turns
almost all code in the repository into a package except for things like
the `test` and `x-pack/test` directories. The problem we ran into is
that the alerting api-integration test plugins are being migrated to
packages but they are currently consuming a handful of helpers from the
parent `../lib` directory. This doesn't work, as packages can only
import other packages and the `../lib` directory isn't in a package,
it's just free-floating `x-pack/test` code. To fix this I've moved the
necessary components out of `common/lib` and into `packages/helpers`
which is importable via `@kbn/alerting-api-integration-helpers` and
updated all the uses to access this new package.
* Add new plugint to collect additional kibana monitoring metrics
* Readme
* Update generated document
* WIP
* Remove task manager and add support for max number
* Use MAX_SAFE_INTEGER
* We won't use this route
* Tests and lint
* Track actions
* Use dynamic route style
* Fix test
* Add in mapping verification
* Adapt to new changes in base PR
* Fix types
* Feedback from PR
* PR feedback
* We do not need this
* PR feedback
* Match options to api/stats
* Remove internal collection support
* Fix api change
* Fix small issues
* Separate cluster and node metrics
* Add more tests
* Add retryAt in the test too
* Add logging and use a class
* fix types
* Fix tests
* PR feedback
* Add types
* Fix types
* Linting fixes
* Remove unnecessary changes
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
* Renaming getTestAlertData to getTestRuleData
* Adding run now route to alerting_api_integration tests
* Renaming getTestAlertData to getTestRuleData
* Adding alerting telemetry functional test
* Adding actions telemetry functional test
* Changing order of tests
* Clearing telemetry task state before running tests
* Debugging
* Cleanup
* Moving to own file
* Merge
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This PR adds _Role Based Access-Control_ to the Alerting framework & Actions feature using Kibana Feature Controls, addressing most of the Meta issue: https://github.com/elastic/kibana/issues/43994
This also closes https://github.com/elastic/kibana/issues/62438
This PR includes the following:
1. Adds `alerting` specific Security Actions (not to be confused with Alerting Actions) to the `security` plugin which allows us to assign alerting specific privileges to users of other plugins using the `features` plugin.
2. Removes the security wrapper from the savedObjectsClient in AlertsClient and instead plugs in the new AlertsAuthorization which performs the privilege checks on each api call made to the AlertsClient.
3. Adds privileges in each plugin that is already using the Alerting Framework which mirror (as closely as possible) the existing api-level tag-based privileges and plugs them into the AlertsClient.
4. Adds feature granted privileges arounds Actions (by relying on Saved Object privileges under the hood) and plugs them into the ActionsClient
5. Removes the legacy api-level tag-based privilege system from both the Alerts and Action HTTP APIs
resolves https://github.com/elastic/kibana/issues/70086
Configures the saved object client for the event log to access the recently
hidden action and alert saved objects.
We didn't have tests for action/alert event log activity, so added some now.
Also found a buglet that was preventing access to event log data from actions
and alerts in non-default spaces.
* 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
* Initial work
* Apply PR feedback pt1
* Apply PR feedback pt2
* Convert lastFired to be stored per group
* Keep track of alert instances until no longer throttled or no longer firing
* Fix broken jest tests
* Fix TypeScript types in AlertInstance
* Add unit tests for alert instance
* Rename confusing variable
* TypeScript Meta
* Fix failing api integration tests
* Add throttle integration test
* Make alert instances obsolete as soon as they don't fire
* Make action groups strict
* Change throttle behaviour as per discuss issue
* Fix jest test failures
* Cleanup
* Add test scenarios for throttle reset & changing groups
* Fix test failures
* Fix failing tests, share utils
* Cleanup
* i18n
* Rename epocTime
* Add new updateLastFired function
* Change lastScheduleActions to lastScheduledActions
* Add es test index tool class
* Make throttle string | null instead of string | undefined
* Remove isResolved
* Log instead of throwing error in createExecutionHandler
* Remove examples from regex validation
* Fix failing jest tests
* Fix throttle?: string to string | null
* Make throttle parameter mandatory on update
* Fix type check failures
* Fix failing integration test
* Fix other failing integration test
* Initial work
* Cleanup add createAPIKey fn pt1
* Change getServices function to take request as parameter
* Use API key when executing alerts
* Revert task manager using encrypted saved objects
* Store fired actions within a saved object to encrypt API keys
* Fix fireActionId
* Cleanup code, fix type check error
* Add a type for getScopedSavedObjectsClient
* Fix getBasePath and spaceIdToNamespace functions
* Add safety check for API key and action
* Fix integration tests
* Fix broken jest tests
* Cleanup
* Rename generatedApiKey to apiKeyValue
* Ensure access to action record
* Cleanup
* Add unit tests
* Fix variable conflict
* Revert task manager specific code (no longer needed)
* Remove fire terminology
* Move tests to spaces and security folder
* Use ES Archiver to remove spaces (empty_kibana)
* Fix missing pieces
* Convert action tests to run per user
* Convert alerting tests to run per user
* Fix type check issue
* Fix failing test
* Add callCluster and savedObjectsClient authorization tests
* Make savedObjectsClient return 403 for authorization tests
* Cleanup
* Fix test failure
* Common function to get data from test index
* Create ObjectRemover
* Cleanup
* useApiKey now provided to functions instead of relying on condition of two strings
* Fix typo
* Make tests it(...) start with should
* Rename useApiKey to isSecurityEnabled
* Merge apiKeyId and apiKeyValue into one
* Update docs
* Use feature controls for list alert / action types API
* Remove need to add ! in TypeScript for required plugins
* Fix ESLint issue
* Include actions and alertTypeParams into AAD and genereate new API key on update
* Generate random id for API key name attribute
* Include interval in AAD
* Send pre-encoded string
* Fix ExecutorError
* Fix apiKey snapshot
* Fix 'default' typo
* De-compose apiKey
* Refresh API key when enabling / disabling an alert
* Add updatedBy
* Make unauthorized APIs return 404
2019-08-20 11:42:15 -04:00
Renamed from x-pack/test/alerting_api_integration/apis/actions/constants.ts (Browse further)