[Response Ops] Renaming Alert to Rule (#129136)

* Rename all the things

* Fixing checks

* Removing unnecessary change

* Fixing checks
This commit is contained in:
Ying Mao 2022-04-04 07:32:32 -04:00 committed by GitHub
parent 9e1fd5e17d
commit 25d9f5d97e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
273 changed files with 1176 additions and 1211 deletions

View file

@ -11,7 +11,7 @@ import { validateExpression } from './validation';
import { EsQueryAlertParams, SearchType } from './types';
import { RuleTypeModel } from '../../../../triggers_actions_ui/public';
import { PluginSetupContract as AlertingSetup } from '../../../../alerting/public';
import { SanitizedAlert } from '../../../../alerting/common';
import { SanitizedRule } from '../../../../alerting/common';
const PLUGIN_ID = 'discover';
const ES_QUERY_ALERT_TYPE = '.es-query';
@ -47,7 +47,7 @@ function registerNavigation(alerting: AlertingSetup) {
alerting.registerNavigation(
PLUGIN_ID,
ES_QUERY_ALERT_TYPE,
(alert: SanitizedAlert<EsQueryAlertParams<SearchType.searchSource>>) => {
(alert: SanitizedRule<EsQueryAlertParams<SearchType.searchSource>>) => {
return `#/viewAlert/${alert.id}`;
}
);

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { AlertTypeParams } from '../../../../alerting/common';
import { RuleTypeParams } from '../../../../alerting/common';
import { SerializedSearchSourceFields } from '../../../../../../src/plugins/data/common';
export interface Comparator {
@ -19,7 +19,7 @@ export enum SearchType {
searchSource = 'searchSource',
}
export interface CommonAlertParams<T extends SearchType> extends AlertTypeParams {
export interface CommonAlertParams<T extends SearchType> extends RuleTypeParams {
size: number;
thresholdComparator?: string;
threshold: number[];

View file

@ -5,10 +5,10 @@
* 2.0.
*/
import { AlertTypeParams } from '../../../../alerting/common';
import { RuleTypeParams } from '../../../../alerting/common';
import { Query } from '../../../../../../src/plugins/data/common';
export interface GeoContainmentAlertParams extends AlertTypeParams {
export interface GeoContainmentAlertParams extends RuleTypeParams {
index: string;
indexId: string;
geoField: string;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { AlertTypeParams } from '../../../../alerting/common';
import { RuleTypeParams } from '../../../../alerting/common';
export interface Comparator {
text: string;
@ -27,7 +27,7 @@ export interface GroupByType {
validNormalizedTypes: string[];
}
export interface IndexThresholdAlertParams extends AlertTypeParams {
export interface IndexThresholdAlertParams extends RuleTypeParams {
index: string | string[];
timeField?: string;
aggType: string;

View file

@ -7,12 +7,12 @@
import { i18n } from '@kbn/i18n';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { AlertExecutorOptions, AlertInstanceContext } from '../../../../alerting/server';
import { RuleExecutorOptions, AlertInstanceContext } from '../../../../alerting/server';
import { OnlyEsQueryAlertParams, OnlySearchSourceAlertParams } from './types';
// alert type context provided to actions
type AlertInfo = Pick<AlertExecutorOptions, 'name'>;
type AlertInfo = Pick<RuleExecutorOptions, 'name'>;
export interface ActionContext extends EsQueryAlertActionContext {
// a short pre-constructed message which may be used in an action field

View file

@ -7,9 +7,9 @@
import uuid from 'uuid';
import type { Writable } from '@kbn/utility-types';
import { AlertServices } from '../../../../alerting/server';
import { RuleExecutorServices } from '../../../../alerting/server';
import {
AlertServicesMock,
RuleExecutorServicesMock,
alertsMock,
AlertInstanceMock,
} from '../../../../alerting/server/mocks';
@ -146,7 +146,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.BETWEEN,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const searchResult: ESSearchResponse<unknown, {}> = generateResults([]);
alertServices.scopedClusterClient.asCurrentUser.search.mockResolvedValueOnce(
@ -175,7 +175,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const newestDocumentTimestamp = Date.now();
@ -220,7 +220,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const previousTimestamp = Date.now();
const newestDocumentTimestamp = previousTimestamp + 1000;
@ -268,7 +268,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const oldestDocumentTimestamp = Date.now();
@ -310,7 +310,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const oldestDocumentTimestamp = Date.now();
@ -381,7 +381,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const oldestDocumentTimestamp = Date.now();
@ -426,7 +426,7 @@ describe('alertType', () => {
thresholdComparator: Comparator.GT,
threshold: [0],
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const oldestDocumentTimestamp = Date.now();
@ -524,7 +524,7 @@ describe('alertType', () => {
it('alert executor handles no documents returned by ES', async () => {
const params = defaultParams;
const searchResult: ESSearchResponse<unknown, {}> = generateResults([]);
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
(searchSourceInstanceMock.getField as jest.Mock).mockImplementationOnce((name: string) => {
if (name === 'index') {
@ -540,7 +540,7 @@ describe('alertType', () => {
it('alert executor throws an error when index does not have time field', async () => {
const params = defaultParams;
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
(searchSourceInstanceMock.getField as jest.Mock).mockImplementationOnce((name: string) => {
if (name === 'index') {
@ -555,7 +555,7 @@ describe('alertType', () => {
it('alert executor schedule actions when condition met', async () => {
const params = { ...defaultParams, thresholdComparator: Comparator.GT_OR_EQ, threshold: [3] };
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
(searchSourceInstanceMock.getField as jest.Mock).mockImplementationOnce((name: string) => {
if (name === 'index') {
@ -620,7 +620,7 @@ async function invokeExecutor({
state,
}: {
params: OnlySearchSourceAlertParams | OnlyEsQueryAlertParams;
alertServices: AlertServicesMock;
alertServices: RuleExecutorServicesMock;
state?: EsQueryAlertState;
}) {
return await alertType.executor({
@ -628,7 +628,7 @@ async function invokeExecutor({
executionId: uuid.v4(),
startedAt: new Date(),
previousStartedAt: new Date(),
services: alertServices as unknown as AlertServices<
services: alertServices as unknown as RuleExecutorServices<
EsQueryAlertState,
ActionContext,
typeof ActionGroupId

View file

@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import { schema, Type, TypeOf } from '@kbn/config-schema';
import { validateTimeWindowUnits } from '../../../../triggers_actions_ui/server';
import { AlertTypeState } from '../../../../alerting/server';
import { RuleTypeState } from '../../../../alerting/server';
import { Comparator } from '../../../common/comparator_types';
import { ComparatorFnNames } from '../lib';
@ -16,7 +16,7 @@ export const ES_QUERY_MAX_HITS_PER_EXECUTION = 10000;
// alert type parameters
export type EsQueryAlertParams = TypeOf<typeof EsQueryAlertParamsSchema>;
export interface EsQueryAlertState extends AlertTypeState {
export interface EsQueryAlertState extends RuleTypeState {
latestTimestamp: string | undefined;
}

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { AlertExecutorOptions, AlertTypeParams } from '../../types';
import { RuleExecutorOptions, RuleTypeParams } from '../../types';
import { ActionContext } from './action_context';
import { EsQueryAlertParams, EsQueryAlertState } from './alert_type_params';
import { ActionGroupId } from './constants';
@ -19,7 +19,7 @@ export type OnlySearchSourceAlertParams = Omit<
searchType: 'searchSource';
};
export type ExecutorOptions<P extends AlertTypeParams> = AlertExecutorOptions<
export type ExecutorOptions<P extends RuleTypeParams> = RuleExecutorOptions<
P,
EsQueryAlertState,
{},

View file

@ -12,11 +12,11 @@ import { STACK_ALERTS_FEATURE_ID } from '../../../common';
import { getGeoContainmentExecutor } from './geo_containment';
import {
RuleType,
AlertTypeState,
RuleTypeState,
AlertInstanceState,
AlertInstanceContext,
RuleParamsAndRefs,
AlertTypeParams,
RuleTypeParams,
} from '../../../../alerting/server';
import { Query } from '../../../../../../src/plugins/data/common/query';
@ -24,7 +24,7 @@ export const ActionGroupId = 'Tracked entity contained';
export const RecoveryActionGroupId = 'notGeoContained';
export const GEO_CONTAINMENT_ID = '.geo-containment';
export interface GeoContainmentParams extends AlertTypeParams {
export interface GeoContainmentParams extends RuleTypeParams {
index: string;
indexId: string;
geoField: string;
@ -126,7 +126,7 @@ export const ParamsSchema = schema.object({
boundaryIndexQuery: schema.maybe(schema.any({})),
});
export interface GeoContainmentState extends AlertTypeState {
export interface GeoContainmentState extends RuleTypeState {
shapesFilters: Record<string, unknown>;
shapesIdsNamesMap: Record<string, unknown>;
prevLocationMap: Record<string, unknown>;

View file

@ -9,7 +9,7 @@ import _ from 'lodash';
import { Logger } from 'src/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { executeEsQueryFactory, getShapesFilters, OTHER_CATEGORY } from './es_query_builder';
import { AlertServices } from '../../../../alerting/server';
import { RuleExecutorServices } from '../../../../alerting/server';
import {
ActionGroupId,
GeoContainmentInstanceState,
@ -87,7 +87,7 @@ export function transformResults(
export function getActiveEntriesAndGenerateAlerts(
prevLocationMap: Map<string, LatestEntityLocation[]>,
currLocationMap: Map<string, LatestEntityLocation[]>,
alertFactory: AlertServices<
alertFactory: RuleExecutorServices<
GeoContainmentInstanceState,
GeoContainmentInstanceContext,
typeof ActionGroupId

View file

@ -7,7 +7,7 @@
import _ from 'lodash';
import { loggingSystemMock, elasticsearchServiceMock } from 'src/core/server/mocks';
import { AlertServicesMock, alertsMock } from '../../../../../alerting/server/mocks';
import { RuleExecutorServicesMock, alertsMock } from '../../../../../alerting/server/mocks';
import sampleAggsJsonResponse from './es_sample_response.json';
import sampleShapesJsonResponse from './es_sample_response_shapes.json';
import sampleAggsJsonResponseWithNesting from './es_sample_response_with_nesting.json';
@ -525,8 +525,8 @@ describe('geo_containment', () => {
}
});
const alertServicesWithSearchMock: AlertServicesMock = {
...alertsMock.createAlertServices(),
const alertServicesWithSearchMock: RuleExecutorServicesMock = {
...alertsMock.createRuleExecutorServices(),
// @ts-ignore
alertFactory: alertFactory(contextKeys, testAlertActionArr),
// @ts-ignore

View file

@ -7,11 +7,11 @@
import { i18n } from '@kbn/i18n';
import { Params } from './alert_type_params';
import { AlertExecutorOptions, AlertInstanceContext } from '../../../../alerting/server';
import { RuleExecutorOptions, AlertInstanceContext } from '../../../../alerting/server';
// alert type context provided to actions
type RuleInfo = Pick<AlertExecutorOptions, 'name'>;
type RuleInfo = Pick<RuleExecutorOptions, 'name'>;
export interface ActionContext extends BaseActionContext {
// a short pre-constructed message which may be used in an action field

View file

@ -8,11 +8,11 @@
import uuid from 'uuid';
import type { Writable } from '@kbn/utility-types';
import { loggingSystemMock } from '../../../../../../src/core/server/mocks';
import { AlertServices } from '../../../../alerting/server';
import { RuleExecutorServices } from '../../../../alerting/server';
import { getAlertType, ActionGroupId } from './alert_type';
import { ActionContext } from './action_context';
import { Params } from './alert_type_params';
import { AlertServicesMock, alertsMock } from '../../../../alerting/server/mocks';
import { RuleExecutorServicesMock, alertsMock } from '../../../../alerting/server/mocks';
import { Comparator } from '../../../common/comparator_types';
describe('alertType', () => {
@ -20,7 +20,7 @@ describe('alertType', () => {
const data = {
timeSeriesQuery: jest.fn(),
};
const alertServices: AlertServicesMock = alertsMock.createAlertServices();
const alertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
const alertType = getAlertType(logger, Promise.resolve(data));
@ -173,7 +173,11 @@ describe('alertType', () => {
executionId: uuid.v4(),
startedAt: new Date(),
previousStartedAt: new Date(),
services: alertServices as unknown as AlertServices<{}, ActionContext, typeof ActionGroupId>,
services: alertServices as unknown as RuleExecutorServices<
{},
ActionContext,
typeof ActionGroupId
>,
params,
state: {
latestTimestamp: undefined,
@ -208,7 +212,7 @@ describe('alertType', () => {
});
it('should ensure a null result does not fire actions', async () => {
const customAlertServices: AlertServicesMock = alertsMock.createAlertServices();
const customAlertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
data.timeSeriesQuery.mockImplementation((...args) => {
return {
results: [
@ -235,7 +239,7 @@ describe('alertType', () => {
executionId: uuid.v4(),
startedAt: new Date(),
previousStartedAt: new Date(),
services: customAlertServices as unknown as AlertServices<
services: customAlertServices as unknown as RuleExecutorServices<
{},
ActionContext,
typeof ActionGroupId
@ -274,7 +278,7 @@ describe('alertType', () => {
});
it('should ensure an undefined result does not fire actions', async () => {
const customAlertServices: AlertServicesMock = alertsMock.createAlertServices();
const customAlertServices: RuleExecutorServicesMock = alertsMock.createRuleExecutorServices();
data.timeSeriesQuery.mockImplementation((...args) => {
return {
results: [
@ -301,7 +305,7 @@ describe('alertType', () => {
executionId: uuid.v4(),
startedAt: new Date(),
previousStartedAt: new Date(),
services: customAlertServices as unknown as AlertServices<
services: customAlertServices as unknown as RuleExecutorServices<
{},
ActionContext,
typeof ActionGroupId

View file

@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import { Logger } from 'src/core/server';
import { RuleType, AlertExecutorOptions, StackAlertsStartDeps } from '../../types';
import { RuleType, RuleExecutorOptions, StackAlertsStartDeps } from '../../types';
import { Params, ParamsSchema } from './alert_type_params';
import { ActionContext, BaseActionContext, addMessages } from './action_context';
import { STACK_ALERTS_FEATURE_ID } from '../../../common';
@ -132,7 +132,7 @@ export function getAlertType(
};
async function executor(
options: AlertExecutorOptions<Params, {}, {}, ActionContext, typeof ActionGroupId>
options: RuleExecutorOptions<Params, {}, {}, ActionContext, typeof ActionGroupId>
) {
const { alertId: ruleId, name, services, params } = options;
const { alertFactory, scopedClusterClient } = services;

View file

@ -12,8 +12,8 @@ export type {
PluginSetupContract as AlertingSetup,
RuleType,
RuleParamsAndRefs,
AlertExecutorOptions,
AlertTypeParams,
RuleExecutorOptions,
RuleTypeParams,
} from '../../alerting/server';
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';