Skip to content

Commit

Permalink
Merge branch 'main' into eui/46.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsongl committed Jan 27, 2022
2 parents 65c4911 + 159825a commit 21d1937
Show file tree
Hide file tree
Showing 71 changed files with 550 additions and 315 deletions.
2 changes: 1 addition & 1 deletion docs/user/troubleshooting/trace-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Sometimes the {es} server might be slowed down by the execution of an expensive query. Such queries are logged to {es}'s {ref}/index-modules-slowlog.html#search-slow-log[search slow log] file. But there is a problem: it's impossible to say what triggered a slow search request—a {kib} instance or a user accessing an {es} endpoint directly.
To simplify the investigation of such cases, the search slow log file includes the `x-opaque-id` header, which might provide additional information about a request if it originated from {kib}.

WARNING: At the moment, {kib} can only highlight cases where a slow query originated from a {kib} visualization, *Lens*, *Discover*, or *Alerting*.
WARNING: At the moment, {kib} can only highlight cases where a slow query originated from a {kib} visualization, *Lens*, *Discover*, *Maps*, or *Alerting*.

For example, if a request to {es} was initiated by a Vega visualization on a dashboard, you will see the following in the slow logs:
[source,json]
Expand Down
2 changes: 1 addition & 1 deletion test/common/fixtures/plugins/newsfeed/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { PluginInitializerContext } from 'kibana/public';
import type { PluginInitializerContext } from 'kibana/server';
import { NewsFeedSimulatorPlugin } from './plugin';

export function plugin(initializerContext: PluginInitializerContext) {
Expand Down
3 changes: 1 addition & 2 deletions test/common/fixtures/plugins/newsfeed/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* Side Public License, v 1.
*/

import { CoreSetup, Plugin } from 'kibana/server';
import { PluginInitializerContext } from 'kibana/public';
import type { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/server';

export class NewsFeedSimulatorPlugin implements Plugin {
constructor(private readonly initializerContext: PluginInitializerContext) {}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ describe('enqueueExecution()', () => {
id: uuid.v4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
});
expect(authorization.ensureAuthorized).toHaveBeenCalledWith('execute');
Expand All @@ -1906,6 +1907,7 @@ describe('enqueueExecution()', () => {
id: uuid.v4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
})
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);
Expand All @@ -1922,6 +1924,7 @@ describe('enqueueExecution()', () => {
id: uuid.v4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
});

Expand All @@ -1937,6 +1940,7 @@ describe('enqueueExecution()', () => {
id: uuid.v4(),
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
};
await expect(actionsClient.enqueueExecution(opts)).resolves.toMatchInlineSnapshot(`undefined`);
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/actions/server/create_execute_function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asHttpRequestExecutionSource(request),
});
Expand All @@ -74,6 +75,7 @@ describe('execute()', () => {
{
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
{
Expand Down Expand Up @@ -119,6 +121,7 @@ describe('execute()', () => {
spaceId: 'default',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asHttpRequestExecutionSource(request),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'some-id',
Expand All @@ -134,6 +137,7 @@ describe('execute()', () => {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -196,6 +200,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asSavedObjectExecutionSource(source),
});
Expand All @@ -221,6 +226,7 @@ describe('execute()', () => {
{
actionId: '123',
params: { baz: false },
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
},
{
Expand Down Expand Up @@ -273,6 +279,7 @@ describe('execute()', () => {
spaceId: 'default',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asSavedObjectExecutionSource(source),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'some-id',
Expand Down Expand Up @@ -305,6 +312,7 @@ describe('execute()', () => {
actionId: '123',
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -343,6 +351,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: null,
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down Expand Up @@ -372,6 +381,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: null,
})
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down Expand Up @@ -404,6 +414,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: null,
})
).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`);
Expand Down Expand Up @@ -446,6 +457,7 @@ describe('execute()', () => {
id: '123',
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: null,
});

Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/actions/server/create_execute_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ExecuteOptions extends Pick<ActionExecutorOptions, 'params' | '
id: string;
spaceId: string;
apiKey: string | null;
executionId: string;
relatedSavedObjects?: RelatedSavedObjects;
}

Expand All @@ -45,7 +46,7 @@ export function createExecutionEnqueuerFunction({
}: CreateExecuteFunctionOptions): ExecutionEnqueuer<void> {
return async function execute(
unsecuredSavedObjectsClient: SavedObjectsClientContract,
{ id, params, spaceId, source, apiKey, relatedSavedObjects }: ExecuteOptions
{ id, params, spaceId, source, apiKey, executionId, relatedSavedObjects }: ExecuteOptions
) {
if (!isESOCanEncrypt) {
throw new Error(
Expand Down Expand Up @@ -87,6 +88,7 @@ export function createExecutionEnqueuerFunction({
actionId: id,
params,
apiKey,
executionId,
relatedSavedObjects: relatedSavedObjectWithRefs,
},
{
Expand All @@ -113,7 +115,7 @@ export function createEphemeralExecutionEnqueuerFunction({
}: CreateExecuteFunctionOptions): ExecutionEnqueuer<RunNowResult> {
return async function execute(
unsecuredSavedObjectsClient: SavedObjectsClientContract,
{ id, params, spaceId, source, apiKey }: ExecuteOptions
{ id, params, spaceId, source, apiKey, executionId }: ExecuteOptions
): Promise<RunNowResult> {
const { action } = await getAction(unsecuredSavedObjectsClient, preconfiguredActions, id);
validateCanActionBeUsed(action);
Expand All @@ -131,6 +133,7 @@ export function createEphemeralExecutionEnqueuerFunction({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: params as Record<string, any>,
...(apiKey ? { apiKey } : {}),
...(executionId ? { executionId } : {}),
},
...executionSourceAsSavedObjectReferences(source),
};
Expand Down
47 changes: 44 additions & 3 deletions x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const executeParams = {
params: {
foo: true,
},
executionId: '123abc',
request: {} as KibanaRequest,
};

Expand Down Expand Up @@ -118,6 +119,13 @@ test('successfully executes', async () => {
"kind": "action",
},
"kibana": Object {
"alert": Object {
"rule": Object {
"execution": Object {
"uuid": "123abc",
},
},
},
"saved_objects": Array [
Object {
"id": "1",
Expand All @@ -139,6 +147,13 @@ test('successfully executes', async () => {
"outcome": "success",
},
"kibana": Object {
"alert": Object {
"rule": Object {
"execution": Object {
"uuid": "123abc",
},
},
},
"saved_objects": Array [
Object {
"id": "1",
Expand Down Expand Up @@ -518,15 +533,24 @@ test('writes to event log for execute timeout', async () => {

await actionExecutor.logCancellation({
actionId: 'action1',
executionId: '123abc',
relatedSavedObjects: [],
request: {} as KibanaRequest,
});
expect(eventLogger.logEvent).toHaveBeenCalledTimes(1);
expect(eventLogger.logEvent.mock.calls[0][0]).toMatchObject({
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
event: {
action: 'execute-timeout',
kind: 'action',
},
kibana: {
alert: {
rule: {
execution: {
uuid: '123abc',
},
},
},
saved_objects: [
{
rel: 'primary',
Expand All @@ -549,11 +573,19 @@ test('writes to event log for execute and execute start', async () => {
});
await actionExecutor.execute(executeParams);
expect(eventLogger.logEvent).toHaveBeenCalledTimes(2);
expect(eventLogger.logEvent.mock.calls[0][0]).toMatchObject({
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(1, {
event: {
action: 'execute-start',
kind: 'action',
},
kibana: {
alert: {
rule: {
execution: {
uuid: '123abc',
},
},
},
saved_objects: [
{
rel: 'primary',
Expand All @@ -566,11 +598,20 @@ test('writes to event log for execute and execute start', async () => {
},
message: 'action started: test:1: action-1',
});
expect(eventLogger.logEvent.mock.calls[1][0]).toMatchObject({
expect(eventLogger.logEvent).toHaveBeenNthCalledWith(2, {
event: {
action: 'execute',
kind: 'action',
outcome: 'success',
},
kibana: {
alert: {
rule: {
execution: {
uuid: '123abc',
},
},
},
saved_objects: [
{
rel: 'primary',
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ExecuteOptions<Source = unknown> {
params: Record<string, unknown>;
source?: ActionExecutionSource<Source>;
taskInfo?: TaskInfo;
executionId?: string;
relatedSavedObjects?: RelatedSavedObjects;
}

Expand Down Expand Up @@ -90,6 +91,7 @@ export class ActionExecutor {
source,
isEphemeral,
taskInfo,
executionId,
relatedSavedObjects,
}: ExecuteOptions): Promise<ActionTypeExecutorResult<unknown>> {
if (!this.isInitialized) {
Expand Down Expand Up @@ -187,6 +189,7 @@ export class ActionExecutor {
action: EVENT_LOG_ACTIONS.execute,
...namespace,
...task,
executionId,
savedObjects: [
{
type: 'action',
Expand Down Expand Up @@ -283,11 +286,13 @@ export class ActionExecutor {
request,
relatedSavedObjects,
source,
executionId,
taskInfo,
}: {
actionId: string;
request: KibanaRequest;
taskInfo?: TaskInfo;
executionId?: string;
relatedSavedObjects: RelatedSavedObjects;
source?: ActionExecutionSource<Source>;
}) {
Expand Down Expand Up @@ -327,6 +332,7 @@ export class ActionExecutor {
}' execution cancelled due to timeout - exceeded default timeout of "5m"`,
...namespace,
...task,
executionId,
savedObjects: [
{
type: 'action',
Expand Down
Loading

0 comments on commit 21d1937

Please sign in to comment.