[RAM] [Flapping] Add Flapping Rules Settings (#147774)

## Summary
Resolves: https://github.com/elastic/kibana/issues/143529
This PR adds a new saved object `rules-settings` with the schema:
```
  properties: {
    flapping: {
      properties: {
        enabled: {
          type: 'boolean',
        },
        lookBackWindow: {
          type: 'long',
        },
        statusChangeThreshold: {
          type: 'long',
        },
        createdBy: {
          type: 'keyword',
        },
        updatedBy: {
          type: 'keyword',
        },
        createdAt: {
          type: 'date',
        },
        updatedAt: {
          type: 'date',
        },
      },
    },
  },
```
It also adds 2 new endpoints:
`GET /rules/settings/_flapping`
`POST /rules/settings/_flapping`

The new rules settings saved object is instantiated per space, using a
predetermined ID to enable OCC. This new saved object allows the user to
control rules flapping settings for a given space. Access control to the
new saved object is done through the kibana features API. A new
`RulesSettingsClient` was created and can be used to interact with the
settings saved object. This saved object is instantiated lazily. When
the code calls `rulesSettingsClient.flapping().get` or
`rulesSettingsClient.flapping().update`, we will lazily create a new
saved object if one does not exist for the current space. (I have
explored bootstrapping this saved object elsewhere but I think this is
the easiest solution, I am open to change on this).

We have set up the rules settings to support future rule settings
sections by making the settings client and permissions modular. Since
permission control can be easily extended by using sub features.

This PR doesn't contain integration for the `task_runner` to use the
flapping settings, but I can do that in this PR if needed.

### Rules settings feature and sub feature (under management)

![rulessettingsprivileges](https://user-images.githubusercontent.com/74562234/210391168-f8dd53d8-21b6-43b1-b653-116c04ad69ed.png)

### Rules settings settings button

![with_permission_rules_config](https://user-images.githubusercontent.com/74562234/208450003-167521de-4222-4705-86cf-8909a6525b18.png)

### Rules settings modal

![rule_config_modal](https://user-images.githubusercontent.com/74562234/208449115-a08150d6-de93-4be7-a19e-7da91496c4a3.png)

### Disabled

![rules_config_modal_disabled](https://user-images.githubusercontent.com/74562234/208450225-8784fcdb-fa27-48cc-9785-e4a8e6360c0e.png)

### Rules settings settings button with insufficient permissions

![no_permission_rules_config](https://user-images.githubusercontent.com/74562234/208450117-9116ecaf-0ca0-4861-b0be-08554587e385.png)

### Rules settings modal with insufficient write subfeature permissions

![no_flapping_permission](https://user-images.githubusercontent.com/74562234/208450263-24a45395-9960-4b55-bbc9-8dbf88646f62.png)

### Rules settings modal with insufficient read subfeature permissions
![Screenshot from 2023-01-03
23-01-48](https://user-images.githubusercontent.com/74562234/210501223-06c9c5cd-73c2-4a11-9889-3a7505e6e0d5.png)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jiawei Wu 2023-01-17 16:40:02 -08:00 committed by GitHub
parent a0ac890f23
commit dc28138d00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 2944 additions and 4 deletions

View file

@ -47,6 +47,7 @@ export default function ({ getService }: FtrProviderContext) {
actions: ['all', 'read', 'minimal_all', 'minimal_read'],
filesManagement: ['all', 'read', 'minimal_all', 'minimal_read'],
filesSharedImage: ['all', 'read', 'minimal_all', 'minimal_read'],
rulesSettings: ['all', 'read', 'minimal_all', 'minimal_read'],
},
global: ['all', 'read'],
space: ['all', 'read'],
@ -161,6 +162,14 @@ export default function ({ getService }: FtrProviderContext) {
'packs_all',
'packs_read',
],
rulesSettings: [
'all',
'read',
'minimal_all',
'minimal_read',
'allFlappingSettings',
'readFlappingSettings',
],
},
reserved: ['fleet-setup', 'ml_user', 'ml_admin', 'ml_apm_user', 'monitoring'],
};