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

Instrument vis_type_vislib, lens and vis_type_timeseries with execution context service #105206

Merged
merged 28 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e79b36c
export executionContext types
mshustov Jul 5, 2021
9f80622
pass execution context for expressions and bsearch
mshustov Jul 5, 2021
00ae806
instrument lens
mshustov Jul 5, 2021
105bc80
remove duplicated imports
mshustov Jul 8, 2021
36891cd
fix type
mshustov Jul 8, 2021
73e4be0
instrument tsvb
mshustov Jul 8, 2021
70c070e
pass data as container
mshustov Jul 9, 2021
1def5a3
attach request.id to elasticsearch response logs
mshustov Jul 12, 2021
09333ba
emits execution context to the debug logs
mshustov Jul 12, 2021
9cb03e4
update es client test
mshustov Jul 12, 2021
cc41571
attach url to the execution context
mshustov Jul 12, 2021
3bedbb6
update executionContext mock
mshustov Jul 12, 2021
b1efd7f
fix type errors in tests
mshustov Jul 12, 2021
628227d
update docs
mshustov Jul 12, 2021
0fd1909
Merge branch 'master' into inspect-vis
mshustov Jul 13, 2021
7b19c74
encode id when send x-opaque-id header to elasticsearch server
mshustov Jul 13, 2021
b938fbc
Merge branch 'master' into inspect-vis
mshustov Jul 14, 2021
e9e9ca0
add comment and mark readonly
mshustov Jul 14, 2021
e432f3b
remove leftovers of an alternative approach
mshustov Jul 14, 2021
58a3886
update docs
mshustov Jul 14, 2021
944ce6d
Merge branch 'master' into inspect-vis
mshustov Jul 15, 2021
c8f3752
include name in x-opaque-id header
mshustov Jul 15, 2021
6011737
make expressions executionContext getter
mshustov Jul 15, 2021
859caf2
but interface back for ExecutionContext type
mshustov Jul 15, 2021
e0a2ddf
update docs
mshustov Jul 15, 2021
997c63e
Merge remote-tracking branch 'upstream/master' into inspect-vis
joshdover Jul 16, 2021
166a4e1
Update unicode encoding test
joshdover Jul 16, 2021
35c041d
Merge remote-tracking branch 'upstream/master' into inspect-vis
joshdover Jul 19, 2021
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
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 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshustov It looks like the generated docs have lost some comments- can you bring them back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm..it's how our doc generator handles interface conversion into type. Let me see what I can do with it.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the additional type export from the same location needed?


/**
* 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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to update the test instead of refactoring.

],
]
`);
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