Skip to content

Commit a9d2f32

Browse files
Merge branch 'master' into telemetry/rename-in-other-plugins-to-usage/task-names-in-taskManager
2 parents 470f3ba + c03c7b3 commit a9d2f32

77 files changed

Lines changed: 2839 additions & 1077 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
"babel-eslint": "^10.0.3",
351351
"babel-jest": "^25.5.1",
352352
"babel-plugin-istanbul": "^6.0.0",
353-
"backport": "5.5.1",
353+
"backport": "5.6.0",
354354
"brace": "0.11.1",
355355
"chai": "3.5.0",
356356
"chance": "1.0.18",

x-pack/plugins/actions/common/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ export interface ActionResult {
2424
config: Record<string, any>;
2525
isPreconfigured: boolean;
2626
}
27+
28+
// the result returned from an action type executor function
29+
export interface ActionTypeExecutorResult<Data> {
30+
actionId: string;
31+
status: 'ok' | 'error';
32+
message?: string;
33+
serviceMessage?: string;
34+
data?: Data;
35+
retry?: null | boolean | Date;
36+
}

x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,47 @@ describe('execute()', () => {
284284
]
285285
`);
286286
});
287+
288+
test('resolves with an error when an error occurs in the indexing operation', async () => {
289+
const secrets = {};
290+
// minimal params
291+
const config = { index: 'index-value', refresh: false, executionTimeField: null };
292+
const params = {
293+
documents: [{ '': 'bob' }],
294+
};
295+
296+
const actionId = 'some-id';
297+
298+
services.callCluster.mockResolvedValue({
299+
took: 0,
300+
errors: true,
301+
items: [
302+
{
303+
index: {
304+
_index: 'indexme',
305+
_id: '7buTjHQB0SuNSiS9Hayt',
306+
status: 400,
307+
error: {
308+
type: 'mapper_parsing_exception',
309+
reason: 'failed to parse',
310+
caused_by: {
311+
type: 'illegal_argument_exception',
312+
reason: 'field name cannot be an empty string',
313+
},
314+
},
315+
},
316+
},
317+
],
318+
});
319+
320+
expect(await actionType.executor({ actionId, config, secrets, params, services }))
321+
.toMatchInlineSnapshot(`
322+
Object {
323+
"actionId": "some-id",
324+
"message": "error indexing documents",
325+
"serviceMessage": "failed to parse (field name cannot be an empty string)",
326+
"status": "error",
327+
}
328+
`);
329+
});
287330
});

x-pack/plugins/actions/server/builtin_action_types/es_index.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { curry } from 'lodash';
7+
import { curry, find } from 'lodash';
88
import { i18n } from '@kbn/i18n';
99
import { schema, TypeOf } from '@kbn/config-schema';
1010

@@ -85,21 +85,39 @@ async function executor(
8585
refresh: config.refresh,
8686
};
8787

88-
let result;
8988
try {
90-
result = await services.callCluster('bulk', bulkParams);
89+
const result = await services.callCluster('bulk', bulkParams);
90+
91+
const err = find(result.items, 'index.error.reason');
92+
if (err) {
93+
return wrapErr(
94+
`${err.index.error!.reason}${
95+
err.index.error?.caused_by ? ` (${err.index.error?.caused_by?.reason})` : ''
96+
}`,
97+
actionId,
98+
logger
99+
);
100+
}
101+
102+
return { status: 'ok', data: result, actionId };
91103
} catch (err) {
92-
const message = i18n.translate('xpack.actions.builtin.esIndex.errorIndexingErrorMessage', {
93-
defaultMessage: 'error indexing documents',
94-
});
95-
logger.error(`error indexing documents: ${err.message}`);
96-
return {
97-
status: 'error',
98-
actionId,
99-
message,
100-
serviceMessage: err.message,
101-
};
104+
return wrapErr(err.message, actionId, logger);
102105
}
106+
}
103107

104-
return { status: 'ok', data: result, actionId };
108+
function wrapErr(
109+
errMessage: string,
110+
actionId: string,
111+
logger: Logger
112+
): ActionTypeExecutorResult<unknown> {
113+
const message = i18n.translate('xpack.actions.builtin.esIndex.errorIndexingErrorMessage', {
114+
defaultMessage: 'error indexing documents',
115+
});
116+
logger.error(`error indexing documents: ${errMessage}`);
117+
return {
118+
status: 'error',
119+
actionId,
120+
message,
121+
serviceMessage: errMessage,
122+
};
105123
}

x-pack/plugins/actions/server/types.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
SavedObjectsClientContract,
1616
SavedObjectAttributes,
1717
} from '../../../../src/core/server';
18+
import { ActionTypeExecutorResult } from '../common';
19+
export { ActionTypeExecutorResult } from '../common';
1820

1921
export type WithoutQueryAndParams<T> = Pick<T, Exclude<keyof T, 'query' | 'params'>>;
2022
export type GetServicesFunction = (request: KibanaRequest) => Services;
@@ -80,16 +82,6 @@ export interface FindActionResult extends ActionResult {
8082
referencedByCount: number;
8183
}
8284

83-
// the result returned from an action type executor function
84-
export interface ActionTypeExecutorResult<Data> {
85-
actionId: string;
86-
status: 'ok' | 'error';
87-
message?: string;
88-
serviceMessage?: string;
89-
data?: Data;
90-
retry?: null | boolean | Date;
91-
}
92-
9385
// signature of the action type executor function
9486
export type ExecutorType<Config, Secrets, Params, ResultData> = (
9587
options: ActionTypeExecutorOptions<Config, Secrets, Params>

x-pack/plugins/security_solution/common/search_strategy/security_solution/hosts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './authentications';
99
export * from './common';
1010
export * from './details';
1111
export * from './first_last_seen';
12+
export * from './kpi';
1213
export * from './overview';
1314
export * from './uncommon_processes';
1415

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common';
8+
import { Inspect, Maybe } from '../../../../common';
9+
import { RequestBasicOptions } from '../../..';
10+
import { HostsKpiHistogramData } from '../common';
11+
12+
export interface HostsKpiAuthenticationsHistogramCount {
13+
doc_count: number;
14+
}
15+
16+
export type HostsKpiAuthenticationsRequestOptions = RequestBasicOptions;
17+
18+
export interface HostsKpiAuthenticationsStrategyResponse extends IEsSearchResponse {
19+
authenticationsSuccess: Maybe<number>;
20+
authenticationsSuccessHistogram: Maybe<HostsKpiHistogramData[]>;
21+
authenticationsFailure: Maybe<number>;
22+
authenticationsFailureHistogram: Maybe<HostsKpiHistogramData[]>;
23+
inspect?: Maybe<Inspect>;
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
/*
8+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
9+
* or more contributor license agreements. Licensed under the Elastic License;
10+
* you may not use this file except in compliance with the Elastic License.
11+
*/
12+
13+
import { Maybe } from '../../../../common';
14+
15+
export interface HostsKpiHistogramData {
16+
x?: Maybe<number>;
17+
y?: Maybe<number>;
18+
}
19+
20+
export interface HostsKpiHistogram<T> {
21+
key_as_string: string;
22+
key: number;
23+
doc_count: number;
24+
count: T;
25+
}
26+
27+
export interface HostsKpiGeneralHistogramCount {
28+
value: number;
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common';
8+
import { Inspect, Maybe } from '../../../../common';
9+
import { RequestBasicOptions } from '../../..';
10+
import { HostsKpiHistogramData } from '../common';
11+
12+
export type HostsKpiHostsRequestOptions = RequestBasicOptions;
13+
14+
export interface HostsKpiHostsStrategyResponse extends IEsSearchResponse {
15+
hosts: Maybe<number>;
16+
hostsHistogram: Maybe<HostsKpiHistogramData[]>;
17+
inspect?: Maybe<Inspect>;
18+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export * from './authentications';
8+
export * from './common';
9+
export * from './hosts';
10+
export * from './unique_ips';
11+
12+
import { HostsKpiAuthenticationsStrategyResponse } from './authentications';
13+
import { HostsKpiHostsStrategyResponse } from './hosts';
14+
import { HostsKpiUniqueIpsStrategyResponse } from './unique_ips';
15+
16+
export enum HostsKpiQueries {
17+
kpiAuthentications = 'hostsKpiAuthentications',
18+
kpiHosts = 'hostsKpiHosts',
19+
kpiUniqueIps = 'hostsKpiUniqueIps',
20+
}
21+
22+
export type HostsKpiStrategyResponse =
23+
| Omit<HostsKpiAuthenticationsStrategyResponse, 'rawResponse'>
24+
| Omit<HostsKpiHostsStrategyResponse, 'rawResponse'>
25+
| Omit<HostsKpiUniqueIpsStrategyResponse, 'rawResponse'>;

0 commit comments

Comments
 (0)