-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAC] turn off observability alerts as data writing in a more granula…
…r way (#119602) (#120126) * [RAC] turn off writing to disabled alerts indices * fix error * fix errors * do not install component templates for disabled registration contexts * add resource installer unit tests * refactoring: disable installing index level resources in the rule data plugin service and not in the resourceInstaller * refactor based on review comments * update comment for isWriteEnabled method Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: mgiota <[email protected]>
- Loading branch information
1 parent
f0462e0
commit f6ca30d
Showing
5 changed files
with
145 additions
and
12 deletions.
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
126 changes: 126 additions & 0 deletions
126
x-pack/plugins/rule_registry/server/rule_data_plugin_service/resource_installer.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,126 @@ | ||
/* | ||
* 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 { ResourceInstaller } from './resource_installer'; | ||
import { loggerMock } from '@kbn/logging/mocks'; | ||
import { AlertConsumers } from '@kbn/rule-data-utils/alerts_as_data_rbac'; | ||
|
||
import { Dataset } from './index_options'; | ||
import { IndexInfo } from './index_info'; | ||
import { elasticsearchServiceMock } from 'src/core/server/mocks'; | ||
import { | ||
DEFAULT_ILM_POLICY_ID, | ||
ECS_COMPONENT_TEMPLATE_NAME, | ||
TECHNICAL_COMPONENT_TEMPLATE_NAME, | ||
} from '../../common/assets'; | ||
|
||
describe('resourceInstaller', () => { | ||
describe('if write is disabled', () => { | ||
it('should not install common resources', async () => { | ||
const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
const getClusterClient = jest.fn(() => Promise.resolve(mockClusterClient)); | ||
const installer = new ResourceInstaller({ | ||
logger: loggerMock.create(), | ||
isWriteEnabled: false, | ||
disabledRegistrationContexts: [], | ||
getResourceName: jest.fn(), | ||
getClusterClient, | ||
}); | ||
installer.installCommonResources(); | ||
expect(getClusterClient).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not install index level resources', () => { | ||
const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
const getClusterClient = jest.fn(() => Promise.resolve(mockClusterClient)); | ||
|
||
const installer = new ResourceInstaller({ | ||
logger: loggerMock.create(), | ||
isWriteEnabled: false, | ||
disabledRegistrationContexts: [], | ||
getResourceName: jest.fn(), | ||
getClusterClient, | ||
}); | ||
const indexOptions = { | ||
feature: AlertConsumers.LOGS, | ||
registrationContext: 'observability.logs', | ||
dataset: Dataset.alerts, | ||
componentTemplateRefs: [], | ||
componentTemplates: [ | ||
{ | ||
name: 'mappings', | ||
}, | ||
], | ||
}; | ||
const indexInfo = new IndexInfo({ indexOptions, kibanaVersion: '8.1.0' }); | ||
|
||
installer.installIndexLevelResources(indexInfo); | ||
expect(mockClusterClient.cluster.putComponentTemplate).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('if write is enabled', () => { | ||
it('should install common resources', async () => { | ||
const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
const getClusterClient = jest.fn(() => Promise.resolve(mockClusterClient)); | ||
const getResourceNameMock = jest | ||
.fn() | ||
.mockReturnValueOnce(DEFAULT_ILM_POLICY_ID) | ||
.mockReturnValueOnce(TECHNICAL_COMPONENT_TEMPLATE_NAME) | ||
.mockReturnValueOnce(ECS_COMPONENT_TEMPLATE_NAME); | ||
const installer = new ResourceInstaller({ | ||
logger: loggerMock.create(), | ||
isWriteEnabled: true, | ||
disabledRegistrationContexts: [], | ||
getResourceName: getResourceNameMock, | ||
getClusterClient, | ||
}); | ||
|
||
await installer.installCommonResources(); | ||
|
||
expect(mockClusterClient.ilm.putLifecycle).toHaveBeenCalled(); | ||
expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenCalledTimes(2); | ||
expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( | ||
1, | ||
expect.objectContaining({ name: TECHNICAL_COMPONENT_TEMPLATE_NAME }) | ||
); | ||
expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenNthCalledWith( | ||
2, | ||
expect.objectContaining({ name: ECS_COMPONENT_TEMPLATE_NAME }) | ||
); | ||
}); | ||
it('should install index level resources', async () => { | ||
const mockClusterClient = elasticsearchServiceMock.createElasticsearchClient(); | ||
const getClusterClient = jest.fn(() => Promise.resolve(mockClusterClient)); | ||
const installer = new ResourceInstaller({ | ||
logger: loggerMock.create(), | ||
isWriteEnabled: true, | ||
disabledRegistrationContexts: [], | ||
getResourceName: jest.fn(), | ||
getClusterClient, | ||
}); | ||
|
||
const indexOptions = { | ||
feature: AlertConsumers.LOGS, | ||
registrationContext: 'observability.logs', | ||
dataset: Dataset.alerts, | ||
componentTemplateRefs: [], | ||
componentTemplates: [ | ||
{ | ||
name: 'mappings', | ||
}, | ||
], | ||
}; | ||
const indexInfo = new IndexInfo({ indexOptions, kibanaVersion: '8.1.0' }); | ||
|
||
await installer.installIndexLevelResources(indexInfo); | ||
expect(mockClusterClient.cluster.putComponentTemplate).toHaveBeenCalledWith( | ||
expect.objectContaining({ name: '.alerts-observability.logs.alerts-mappings' }) | ||
); | ||
}); | ||
}); | ||
}); |
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