mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[BUG] Connectors with the option "If alert matches a query" don't consider ES Query config from Kibana Advanced settings (#174367)
# Summary
Fixes #174366 by fetching the ES Query configuration.
<img width="604" alt="Screenshot 2024-01-05 at 17 04 26"
src="6ca2b17b
-b69a-4bd0-900d-e1ef6adaa946">
This commit is contained in:
parent
c8d0ae5b9f
commit
dd6250bb9e
42 changed files with 211 additions and 23 deletions
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -61,6 +62,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
alertsService: null,
|
||||
maxScheduledPerMinute: 1000,
|
||||
internalSavedObjectsRepository,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
*/
|
||||
|
||||
import { RulesClient, ConstructorOptions } from '../../../../rules_client/rules_client';
|
||||
import { savedObjectsClientMock, savedObjectsRepositoryMock } from '@kbn/core/server/mocks';
|
||||
import {
|
||||
savedObjectsClientMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
|
||||
|
@ -82,6 +86,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const getBulkOperationStatusErrorResponse = (statusCode: number) => ({
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
*/
|
||||
import { AlertConsumers } from '@kbn/rule-data-utils';
|
||||
import { RulesClient, ConstructorOptions } from '../../../../rules_client/rules_client';
|
||||
import { savedObjectsClientMock, savedObjectsRepositoryMock } from '@kbn/core/server/mocks';
|
||||
import {
|
||||
savedObjectsClientMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import type { SavedObject } from '@kbn/core-saved-objects-server';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -96,6 +100,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -105,6 +106,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: getAuthenticationApiKeyMock,
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
const paramsModifier = jest.fn();
|
||||
|
||||
|
|
|
@ -638,7 +638,7 @@ async function getUpdatedAttributesFromOperations<Params extends RuleParams>({
|
|||
case 'actions': {
|
||||
const updatedOperation = {
|
||||
...operation,
|
||||
value: addGeneratedActionValues(operation.value),
|
||||
value: await addGeneratedActionValues(operation.value, context),
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { RulesClient, ConstructorOptions } from '../../../../rules_client/rules_client';
|
||||
import { savedObjectsClientMock, savedObjectsRepositoryMock } from '@kbn/core/server/mocks';
|
||||
import {
|
||||
savedObjectsClientMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
|
||||
import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks';
|
||||
|
@ -56,6 +60,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
describe('bulkUntrackAlerts()', () => {
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -85,6 +86,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -59,7 +59,10 @@ export async function createRule<Params extends RuleParams = never>(
|
|||
// TODO (http-versioning): Remove this cast when we fix addGeneratedActionValues
|
||||
const data = {
|
||||
...initialData,
|
||||
actions: addGeneratedActionValues(initialData.actions as NormalizedAlertAction[]),
|
||||
actions: await addGeneratedActionValues(
|
||||
initialData.actions as NormalizedAlertAction[],
|
||||
context
|
||||
),
|
||||
};
|
||||
|
||||
const id = options?.id || SavedObjectsUtils.generateId();
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -55,6 +56,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const getMockAggregationResult = (
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../../../rule_type_registry.mock';
|
||||
|
@ -57,6 +58,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const listedTypes = new Set<RegistryRuleType>([
|
||||
|
|
|
@ -459,7 +459,6 @@ export class AlertingPlugin {
|
|||
security,
|
||||
licenseState,
|
||||
} = this;
|
||||
|
||||
licenseState?.setNotifyUsage(plugins.licensing.featureUsage.notifyUsage);
|
||||
|
||||
const encryptedSavedObjectsClient = plugins.encryptedSavedObjects.getClient({
|
||||
|
@ -508,6 +507,7 @@ export class AlertingPlugin {
|
|||
maxScheduledPerMinute: this.config.rules.maxScheduledPerMinute,
|
||||
getAlertIndicesAlias: createGetAlertIndicesAliasFn(this.ruleTypeRegistry!),
|
||||
alertsService: this.alertsService,
|
||||
uiSettings: core.uiSettings,
|
||||
});
|
||||
|
||||
rulesSettingsClientFactory.initialize({
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`addGeneratedActionValues() throws error if KQL is not valid: "Error creating DSL query: invalid KQL" 1`] = `"Error creating DSL query: invalid KQL"`;
|
|
@ -7,12 +7,63 @@
|
|||
|
||||
import { addGeneratedActionValues } from './add_generated_action_values';
|
||||
import { RuleAction } from '../../../common';
|
||||
import { ActionsAuthorization } from '@kbn/actions-plugin/server';
|
||||
import { actionsAuthorizationMock } from '@kbn/actions-plugin/server/mocks';
|
||||
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
|
||||
import {
|
||||
savedObjectsClientMock,
|
||||
savedObjectsRepositoryMock,
|
||||
} from '@kbn/core-saved-objects-api-server-mocks';
|
||||
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
|
||||
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { AlertingAuthorization } from '../../authorization';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { ConstructorOptions } from '../rules_client';
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
v4: () => '111-222',
|
||||
}));
|
||||
|
||||
describe('addGeneratedActionValues()', () => {
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
const internalSavedObjectsRepository = savedObjectsRepositoryMock.create();
|
||||
|
||||
const kibanaVersion = 'v7.10.0';
|
||||
const logger = loggingSystemMock.create().get();
|
||||
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: authorization as unknown as AlertingAuthorization,
|
||||
actionsAuthorization: actionsAuthorization as unknown as ActionsAuthorization,
|
||||
spaceId: 'default',
|
||||
namespace: 'default',
|
||||
getUserName: jest.fn(),
|
||||
createAPIKey: jest.fn(),
|
||||
logger,
|
||||
internalSavedObjectsRepository,
|
||||
encryptedSavedObjectsClient: encryptedSavedObjects,
|
||||
getActionsClient: jest.fn(),
|
||||
getEventLogClient: jest.fn(),
|
||||
kibanaVersion,
|
||||
maxScheduledPerMinute: 10000,
|
||||
minimumScheduleInterval: { value: '1m', enforce: false },
|
||||
isAuthenticationTypeAPIKey: jest.fn(),
|
||||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const mockAction: RuleAction = {
|
||||
id: '1',
|
||||
group: 'default',
|
||||
|
@ -42,25 +93,40 @@ describe('addGeneratedActionValues()', () => {
|
|||
};
|
||||
|
||||
test('adds uuid', async () => {
|
||||
const actionWithGeneratedValues = addGeneratedActionValues([mockAction]);
|
||||
const actionWithGeneratedValues = await addGeneratedActionValues([mockAction], {
|
||||
...rulesClientParams,
|
||||
fieldsToExcludeFromPublicApi: [],
|
||||
minimumScheduleIntervalInMs: 0,
|
||||
});
|
||||
expect(actionWithGeneratedValues[0].uuid).toBe('111-222');
|
||||
});
|
||||
|
||||
test('adds DSL', async () => {
|
||||
const actionWithGeneratedValues = addGeneratedActionValues([mockAction]);
|
||||
const actionWithGeneratedValues = await addGeneratedActionValues([mockAction], {
|
||||
...rulesClientParams,
|
||||
fieldsToExcludeFromPublicApi: [],
|
||||
minimumScheduleIntervalInMs: 0,
|
||||
});
|
||||
expect(actionWithGeneratedValues[0].alertsFilter?.query?.dsl).toBe(
|
||||
'{"bool":{"must":[],"filter":[{"bool":{"should":[{"match":{"test":"testValue"}}],"minimum_should_match":1}},{"match_phrase":{"foo":"bar "}}],"should":[],"must_not":[]}}'
|
||||
);
|
||||
});
|
||||
|
||||
test('throws error if KQL is not valid', async () => {
|
||||
expect(() =>
|
||||
addGeneratedActionValues([
|
||||
expect(async () =>
|
||||
addGeneratedActionValues(
|
||||
[
|
||||
{
|
||||
...mockAction,
|
||||
alertsFilter: { query: { kql: 'foo:bar:1', filters: [] } },
|
||||
},
|
||||
],
|
||||
{
|
||||
...mockAction,
|
||||
alertsFilter: { query: { kql: 'foo:bar:1', filters: [] } },
|
||||
},
|
||||
])
|
||||
).toThrowErrorMatchingInlineSnapshot('"Error creating DSL query: invalid KQL"');
|
||||
...rulesClientParams,
|
||||
fieldsToExcludeFromPublicApi: [],
|
||||
minimumScheduleIntervalInMs: 0,
|
||||
}
|
||||
)
|
||||
).rejects.toThrowErrorMatchingSnapshot('"Error creating DSL query: invalid KQL"');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,16 +8,34 @@
|
|||
import { v4 } from 'uuid';
|
||||
import { buildEsQuery, Filter } from '@kbn/es-query';
|
||||
import Boom from '@hapi/boom';
|
||||
import { NormalizedAlertAction, NormalizedAlertActionWithGeneratedValues } from '..';
|
||||
import { UI_SETTINGS } from '@kbn/data-plugin/common';
|
||||
import {
|
||||
NormalizedAlertAction,
|
||||
NormalizedAlertActionWithGeneratedValues,
|
||||
RulesClientContext,
|
||||
} from '..';
|
||||
|
||||
export function addGeneratedActionValues(
|
||||
actions: NormalizedAlertAction[] = []
|
||||
): NormalizedAlertActionWithGeneratedValues[] {
|
||||
export async function addGeneratedActionValues(
|
||||
actions: NormalizedAlertAction[] = [],
|
||||
context: RulesClientContext
|
||||
): Promise<NormalizedAlertActionWithGeneratedValues[]> {
|
||||
const uiSettingClient = context.uiSettings.asScopedToClient(context.unsecuredSavedObjectsClient);
|
||||
const [allowLeadingWildcards, queryStringOptions, ignoreFilterIfFieldNotInIndex] =
|
||||
await Promise.all([
|
||||
uiSettingClient.get(UI_SETTINGS.QUERY_ALLOW_LEADING_WILDCARDS),
|
||||
uiSettingClient.get(UI_SETTINGS.QUERY_STRING_OPTIONS),
|
||||
uiSettingClient.get(UI_SETTINGS.COURIER_IGNORE_FILTER_IF_FIELD_NOT_IN_INDEX),
|
||||
]);
|
||||
const esQueryConfig = {
|
||||
allowLeadingWildcards,
|
||||
queryStringOptions,
|
||||
ignoreFilterIfFieldNotInIndex,
|
||||
};
|
||||
return actions.map(({ uuid, alertsFilter, ...action }) => {
|
||||
const generateDSL = (kql: string, filters: Filter[]) => {
|
||||
try {
|
||||
return JSON.stringify(
|
||||
buildEsQuery(undefined, [{ query: kql, language: 'kuery' }], filters)
|
||||
buildEsQuery(undefined, [{ query: kql, language: 'kuery' }], filters, esQueryConfig)
|
||||
);
|
||||
} catch (e) {
|
||||
throw Boom.badRequest(`Error creating DSL query: invalid KQL`);
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<RulesClientContext> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const username = 'test';
|
||||
|
|
|
@ -218,7 +218,10 @@ async function updateAlert<Params extends RuleTypeParams>(
|
|||
currentRule: SavedObject<RawRule>
|
||||
): Promise<PartialRule<Params>> {
|
||||
const { attributes, version } = currentRule;
|
||||
const data = { ...initialData, actions: addGeneratedActionValues(initialData.actions) };
|
||||
const data = {
|
||||
...initialData,
|
||||
actions: await addGeneratedActionValues(initialData.actions, context),
|
||||
};
|
||||
|
||||
const ruleType = context.ruleTypeRegistry.get(attributes.alertTypeId);
|
||||
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
*/
|
||||
import { AlertConsumers } from '@kbn/rule-data-utils';
|
||||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, savedObjectsRepositoryMock } from '@kbn/core/server/mocks';
|
||||
import {
|
||||
savedObjectsClientMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
|
@ -85,6 +89,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -72,6 +73,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
describe('clearExpiredSnoozes()', () => {
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -74,6 +75,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -76,6 +77,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -73,6 +74,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
setGlobalDate();
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -66,6 +67,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -63,6 +64,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { fromKueryExpression } from '@kbn/es-query';
|
||||
|
@ -62,6 +63,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -60,6 +61,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -63,6 +64,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import { IEventLogClient } from '@kbn/event-log-plugin/server';
|
|||
import { actionsClientMock } from '@kbn/actions-plugin/server/mocks';
|
||||
import { eventLogClientMock } from '@kbn/event-log-plugin/server/mocks';
|
||||
import { TaskStatus } from '@kbn/task-manager-plugin/server';
|
||||
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
|
||||
import { ConstructorOptions } from '../rules_client';
|
||||
import { RuleTypeRegistry } from '../../rule_type_registry';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
|
@ -50,6 +51,8 @@ export function getBeforeSetup(
|
|||
eventLogClient?: jest.Mocked<IEventLogClient>
|
||||
) {
|
||||
jest.resetAllMocks();
|
||||
rulesClientParams.uiSettings.asScopedToClient =
|
||||
uiSettingsServiceMock.createStartContract().asScopedToClient;
|
||||
rulesClientParams.createAPIKey.mockResolvedValue({ apiKeysEnabled: false });
|
||||
rulesClientParams.getUserName.mockResolvedValue('elastic');
|
||||
taskManager.runSoon.mockResolvedValue({ id: '' });
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -57,6 +58,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -63,6 +64,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -56,6 +57,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
setGlobalDate();
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -54,6 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -93,6 +94,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
|
@ -61,6 +62,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
SavedObjectsClientContract,
|
||||
PluginInitializerContext,
|
||||
ISavedObjectsRepository,
|
||||
UiSettingsServiceStart,
|
||||
} from '@kbn/core/server';
|
||||
import { ActionsClient, ActionsAuthorization } from '@kbn/actions-plugin/server';
|
||||
import {
|
||||
|
@ -78,6 +79,7 @@ export interface RulesClientContext {
|
|||
readonly getAuthenticationAPIKey: (name: string) => CreateAPIKeyResult;
|
||||
readonly getAlertIndicesAlias: GetAlertIndicesAlias;
|
||||
readonly alertsService: AlertsService | null;
|
||||
readonly uiSettings: UiSettingsServiceStart;
|
||||
}
|
||||
|
||||
export type NormalizedAlertAction = Omit<RuleAction, 'actionTypeId'>;
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
savedObjectsClientMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
|
||||
import { ruleTypeRegistryMock } from './rule_type_registry.mock';
|
||||
|
@ -69,6 +70,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
getAuthenticationAPIKey: jest.fn(),
|
||||
getAlertIndicesAlias: jest.fn(),
|
||||
alertsService: null,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
// this suite consists of two suites running tests against mutable RulesClient APIs:
|
||||
|
@ -115,6 +117,8 @@ describe('rules_client_conflict_retries', () => {
|
|||
|
||||
async function update(success: boolean) {
|
||||
try {
|
||||
rulesClientParams.uiSettings.asScopedToClient =
|
||||
uiSettingsServiceMock.createStartContract().asScopedToClient;
|
||||
await rulesClient.update({
|
||||
id: MockAlertId,
|
||||
data: {
|
||||
|
|
|
@ -13,6 +13,7 @@ import {
|
|||
savedObjectsServiceMock,
|
||||
loggingSystemMock,
|
||||
savedObjectsRepositoryMock,
|
||||
uiSettingsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks';
|
||||
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||
|
@ -58,6 +59,7 @@ const rulesClientFactoryParams: jest.Mocked<RulesClientFactoryOpts> = {
|
|||
kibanaVersion: '7.10.0',
|
||||
authorization:
|
||||
alertingAuthorizationClientFactory as unknown as AlertingAuthorizationClientFactory,
|
||||
uiSettings: uiSettingsServiceMock.createStartContract(),
|
||||
};
|
||||
|
||||
const actionsAuthorization = actionsAuthorizationMock.create();
|
||||
|
@ -70,6 +72,8 @@ beforeEach(() => {
|
|||
).getActionsAuthorizationWithRequest.mockReturnValue(actionsAuthorization);
|
||||
rulesClientFactoryParams.getSpaceId.mockReturnValue('default');
|
||||
rulesClientFactoryParams.spaceIdToNamespace.mockReturnValue('default');
|
||||
rulesClientFactoryParams.uiSettings.asScopedToClient =
|
||||
uiSettingsServiceMock.createStartContract().asScopedToClient;
|
||||
});
|
||||
|
||||
test('creates a rules client with proper constructor arguments when security is enabled', async () => {
|
||||
|
@ -117,6 +121,7 @@ test('creates a rules client with proper constructor arguments when security is
|
|||
getAuthenticationAPIKey: expect.any(Function),
|
||||
getAlertIndicesAlias: expect.any(Function),
|
||||
alertsService: null,
|
||||
uiSettings: rulesClientFactoryParams.uiSettings,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -161,6 +166,7 @@ test('creates a rules client with proper constructor arguments', async () => {
|
|||
getAuthenticationAPIKey: expect.any(Function),
|
||||
getAlertIndicesAlias: expect.any(Function),
|
||||
alertsService: null,
|
||||
uiSettings: rulesClientFactoryParams.uiSettings,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
SavedObjectsServiceStart,
|
||||
PluginInitializerContext,
|
||||
ISavedObjectsRepository,
|
||||
CoreStart,
|
||||
} from '@kbn/core/server';
|
||||
import { PluginStartContract as ActionsPluginStartContract } from '@kbn/actions-plugin/server';
|
||||
import {
|
||||
|
@ -48,6 +49,7 @@ export interface RulesClientFactoryOpts {
|
|||
maxScheduledPerMinute: AlertingRulesConfig['maxScheduledPerMinute'];
|
||||
getAlertIndicesAlias: GetAlertIndicesAlias;
|
||||
alertsService: AlertsService | null;
|
||||
uiSettings: CoreStart['uiSettings'];
|
||||
}
|
||||
|
||||
export class RulesClientFactory {
|
||||
|
@ -70,6 +72,7 @@ export class RulesClientFactory {
|
|||
private maxScheduledPerMinute!: AlertingRulesConfig['maxScheduledPerMinute'];
|
||||
private getAlertIndicesAlias!: GetAlertIndicesAlias;
|
||||
private alertsService!: AlertsService | null;
|
||||
private uiSettings!: CoreStart['uiSettings'];
|
||||
|
||||
public initialize(options: RulesClientFactoryOpts) {
|
||||
if (this.isInitialized) {
|
||||
|
@ -94,6 +97,7 @@ export class RulesClientFactory {
|
|||
this.maxScheduledPerMinute = options.maxScheduledPerMinute;
|
||||
this.getAlertIndicesAlias = options.getAlertIndicesAlias;
|
||||
this.alertsService = options.alertsService;
|
||||
this.uiSettings = options.uiSettings;
|
||||
}
|
||||
|
||||
public create(request: KibanaRequest, savedObjects: SavedObjectsServiceStart): RulesClient {
|
||||
|
@ -124,6 +128,8 @@ export class RulesClientFactory {
|
|||
auditLogger: securityPluginSetup?.audit.asScoped(request),
|
||||
getAlertIndicesAlias: this.getAlertIndicesAlias,
|
||||
alertsService: this.alertsService,
|
||||
uiSettings: this.uiSettings,
|
||||
|
||||
async getUserName() {
|
||||
if (!securityPluginStart) {
|
||||
return null;
|
||||
|
|
|
@ -64,7 +64,11 @@
|
|||
"@kbn/core-saved-objects-api-server",
|
||||
"@kbn/alerts-ui-shared",
|
||||
"@kbn/core-http-browser",
|
||||
"@kbn/core-saved-objects-api-server-mocks",
|
||||
"@kbn/core-ui-settings-server-mocks",
|
||||
"@kbn/core-test-helpers-kbn-server"
|
||||
],
|
||||
"exclude": ["target/**/*"]
|
||||
"exclude": [
|
||||
"target/**/*"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue