Skip to content

Commit

Permalink
[data.search] Move background session service to data enhanced plugin (
Browse files Browse the repository at this point in the history
…#84837) (#85152)

* [data.search] Move search method inside session service and add tests

* Move background session service to data_enhanced plugin

* Fix types

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
lukasolson and kibanamachine authored Dec 7, 2020
1 parent 25f6174 commit a821cff
Show file tree
Hide file tree
Showing 44 changed files with 944 additions and 783 deletions.
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; [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md) &gt; [asScopedProvider](./kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md)

## ISessionService.asScopedProvider property

<b>Signature:</b>

```typescript
asScopedProvider: (core: CoreStart) => (request: KibanaRequest) => IScopedSessionService;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- 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; [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md)

## ISessionService interface

<b>Signature:</b>

```typescript
export interface ISessionService
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [asScopedProvider](./kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md) | <code>(core: CoreStart) =&gt; (request: KibanaRequest) =&gt; IScopedSessionService</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
| [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) | |
| [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) | |
| [Plugin](./kibana-plugin-plugins-data-server.plugin.md) | |
| [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) | The OSS session service. See data\_enhanced in X-Pack for the background session service. |

## Enumerations

Expand Down Expand Up @@ -54,6 +55,7 @@
| [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) | |
| [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) | |
| [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) | Search strategy interface contains a search method that takes in a request and returns a promise that resolves to a response. |
| [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md) | |
| [KueryNode](./kibana-plugin-plugins-data-server.kuerynode.md) | |
| [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) | |
| [PluginSetup](./kibana-plugin-plugins-data-server.pluginsetup.md) | |
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-data-server](./kibana-plugin-plugins-data-server.md) &gt; [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) &gt; [(constructor)](./kibana-plugin-plugins-data-server.sessionservice._constructor_.md)

## SessionService.(constructor)

Constructs a new instance of the `SessionService` class

<b>Signature:</b>

```typescript
constructor();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- 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; [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) &gt; [asScopedProvider](./kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md)

## SessionService.asScopedProvider() method

<b>Signature:</b>

```typescript
asScopedProvider(core: CoreStart): (request: KibanaRequest) => {
search: <Request_1 extends IKibanaSearchRequest<any>, Response_1 extends IKibanaSearchResponse<any>>(strategy: ISearchStrategy<Request_1, Response_1>, request: Request_1, options: import("../../../common").ISearchOptions, deps: import("../types").SearchStrategyDependencies) => import("rxjs").Observable<Response_1>;
};
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| core | <code>CoreStart</code> | |

<b>Returns:</b>

`(request: KibanaRequest) => {
search: <Request_1 extends IKibanaSearchRequest<any>, Response_1 extends IKibanaSearchResponse<any>>(strategy: ISearchStrategy<Request_1, Response_1>, request: Request_1, options: import("../../../common").ISearchOptions, deps: import("../types").SearchStrategyDependencies) => import("rxjs").Observable<Response_1>;
}`

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- 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; [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md)

## SessionService class

The OSS session service. See data\_enhanced in X-Pack for the background session service.

<b>Signature:</b>

```typescript
export declare class SessionService implements ISessionService
```
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)()](./kibana-plugin-plugins-data-server.sessionservice._constructor_.md) | | Constructs a new instance of the <code>SessionService</code> class |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [asScopedProvider(core)](./kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md) | | |
| [search(strategy, args)](./kibana-plugin-plugins-data-server.sessionservice.search.md) | | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- 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; [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) &gt; [search](./kibana-plugin-plugins-data-server.sessionservice.search.md)

## SessionService.search() method

<b>Signature:</b>

```typescript
search<Request extends IKibanaSearchRequest, Response extends IKibanaSearchResponse>(strategy: ISearchStrategy<Request, Response>, ...args: Parameters<ISearchStrategy<Request, Response>['search']>): import("rxjs").Observable<Response>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| strategy | <code>ISearchStrategy&lt;Request, Response&gt;</code> | |
| args | <code>Parameters&lt;ISearchStrategy&lt;Request, Response&gt;['search']&gt;</code> | |
<b>Returns:</b>
`import("rxjs").Observable<Response>`
1 change: 0 additions & 1 deletion src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export * from './expressions';
export * from './search_source';
export * from './tabify';
export * from './types';
export * from './session';
export * from './utils';
21 changes: 0 additions & 21 deletions src/plugins/data/common/search/session/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/plugins/data/common/search/session/status.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { SavedObject } from 'kibana/server';
import { SavedObject as SavedObject_2 } from 'src/core/server';
import { SavedObjectReference } from 'src/core/types';
import { SavedObjectsClientContract } from 'src/core/public';
import { SavedObjectsFindOptions } from 'kibana/public';
import { SavedObjectsFindResponse } from 'kibana/server';
import { Search } from '@elastic/elasticsearch/api/requestParams';
import { SearchResponse } from 'elasticsearch';
Expand Down
16 changes: 5 additions & 11 deletions src/plugins/data/public/search/session/sessions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/

import { PublicContract } from '@kbn/utility-types';
import { HttpSetup } from 'kibana/public';
import { HttpSetup, SavedObjectsFindOptions } from 'kibana/public';
import type { SavedObject, SavedObjectsFindResponse } from 'kibana/server';
import { BackgroundSessionSavedObjectAttributes, SearchSessionFindOptions } from '../../../common';

export type ISessionsClient = PublicContract<SessionsClient>;
export interface SessionsClientDeps {
Expand All @@ -37,7 +36,7 @@ export class SessionsClient {
this.http = deps.http;
}

public get(sessionId: string): Promise<SavedObject<BackgroundSessionSavedObjectAttributes>> {
public get(sessionId: string): Promise<SavedObject> {
return this.http.get(`/internal/session/${encodeURIComponent(sessionId)}`);
}

Expand All @@ -55,7 +54,7 @@ export class SessionsClient {
restoreState: Record<string, unknown>;
urlGeneratorId: string;
sessionId: string;
}): Promise<SavedObject<BackgroundSessionSavedObjectAttributes>> {
}): Promise<SavedObject> {
return this.http.post(`/internal/session`, {
body: JSON.stringify({
name,
Expand All @@ -68,18 +67,13 @@ export class SessionsClient {
});
}

public find(
options: SearchSessionFindOptions
): Promise<SavedObjectsFindResponse<BackgroundSessionSavedObjectAttributes>> {
public find(options: SavedObjectsFindOptions): Promise<SavedObjectsFindResponse> {
return this.http!.post(`/internal/session`, {
body: JSON.stringify(options),
});
}

public update(
sessionId: string,
attributes: Partial<BackgroundSessionSavedObjectAttributes>
): Promise<SavedObject<BackgroundSessionSavedObjectAttributes>> {
public update(sessionId: string, attributes: unknown): Promise<SavedObject> {
return this.http!.put(`/internal/session/${encodeURIComponent(sessionId)}`, {
body: JSON.stringify(attributes),
});
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export {
searchUsageObserver,
shimAbortSignal,
SearchUsage,
SessionService,
ISessionService,
} from './search';

// Search namespace
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ export { querySavedObjectType } from './query';
export { indexPatternSavedObjectType } from './index_patterns';
export { kqlTelemetry } from './kql_telemetry';
export { searchTelemetry } from './search_telemetry';
export { BACKGROUND_SESSION_TYPE, backgroundSessionMapping } from './background_session';
1 change: 1 addition & 0 deletions src/plugins/data/server/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './es_search';
export { usageProvider, SearchUsage, searchUsageObserver } from './collectors';
export * from './aggs';
export { shimHitsTotal } from './routes';
export * from './session';
21 changes: 0 additions & 21 deletions src/plugins/data/server/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import type { RequestHandlerContext } from 'src/core/server';
import { coreMock } from '../../../../core/server/mocks';
import { ISearchSetup, ISearchStart } from './types';
import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks';
import { searchSourceMock } from './search_source/mocks';
Expand All @@ -42,22 +40,3 @@ export function createSearchStartMock(): jest.Mocked<ISearchStart> {
searchSource: searchSourceMock.createStartContract(),
};
}

export function createSearchRequestHandlerContext(): jest.Mocked<RequestHandlerContext> {
return {
core: coreMock.createRequestHandlerContext(),
search: {
search: jest.fn(),
cancel: jest.fn(),
session: {
save: jest.fn(),
get: jest.fn(),
find: jest.fn(),
update: jest.fn(),
delete: jest.fn(),
trackId: jest.fn(),
getId: jest.fn(),
},
},
};
}
Loading

0 comments on commit a821cff

Please sign in to comment.