Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into clone-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Nov 14, 2022
2 parents 2dfc7b4 + b72a9a3 commit c96c59f
Show file tree
Hide file tree
Showing 76 changed files with 2,550 additions and 548 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pageLoadAssetSize:
controls: 40000
core: 435325
crossClusterReplication: 65408
customIntegrations: 44305
customIntegrations: 22034
dashboard: 82025
dashboardEnhanced: 65646
data: 454087
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
Object {
"action": "7858e6d5a9f231bf23f6f2e57328eb0095b26735",
"action_task_params": "bbd38cbfd74bf6713586fe078e3fa92db2234299",
"alert": "48461f3375d9ba22882ea23a318b62a5b0921a9b",
"alert": "eefada4a02ce05962387c0679d7b292771a931c4",
"api_key_pending_invalidation": "9b4bc1235337da9a87ef05a1d1f4858b2a3b77c6",
"apm-indices": "ceb0870f3a74e2ffc3a1cd3a3c73af76baca0999",
"apm-server-schema": "2bfd2998d3873872e1366458ce553def85418f91",
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/custom_integrations/public/language_components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { SampleClientReadme } from './components/fleet_integration/sample/sample_client_readme';
export { ElasticsearchJsClientReadme } from './components/fleet_integration/elasticsearch_js/elasticsearch_js_readme';
export { ElasticsearchPyClientReadme } from './components/fleet_integration/elasticsearch_py/elasticsearch_py_readme';
16 changes: 9 additions & 7 deletions src/plugins/custom_integrations/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import {

import { CustomIntegrationsServicesProvider } from './services';
import { servicesFactory } from './services/kibana';
import { SampleClientReadme } from './components/fleet_integration/sample/sample_client_readme';
import { ElasticsearchJsClientReadme } from './components/fleet_integration/elasticsearch_js/elasticsearch_js_readme';
import { ElasticsearchPyClientReadme } from './components/fleet_integration/elasticsearch_py/elasticsearch_py_readme';

export class CustomIntegrationsPlugin
implements Plugin<CustomIntegrationsSetup, CustomIntegrationsStart>
{
Expand All @@ -49,9 +45,15 @@ export class CustomIntegrationsPlugin
const services = servicesFactory({ coreStart, startPlugins });

const languageClientsUiComponents = {
sample: SampleClientReadme,
javascript: ElasticsearchJsClientReadme,
python: ElasticsearchPyClientReadme,
sample: React.lazy(async () => ({
default: (await import('./language_components')).SampleClientReadme,
})),
javascript: React.lazy(async () => ({
default: (await import('./language_components')).ElasticsearchJsClientReadme,
})),
python: React.lazy(async () => ({
default: (await import('./language_components')).ElasticsearchPyClientReadme,
})),
};

const ContextProvider: React.FC = ({ children }) => (
Expand Down
52 changes: 44 additions & 8 deletions x-pack/plugins/alerting/common/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const RuleExecutionStatusValues = [
] as const;
export type RuleExecutionStatuses = typeof RuleExecutionStatusValues[number];

export const RuleLastRunOutcomeValues = ['succeeded', 'warning', 'failed'] as const;
export type RuleLastRunOutcomes = typeof RuleLastRunOutcomeValues[number];

export enum RuleExecutionStatusErrorReasons {
Read = 'read',
Decrypt = 'decrypt',
Expand Down Expand Up @@ -76,12 +79,25 @@ export interface RuleAction {

export interface RuleAggregations {
alertExecutionStatus: { [status: string]: number };
ruleLastRunOutcome: { [status: string]: number };
ruleEnabledStatus: { enabled: number; disabled: number };
ruleMutedStatus: { muted: number; unmuted: number };
ruleSnoozedStatus: { snoozed: number };
ruleTags: string[];
}

export interface RuleLastRun {
outcome: RuleLastRunOutcomes;
warning?: RuleExecutionStatusErrorReasons | RuleExecutionStatusWarningReasons | null;
outcomeMsg?: string | null;
alertsCount: {
active?: number | null;
new?: number | null;
recovered?: number | null;
ignored?: number | null;
};
}

export interface MappedParamsProperties {
risk_score?: number;
severity?: string;
Expand Down Expand Up @@ -116,6 +132,8 @@ export interface Rule<Params extends RuleTypeParams = never> {
snoozeSchedule?: RuleSnooze; // Remove ? when this parameter is made available in the public API
activeSnoozes?: string[];
isSnoozedUntil?: Date | null;
lastRun?: RuleLastRun | null;
nextRun?: Date | null;
}

export type SanitizedRule<Params extends RuleTypeParams = never> = Omit<Rule<Params>, 'apiKey'>;
Expand Down Expand Up @@ -175,16 +193,34 @@ export interface RuleMonitoringHistory extends SavedObjectAttributes {
success: boolean;
timestamp: number;
duration?: number;
outcome?: RuleLastRunOutcomes;
}

export interface RuleMonitoringCalculatedMetrics extends SavedObjectAttributes {
p50?: number;
p95?: number;
p99?: number;
success_ratio: number;
}

export interface RuleMonitoringLastRunMetrics extends SavedObjectAttributes {
duration?: number;
total_search_duration_ms?: number | null;
total_indexing_duration_ms?: number | null;
total_alerts_detected?: number | null;
total_alerts_created?: number | null;
gap_duration_s?: number | null;
}

export interface RuleMonitoringLastRun extends SavedObjectAttributes {
timestamp: string;
metrics: RuleMonitoringLastRunMetrics;
}

export interface RuleMonitoring extends SavedObjectAttributes {
execution: {
export interface RuleMonitoring {
run: {
history: RuleMonitoringHistory[];
calculated_metrics: {
p50?: number;
p95?: number;
p99?: number;
success_ratio: number;
};
calculated_metrics: RuleMonitoringCalculatedMetrics;
last_run: RuleMonitoringLastRun;
};
}
150 changes: 149 additions & 1 deletion x-pack/plugins/alerting/public/lib/common_transformations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { ApiRule, transformRule } from './common_transformations';
import { RuleExecutionStatusErrorReasons } from '../../common';
import { RuleExecutionStatusErrorReasons, RuleLastRunOutcomeValues } from '../../common';

beforeEach(() => jest.resetAllMocks());

Expand Down Expand Up @@ -54,6 +54,43 @@ describe('common_transformations', () => {
message: 'this is just a test',
},
},
monitoring: {
run: {
history: [
{
timestamp: dateExecuted.getTime(),
duration: 42,
success: false,
outcome: RuleLastRunOutcomeValues[2],
},
],
calculated_metrics: {
success_ratio: 0,
p50: 0,
p95: 42,
p99: 42,
},
last_run: {
timestamp: dateExecuted.toISOString(),
metrics: {
duration: 42,
total_search_duration_ms: 100,
},
},
},
},
last_run: {
outcome: RuleLastRunOutcomeValues[2],
outcome_msg: 'this is just a test',
warning: RuleExecutionStatusErrorReasons.Unknown,
alerts_count: {
new: 1,
active: 2,
recovered: 3,
ignored: 4,
},
},
next_run: dateUpdated.toISOString(),
};
expect(transformRule(apiRule)).toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -89,12 +126,49 @@ describe('common_transformations', () => {
"status": "error",
},
"id": "some-id",
"lastRun": Object {
"alertsCount": Object {
"active": 2,
"ignored": 4,
"new": 1,
"recovered": 3,
},
"outcome": "failed",
"outcomeMsg": "this is just a test",
"warning": "unknown",
},
"monitoring": Object {
"run": Object {
"calculated_metrics": Object {
"p50": 0,
"p95": 42,
"p99": 42,
"success_ratio": 0,
},
"history": Array [
Object {
"duration": 42,
"outcome": "failed",
"success": false,
"timestamp": 1639571696789,
},
],
"last_run": Object {
"metrics": Object {
"duration": 42,
"total_search_duration_ms": 100,
},
"timestamp": "2021-12-15T12:34:56.789Z",
},
},
},
"muteAll": false,
"mutedInstanceIds": Array [
"bob",
"jim",
],
"name": "some-name",
"nextRun": 2021-12-15T12:34:55.789Z,
"notifyWhen": "onActiveAlert",
"params": Object {
"bar": "foo",
Expand Down Expand Up @@ -152,6 +226,43 @@ describe('common_transformations', () => {
last_execution_date: dateExecuted.toISOString(),
status: 'error',
},
monitoring: {
run: {
history: [
{
timestamp: dateExecuted.getTime(),
duration: 42,
success: false,
outcome: 'failed',
},
],
calculated_metrics: {
success_ratio: 0,
p50: 0,
p95: 42,
p99: 42,
},
last_run: {
timestamp: dateExecuted.toISOString(),
metrics: {
duration: 42,
total_search_duration_ms: 100,
},
},
},
},
last_run: {
outcome: 'failed',
outcome_msg: 'this is just a test',
warning: RuleExecutionStatusErrorReasons.Unknown,
alerts_count: {
new: 1,
active: 2,
recovered: 3,
ignored: 4,
},
},
next_run: dateUpdated.toISOString(),
};
expect(transformRule(apiRule)).toMatchInlineSnapshot(`
Object {
Expand All @@ -176,12 +287,49 @@ describe('common_transformations', () => {
"status": "error",
},
"id": "some-id",
"lastRun": Object {
"alertsCount": Object {
"active": 2,
"ignored": 4,
"new": 1,
"recovered": 3,
},
"outcome": "failed",
"outcomeMsg": "this is just a test",
"warning": "unknown",
},
"monitoring": Object {
"run": Object {
"calculated_metrics": Object {
"p50": 0,
"p95": 42,
"p99": 42,
"success_ratio": 0,
},
"history": Array [
Object {
"duration": 42,
"outcome": "failed",
"success": false,
"timestamp": 1639571696789,
},
],
"last_run": Object {
"metrics": Object {
"duration": 42,
"total_search_duration_ms": 100,
},
"timestamp": "2021-12-15T12:34:56.789Z",
},
},
},
"muteAll": false,
"mutedInstanceIds": Array [
"bob",
"jim",
],
"name": "some-name",
"nextRun": 2021-12-15T12:34:55.789Z,
"notifyWhen": "onActiveAlert",
"params": Object {},
"schedule": Object {
Expand Down
Loading

0 comments on commit c96c59f

Please sign in to comment.