-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
[RAM] [Flapping] Add Flapping Rules Settings #147774
Merged
JiaweiWu
merged 29 commits into
elastic:main
from
JiaweiWu:issue-143529-flapping-config
Jan 18, 2023
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b254a69
Rules config initial implementation
JiaweiWu 7a02e3a
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 429b8fa
Merge branch 'main' into issue-143529-flapping-config
JiaweiWu 5711f5b
Future proof component with compressed mode
JiaweiWu 546394c
Merge branch 'issue-143529-flapping-config' of https://github.com/Jia…
JiaweiWu 5df9511
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 415132b
Address some comments
JiaweiWu b0b24ff
Merge branch 'main' into issue-143529-flapping-config
kibanamachine afa03cd
Unit testing
JiaweiWu 62fdf8a
Merge branch 'main' into issue-143529-flapping-config
kibanamachine bbb52ad
Features integration tests
JiaweiWu 339ceca
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 9c9f855
Merge branch 'main' into issue-143529-flapping-config
kibanamachine b40135e
API integration tests and E2E functional tests
JiaweiWu 0061c4c
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 25dc7f0
Address comments
JiaweiWu f79af29
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 390570a
Fix SO migration snapshots and tests
JiaweiWu 49627f8
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 2cc12bd
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 3a2095a
Merge branch 'main' into issue-143529-flapping-config
kibanamachine a9e8af9
Fix merge conflict
JiaweiWu c19227a
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 64f01cf
Address comments
JiaweiWu 6b1ae68
Address comments
JiaweiWu efd1b47
Fix merge conflict
JiaweiWu 585a40f
Fix tests
JiaweiWu 1f63344
Merge branch 'main' into issue-143529-flapping-config
kibanamachine 3c54c9a
Remove placeholder slider tooltip
JiaweiWu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
export interface RulesSettingsModificationMetadata { | ||
createdBy: string | null; | ||
updatedBy: string | null; | ||
createdAt: string; | ||
updatedAt: string; | ||
} | ||
|
||
export interface RulesSettingsFlappingProperties { | ||
enabled: boolean; | ||
lookBackWindow: number; | ||
statusChangeThreshold: number; | ||
} | ||
|
||
export type RulesSettingsFlapping = RulesSettingsFlappingProperties & | ||
RulesSettingsModificationMetadata; | ||
|
||
export interface RulesSettings { | ||
flapping: RulesSettingsFlapping; | ||
} | ||
|
||
export const MIN_LOOK_BACK_WINDOW = 2; | ||
export const MAX_LOOK_BACK_WINDOW = 20; | ||
export const MIN_STATUS_CHANGE_THRESHOLD = 2; | ||
export const MAX_STATUS_CHANGE_THRESHOLD = 20; | ||
|
||
export const RULES_SETTINGS_FEATURE_ID = 'rulesSettings'; | ||
export const ALL_FLAPPING_SETTINGS_SUB_FEATURE_ID = 'allFlappingSettings'; | ||
export const READ_FLAPPING_SETTINGS_SUB_FEATURE_ID = 'readFlappingSettings'; | ||
|
||
export const API_PRIVILEGES = { | ||
READ_FLAPPING_SETTINGS: 'read-flapping-settings', | ||
WRITE_FLAPPING_SETTINGS: 'write-flapping-settings', | ||
}; | ||
|
||
export const RULES_SETTINGS_SAVED_OBJECT_TYPE = 'rules-settings'; | ||
export const RULES_SETTINGS_SAVED_OBJECT_ID = 'rules-settings'; | ||
|
||
export const DEFAULT_LOOK_BACK_WINDOW = 20; | ||
export const DEFAULT_STATUS_CHANGE_THRESHOLD = 4; | ||
|
||
export const DEFAULT_FLAPPING_SETTINGS = { | ||
enabled: true, | ||
lookBackWindow: 20, | ||
statusChangeThreshold: 4, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/alerting/server/routes/get_flapping_settings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { httpServiceMock } from '@kbn/core/server/mocks'; | ||
import { licenseStateMock } from '../lib/license_state.mock'; | ||
import { mockHandlerArguments } from './_mock_handler_arguments'; | ||
import { rulesSettingsClientMock, RulesSettingsClientMock } from '../rules_settings_client.mock'; | ||
import { getFlappingSettingsRoute } from './get_flapping_settings'; | ||
|
||
let rulesSettingsClient: RulesSettingsClientMock; | ||
|
||
jest.mock('../lib/license_api_access', () => ({ | ||
verifyApiAccess: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
rulesSettingsClient = rulesSettingsClientMock.create(); | ||
}); | ||
|
||
describe('getFlappingSettingsRoute', () => { | ||
test('gets flapping settings', async () => { | ||
const licenseState = licenseStateMock.create(); | ||
const router = httpServiceMock.createRouter(); | ||
|
||
getFlappingSettingsRoute(router, licenseState); | ||
|
||
const [config, handler] = router.get.mock.calls[0]; | ||
|
||
expect(config).toMatchInlineSnapshot(` | ||
Object { | ||
"options": Object { | ||
"tags": Array [ | ||
"access:read-flapping-settings", | ||
], | ||
}, | ||
"path": "/internal/alerting/rules/settings/_flapping", | ||
"validate": false, | ||
} | ||
`); | ||
|
||
(rulesSettingsClient.flapping().get as jest.Mock).mockResolvedValue({ | ||
enabled: true, | ||
lookBackWindow: 10, | ||
statusChangeThreshold: 10, | ||
createdBy: 'test name', | ||
updatedBy: 'test name', | ||
createdAt: new Date().toISOString(), | ||
updatedAt: new Date().toISOString(), | ||
}); | ||
|
||
const [context, req, res] = mockHandlerArguments({ rulesSettingsClient }, {}, ['ok']); | ||
|
||
await handler(context, req, res); | ||
|
||
expect(rulesSettingsClient.flapping().get).toHaveBeenCalledTimes(1); | ||
expect(res.ok).toHaveBeenCalled(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/alerting/server/routes/get_flapping_settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IRouter } from '@kbn/core/server'; | ||
import { ILicenseState } from '../lib'; | ||
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../types'; | ||
import { verifyAccessAndContext } from './lib'; | ||
import { API_PRIVILEGES } from '../../common'; | ||
|
||
export const getFlappingSettingsRoute = ( | ||
router: IRouter<AlertingRequestHandlerContext>, | ||
licenseState: ILicenseState | ||
) => { | ||
router.get( | ||
{ | ||
path: `${INTERNAL_BASE_ALERTING_API_PATH}/rules/settings/_flapping`, | ||
XavierM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
validate: false, | ||
options: { | ||
tags: [`access:${API_PRIVILEGES.READ_FLAPPING_SETTINGS}`], | ||
}, | ||
}, | ||
router.handleLegacyErrors( | ||
verifyAccessAndContext(licenseState, async function (context, req, res) { | ||
const rulesSettingsClient = (await context.alerting).getRulesSettingsClient(); | ||
const flappingSettings = await rulesSettingsClient.flapping().get(); | ||
return res.ok({ body: flappingSettings }); | ||
}) | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find the existing default values, so this will obviously need to be changed 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is here for now -> https://github.com/elastic/kibana/blob/main/x-pack/plugins/alerting/server/lib/flapping_utils.ts