Skip to content
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

[RAC][Alerts as Data] Adds RAC plugin #94663

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/core/utils/default_app_categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ export const DEFAULT_APP_CATEGORIES: Record<string, AppCategory> = Object.freeze
euiIconType: 'logoKibana',
order: 1000,
},
rac: {
id: 'rac',
label: i18n.translate('core.ui.racNavList.label', {
defaultMessage: 'Rules, Alerts, Cases',
}),
order: 2000,
euiIconType: 'logoElasticStack',
},
enterpriseSearch: {
id: 'enterpriseSearch',
label: i18n.translate('core.ui.enterpriseSearchNavList.label', {
defaultMessage: 'Enterprise Search',
}),
order: 2000,
order: 3000,
euiIconType: 'logoEnterpriseSearch',
},
observability: {
Expand All @@ -33,22 +41,22 @@ export const DEFAULT_APP_CATEGORIES: Record<string, AppCategory> = Object.freeze
defaultMessage: 'Observability',
}),
euiIconType: 'logoObservability',
order: 3000,
order: 4000,
},
security: {
id: 'securitySolution',
label: i18n.translate('core.ui.securityNavList.label', {
defaultMessage: 'Security',
}),
order: 4000,
order: 5000,
euiIconType: 'logoSecurity',
},
management: {
id: 'management',
label: i18n.translate('core.ui.managementNavList.label', {
defaultMessage: 'Management',
}),
order: 5000,
order: 6000,
euiIconType: 'managementApp',
},
});
10 changes: 10 additions & 0 deletions typings/elasticsearch/search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ export type AggregateOf<
missing: {
doc_count: number;
} & SubAggregateOf<TAggregationContainer, TDocument>;
multi_terms: {
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: Array<
{
doc_count: number;
key: string[];
} & SubAggregateOf<TAggregationContainer, TDocument>
>;
};
nested: {
doc_count: number;
} & SubAggregateOf<TAggregationContainer, TDocument>;
Expand Down
11 changes: 8 additions & 3 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,16 @@ export class TaskRunner<
};
},
(err: Error) => {
const message = `Executing Alert "${alertId}" has resulted in Error: ${err.message}`;
const error = new Error(
`Executing Alert "${alertId}" has resulted in Error: ${err.message}`
);

Object.assign(error, { wrapped: err });

if (isAlertSavedObjectNotFoundError(err, alertId)) {
this.logger.debug(message);
this.logger.debug(error.message);
} else {
this.logger.error(message);
this.logger.error(error);
}
return originalState;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"licensing",
"triggersActionsUi",
"embeddable",
"infra"
"infra",
"observability"
],
"optionalPlugins": [
"cloud",
"usageCollection",
"taskManager",
"actions",
"alerting",
"observability",
"security",
"ml",
"home",
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/apm/server/lib/alerts/action_variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ export const apmActionVariables = {
'xpack.apm.alerts.action_variables.serviceName',
{ defaultMessage: 'The service the alert is created for' }
),
name: 'serviceName',
name: 'serviceName' as const,
},
transactionType: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.transactionType',
{ defaultMessage: 'The transaction type the alert is created for' }
),
name: 'transactionType',
name: 'transactionType' as const,
},
environment: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.environment',
{ defaultMessage: 'The transaction type the alert is created for' }
),
name: 'environment',
name: 'environment' as const,
},
threshold: {
description: i18n.translate('xpack.apm.alerts.action_variables.threshold', {
defaultMessage:
'Any trigger value above this value will cause the alert to fire',
}),
name: 'threshold',
name: 'threshold' as const,
},
triggerValue: {
description: i18n.translate(
Expand All @@ -44,7 +44,7 @@ export const apmActionVariables = {
'The value that breached the threshold and triggered the alert',
}
),
name: 'triggerValue',
name: 'triggerValue' as const,
},
interval: {
description: i18n.translate(
Expand All @@ -54,6 +54,6 @@ export const apmActionVariables = {
'The length and unit of the time period where the alert conditions were met',
}
),
name: 'interval',
name: 'interval' as const,
},
};
28 changes: 12 additions & 16 deletions x-pack/plugins/apm/server/lib/alerts/alerting_es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@
* 2.0.
*/

import { ApiResponse } from '@elastic/elasticsearch';
import { ThresholdMetActionGroupId } from '../../../common/alert_types';
import {
ESSearchRequest,
ESSearchResponse,
} from '../../../../../../typings/elasticsearch';
import {
AlertInstanceContext,
AlertInstanceState,
AlertServices,
} from '../../../../alerting/server';
import { AlertServices } from '../../../../alerting/server';

export function alertingEsClient<TParams extends ESSearchRequest>(
services: AlertServices<
AlertInstanceState,
AlertInstanceContext,
ThresholdMetActionGroupId
>,
export async function alertingEsClient<TParams extends ESSearchRequest>(
scopedClusterClient: AlertServices<
never,
never,
never
>['scopedClusterClient'],
params: TParams
): Promise<ApiResponse<ESSearchResponse<unknown, TParams>>> {
return (services.scopedClusterClient.asCurrentUser.search({
): Promise<ESSearchResponse<unknown, TParams>> {
const response = await scopedClusterClient.asCurrentUser.search({
...params,
ignore_unavailable: true,
}) as unknown) as Promise<ApiResponse<ESSearchResponse<unknown, TParams>>>;
});

return (response.body as unknown) as ESSearchResponse<unknown, TParams>;
}
33 changes: 10 additions & 23 deletions x-pack/plugins/apm/server/lib/alerts/register_apm_alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,25 @@
*/

import { Observable } from 'rxjs';
import { AlertingPlugin } from '../../../../alerting/server';
import { ActionsPlugin } from '../../../../actions/server';
import { Logger } from 'kibana/server';
import { registerTransactionDurationAlertType } from './register_transaction_duration_alert_type';
import { registerTransactionDurationAnomalyAlertType } from './register_transaction_duration_anomaly_alert_type';
import { registerErrorCountAlertType } from './register_error_count_alert_type';
import { APMConfig } from '../..';
import { MlPluginSetup } from '../../../../ml/server';
import { registerTransactionErrorRateAlertType } from './register_transaction_error_rate_alert_type';
import { APMRuleRegistry } from '../../plugin';

interface Params {
alerting: AlertingPlugin['setup'];
actions: ActionsPlugin['setup'];
export interface RegisterRuleDependencies {
registry: APMRuleRegistry;
ml?: MlPluginSetup;
config$: Observable<APMConfig>;
logger: Logger;
}

export function registerApmAlerts(params: Params) {
registerTransactionDurationAlertType({
alerting: params.alerting,
config$: params.config$,
});
registerTransactionDurationAnomalyAlertType({
alerting: params.alerting,
ml: params.ml,
config$: params.config$,
});
registerErrorCountAlertType({
alerting: params.alerting,
config$: params.config$,
});
registerTransactionErrorRateAlertType({
alerting: params.alerting,
config$: params.config$,
});
export function registerApmAlerts(dependencies: RegisterRuleDependencies) {
registerTransactionDurationAlertType(dependencies);
registerTransactionDurationAnomalyAlertType(dependencies);
registerErrorCountAlertType(dependencies);
registerTransactionErrorRateAlertType(dependencies);
}
Loading