Skip to content

Commit

Permalink
Instrument vis_type_vislib, lens and vis_type_timeseries with executi…
Browse files Browse the repository at this point in the history
…on context service (#105206) (#106117)

Co-authored-by: Josh Dover <1813008+joshdover@users.noreply.github.com>

Co-authored-by: Mikhail Shustov <restrry@gmail.com>
Co-authored-by: Josh Dover <1813008+joshdover@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 19, 2021
1 parent dde9655 commit 50d6106
Show file tree
Hide file tree
Showing 69 changed files with 357 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export interface IExecutionContextContainer
| Property | Type | Description |
| --- | --- | --- |
| [toHeader](./kibana-plugin-core-public.iexecutioncontextcontainer.toheader.md) | <code>() =&gt; Record&lt;string, string&gt;</code> | |
| [toJSON](./kibana-plugin-core-public.iexecutioncontextcontainer.tojson.md) | <code>() =&gt; Readonly&lt;KibanaExecutionContext&gt;</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [IExecutionContextContainer](./kibana-plugin-core-public.iexecutioncontextcontainer.md) &gt; [toJSON](./kibana-plugin-core-public.iexecutioncontextcontainer.tojson.md)

## IExecutionContextContainer.toJSON property

<b>Signature:</b>

```typescript
toJSON: () => Readonly<KibanaExecutionContext>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## KibanaExecutionContext.id property

unique value to indentify find the source
unique value to identify the source

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface KibanaExecutionContext
| Property | Type | Description |
| --- | --- | --- |
| [description](./kibana-plugin-core-public.kibanaexecutioncontext.description.md) | <code>string</code> | human readable description. For example, a vis title, action name |
| [id](./kibana-plugin-core-public.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to indentify find the source |
| [id](./kibana-plugin-core-public.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to identify the source |
| [name](./kibana-plugin-core-public.kibanaexecutioncontext.name.md) | <code>string</code> | public name of a user-facing feature |
| [type](./kibana-plugin-core-public.kibanaexecutioncontext.type.md) | <code>string</code> | Kibana application initated an operation. Can be narrowed to an enum later. |
| [url](./kibana-plugin-core-public.kibanaexecutioncontext.url.md) | <code>string</code> | in browser - url to navigate to a current page, on server - endpoint path, for task: task SO url |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## KibanaExecutionContext.id property

unique value to indentify find the source
unique value to identify the source

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface KibanaExecutionContext
| Property | Type | Description |
| --- | --- | --- |
| [description](./kibana-plugin-core-server.kibanaexecutioncontext.description.md) | <code>string</code> | human readable description. For example, a vis title, action name |
| [id](./kibana-plugin-core-server.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to indentify find the source |
| [id](./kibana-plugin-core-server.kibanaexecutioncontext.id.md) | <code>string</code> | unique value to identify the source |
| [name](./kibana-plugin-core-server.kibanaexecutioncontext.name.md) | <code>string</code> | public name of a user-facing feature |
| [type](./kibana-plugin-core-server.kibanaexecutioncontext.type.md) | <code>string</code> | Kibana application initated an operation. Can be narrowed to an enum later. |
| [url](./kibana-plugin-core-server.kibanaexecutioncontext.url.md) | <code>string</code> | in browser - url to navigate to a current page, on server - endpoint path, for task: task SO url |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) &gt; [executionContext](./kibana-plugin-plugins-data-public.isearchoptions.executioncontext.md)

## ISearchOptions.executionContext property

<b>Signature:</b>

```typescript
executionContext?: KibanaExecutionContext;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ISearchOptions
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-data-public.isearchoptions.abortsignal.md) | <code>AbortSignal</code> | An <code>AbortSignal</code> that allows the caller of <code>search</code> to abort a search request. |
| [executionContext](./kibana-plugin-plugins-data-public.isearchoptions.executioncontext.md) | <code>KibanaExecutionContext</code> | |
| [indexPattern](./kibana-plugin-plugins-data-public.isearchoptions.indexpattern.md) | <code>IndexPattern</code> | Index pattern reference is used for better error messages |
| [inspector](./kibana-plugin-plugins-data-public.isearchoptions.inspector.md) | <code>IInspectorInfo</code> | Inspector integration options |
| [isRestore](./kibana-plugin-plugins-data-public.isearchoptions.isrestore.md) | <code>boolean</code> | Whether the session is restored (i.e. search requests should re-use the stored search IDs, rather than starting from scratch) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) &gt; [executionContext](./kibana-plugin-plugins-data-server.isearchoptions.executioncontext.md)

## ISearchOptions.executionContext property

<b>Signature:</b>

```typescript
executionContext?: KibanaExecutionContext;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ISearchOptions
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-data-server.isearchoptions.abortsignal.md) | <code>AbortSignal</code> | An <code>AbortSignal</code> that allows the caller of <code>search</code> to abort a search request. |
| [executionContext](./kibana-plugin-plugins-data-server.isearchoptions.executioncontext.md) | <code>KibanaExecutionContext</code> | |
| [indexPattern](./kibana-plugin-plugins-data-server.isearchoptions.indexpattern.md) | <code>IndexPattern</code> | Index pattern reference is used for better error messages |
| [inspector](./kibana-plugin-plugins-data-server.isearchoptions.inspector.md) | <code>IInspectorInfo</code> | Inspector integration options |
| [isRestore](./kibana-plugin-plugins-data-server.isearchoptions.isrestore.md) | <code>boolean</code> | Whether the session is restored (i.e. search requests should re-use the stored search IDs, rather than starting from scratch) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) &gt; [ExecutionContext](./kibana-plugin-plugins-expressions-public.executioncontext.md) &gt; [getExecutionContext](./kibana-plugin-plugins-expressions-public.executioncontext.getexecutioncontext.md)

## ExecutionContext.getExecutionContext property

Contains the meta-data about the source of the expression.

<b>Signature:</b>

```typescript
getExecutionContext: () => IExecutionContextContainer | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ExecutionContext<InspectorAdapters extends Adapters = Adapters,
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-expressions-public.executioncontext.abortsignal.md) | <code>AbortSignal</code> | Adds ability to abort current execution. |
| [getExecutionContext](./kibana-plugin-plugins-expressions-public.executioncontext.getexecutioncontext.md) | <code>() =&gt; IExecutionContextContainer &#124; undefined</code> | Contains the meta-data about the source of the expression. |
| [getKibanaRequest](./kibana-plugin-plugins-expressions-public.executioncontext.getkibanarequest.md) | <code>() =&gt; KibanaRequest</code> | Getter to retrieve the <code>KibanaRequest</code> object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user. |
| [getSearchContext](./kibana-plugin-plugins-expressions-public.executioncontext.getsearchcontext.md) | <code>() =&gt; ExecutionContextSearch</code> | Get search context of the expression. |
| [getSearchSessionId](./kibana-plugin-plugins-expressions-public.executioncontext.getsearchsessionid.md) | <code>() =&gt; string &#124; undefined</code> | Search context in which expression should operate. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) &gt; [IExpressionLoaderParams](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.md) &gt; [executionContext](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.executioncontext.md)

## IExpressionLoaderParams.executionContext property

<b>Signature:</b>

```typescript
executionContext?: IExecutionContextContainer;
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IExpressionLoaderParams
| [customRenderers](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.customrenderers.md) | <code>[]</code> | |
| [debug](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.debug.md) | <code>boolean</code> | |
| [disableCaching](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.disablecaching.md) | <code>boolean</code> | |
| [executionContext](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.executioncontext.md) | <code>IExecutionContextContainer</code> | |
| [hasCompatibleActions](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.hascompatibleactions.md) | <code>ExpressionRenderHandlerParams['hasCompatibleActions']</code> | |
| [inspectorAdapters](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.inspectoradapters.md) | <code>Adapters</code> | |
| [onRenderError](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.onrendererror.md) | <code>RenderErrorHandlerFnType</code> | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) &gt; [ExecutionContext](./kibana-plugin-plugins-expressions-server.executioncontext.md) &gt; [getExecutionContext](./kibana-plugin-plugins-expressions-server.executioncontext.getexecutioncontext.md)

## ExecutionContext.getExecutionContext property

Contains the meta-data about the source of the expression.

<b>Signature:</b>

```typescript
getExecutionContext: () => IExecutionContextContainer | undefined;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ExecutionContext<InspectorAdapters extends Adapters = Adapters,
| Property | Type | Description |
| --- | --- | --- |
| [abortSignal](./kibana-plugin-plugins-expressions-server.executioncontext.abortsignal.md) | <code>AbortSignal</code> | Adds ability to abort current execution. |
| [getExecutionContext](./kibana-plugin-plugins-expressions-server.executioncontext.getexecutioncontext.md) | <code>() =&gt; IExecutionContextContainer &#124; undefined</code> | Contains the meta-data about the source of the expression. |
| [getKibanaRequest](./kibana-plugin-plugins-expressions-server.executioncontext.getkibanarequest.md) | <code>() =&gt; KibanaRequest</code> | Getter to retrieve the <code>KibanaRequest</code> object inside an expression function. Useful for functions which are running on the server and need to perform operations that are scoped to a specific user. |
| [getSearchContext](./kibana-plugin-plugins-expressions-server.executioncontext.getsearchcontext.md) | <code>() =&gt; ExecutionContextSearch</code> | Get search context of the expression. |
| [getSearchSessionId](./kibana-plugin-plugins-expressions-server.executioncontext.getsearchsessionid.md) | <code>() =&gt; string &#124; undefined</code> | Search context in which expression should operate. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function enforceMaxLength(header: string): string {
*/
export interface IExecutionContextContainer {
toHeader: () => Record<string, string>;
toJSON: () => Readonly<KibanaExecutionContext>;
}

export class ExecutionContextContainer implements IExecutionContextContainer {
Expand All @@ -42,7 +43,12 @@ export class ExecutionContextContainer implements IExecutionContextContainer {
// escape content as the description property might contain non-ASCII symbols
return enforceMaxLength(encodeURIComponent(value));
}

toHeader() {
return { [BAGGAGE_HEADER]: this.toString() };
}

toJSON() {
return this.#context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { ExecutionContextContainer } from './execution_context_container';
const createContainerMock = () => {
const mock: jest.Mocked<PublicMethodsOf<ExecutionContextContainer>> = {
toHeader: jest.fn(),
toJSON: jest.fn(),
};
return mock;
};
Expand Down
8 changes: 3 additions & 5 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,14 @@ export type {

export type { DeprecationsServiceStart, ResolveDeprecationResponse } from './deprecations';

export type {
IExecutionContextContainer,
ExecutionContextServiceStart,
KibanaExecutionContext,
} from './execution_context';
export type { IExecutionContextContainer, ExecutionContextServiceStart } from './execution_context';

export type { MountPoint, UnmountCallback, PublicUiSettingsParams } from './types';

export { URL_MAX_LENGTH } from './core_app';

export type { KibanaExecutionContext } from './execution_context';

/**
* Core services exposed to the `Plugin` setup lifecycle
*
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,8 @@ export interface IBasePath {
export interface IExecutionContextContainer {
// (undocumented)
toHeader: () => Record<string, string>;
// (undocumented)
toJSON: () => Readonly<KibanaExecutionContext>;
}

// @public
Expand Down
76 changes: 75 additions & 1 deletion src/core/server/elasticsearch/client/configure_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { Buffer } from 'buffer';
import { Readable } from 'stream';

import { RequestEvent, errors } from '@elastic/elasticsearch';
import { TransportRequestParams, RequestBody } from '@elastic/elasticsearch/lib/Transport';
import type {
TransportRequestOptions,
TransportRequestParams,
RequestBody,
} from '@elastic/elasticsearch/lib/Transport';

import { parseClientOptionsMock, ClientMock } from './configure_client.test.mocks';
import { loggingSystemMock } from '../../logging/logging_system.mock';
Expand Down Expand Up @@ -39,12 +43,14 @@ const createApiResponse = <T>({
headers = {},
warnings = [],
params,
requestOptions = {},
}: {
body: T;
statusCode?: number;
headers?: Record<string, string>;
warnings?: string[];
params?: TransportRequestParams;
requestOptions?: TransportRequestOptions;
}): RequestEvent<T> => {
return {
body,
Expand All @@ -54,6 +60,7 @@ const createApiResponse = <T>({
meta: {
request: {
params: params!,
options: requestOptions,
} as any,
} as any,
};
Expand Down Expand Up @@ -146,6 +153,7 @@ describe('configureClient', () => {
"200
GET /foo?hello=dolly
{\\"seq_no_primary_term\\":true,\\"query\\":{\\"term\\":{\\"user\\":\\"kimchy\\"}}}",
undefined,
],
]
`);
Expand All @@ -170,6 +178,7 @@ describe('configureClient', () => {
"200
GET /foo?hello=dolly
{\\"seq_no_primary_term\\":true,\\"query\\":{\\"term\\":{\\"user\\":\\"kimchy\\"}}}",
undefined,
],
]
`);
Expand All @@ -196,6 +205,7 @@ describe('configureClient', () => {
"200
GET /foo?hello=dolly
[buffer]",
undefined,
],
]
`);
Expand All @@ -222,6 +232,7 @@ describe('configureClient', () => {
"200
GET /foo?hello=dolly
[stream]",
undefined,
],
]
`);
Expand All @@ -238,6 +249,7 @@ describe('configureClient', () => {
Array [
"200
GET /foo?hello=dolly",
undefined,
],
]
`);
Expand All @@ -263,6 +275,7 @@ describe('configureClient', () => {
Array [
"200
GET /foo?city=M%C3%BCnich",
undefined,
],
]
`);
Expand Down Expand Up @@ -298,6 +311,7 @@ describe('configureClient', () => {
"500
GET /foo?hello=dolly
{\\"seq_no_primary_term\\":true,\\"query\\":{\\"term\\":{\\"user\\":\\"kimchy\\"}}} [internal server error]: internal server error",
undefined,
],
]
`);
Expand All @@ -313,6 +327,7 @@ describe('configureClient', () => {
Array [
Array [
"[TimeoutError]: message",
undefined,
],
]
`);
Expand Down Expand Up @@ -343,6 +358,7 @@ describe('configureClient', () => {
Array [
"400
GET /_path?hello=dolly [illegal_argument_exception]: request [/_path] contains unrecognized parameter: [name]",
undefined,
],
]
`);
Expand All @@ -369,6 +385,7 @@ describe('configureClient', () => {
Array [
"400
GET /_path [undefined]: Response Error",
undefined,
],
]
`);
Expand All @@ -391,10 +408,67 @@ describe('configureClient', () => {
Array [
"400
GET /_path [undefined]: Response Error",
undefined,
],
]
`);
});

it('adds meta information to logs', () => {
const client = configureClient(createFakeConfig(), { logger, type: 'test', scoped: false });

let response = createApiResponse({
statusCode: 400,
headers: {},
params: {
method: 'GET',
path: '/_path',
},
requestOptions: {
opaqueId: 'opaque-id',
},
body: {
error: {},
},
});
client.emit('response', null, response);

expect(loggingSystemMock.collect(logger).debug[0][1]).toMatchInlineSnapshot(`
Object {
"http": Object {
"request": Object {
"id": "opaque-id",
},
},
}
`);

logger.debug.mockClear();

response = createApiResponse({
statusCode: 400,
headers: {},
params: {
method: 'GET',
path: '/_path',
},
requestOptions: {
opaqueId: 'opaque-id',
},
body: {} as any,
});
client.emit('response', new errors.ResponseError(response), response);

expect(loggingSystemMock.collect(logger).debug[0][1]).toMatchInlineSnapshot(`
Object {
"http": Object {
"request": Object {
"id": "opaque-id",
},
},
}
`);
});
});
});
});
Loading

0 comments on commit 50d6106

Please sign in to comment.