Skip to content

Commit

Permalink
[data.search] Add search session methods to search service contract (#…
Browse files Browse the repository at this point in the history
…87966) (#90187)

* [data.search] Add search session methods to search service contract

* Fix types

* Fix tests and switch to cancel

* Update docs

* Fix types/tests

* Fix tests

* Update status of SO before cancelling search requests

* Add API integration test

* Fix types

* Update expiration route to use config defaultExpiration

* Fix test

* Update docs

* New logic for extend

* Remove declare module

* Review feedback

* fix ts

* Remove test that is no longer valid

* Fix undefined bug

* Use DataRequestHandlerContext in maps

* ts

Co-authored-by: Liza K <liza.katz@elastic.co>

Co-authored-by: Liza K <liza.katz@elastic.co>
  • Loading branch information
lukasolson and Liza K authored Feb 3, 2021
1 parent 7f849bd commit 25415a3
Show file tree
Hide file tree
Showing 48 changed files with 617 additions and 680 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

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; [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md) &gt; [asScopedProvider](./kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md)

## ISearchSessionService.asScopedProvider property

<b>Signature:</b>

```typescript
asScopedProvider: (core: CoreStart) => (request: KibanaRequest) => IScopedSearchSessionsClient<T>;
```
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; [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md)

## ISearchSessionService interface

<b>Signature:</b>

```typescript
export interface ISearchSessionService<T = unknown>
```

## Properties

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
asScoped: (request: KibanaRequest) => ISearchClient;
asScoped: (request: KibanaRequest) => IScopedSearchClient;
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ISearchStart<SearchStrategyRequest extends IKibanaSearchRequest
| Property | Type | Description |
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-server.isearchstart.aggs.md) | <code>AggsStart</code> | |
| [asScoped](./kibana-plugin-plugins-data-server.isearchstart.asscoped.md) | <code>(request: KibanaRequest) =&gt; ISearchClient</code> | |
| [asScoped](./kibana-plugin-plugins-data-server.isearchstart.asscoped.md) | <code>(request: KibanaRequest) =&gt; IScopedSearchClient</code> | |
| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | <code>(name?: string) =&gt; ISearchStrategy&lt;SearchStrategyRequest, SearchStrategyResponse&gt;</code> | Get other registered search strategies by name (or, by default, the Elasticsearch strategy). For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. |
| [searchSource](./kibana-plugin-plugins-data-server.isearchstart.searchsource.md) | <code>{</code><br/><code> asScoped: (request: KibanaRequest) =&gt; Promise&lt;ISearchStartSearchSource&gt;;</code><br/><code> }</code> | |

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
| [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 search session service. |

## Enumerations

Expand Down Expand Up @@ -45,20 +44,18 @@
| --- | --- |
| [AggFunctionsMapping](./kibana-plugin-plugins-data-server.aggfunctionsmapping.md) | A global list of the expression function definitions for each agg type function. |
| [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) | |
| [DataApiRequestHandlerContext](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md) | |
| [EsQueryConfig](./kibana-plugin-plugins-data-server.esqueryconfig.md) | |
| [FieldDescriptor](./kibana-plugin-plugins-data-server.fielddescriptor.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-server.fieldformatconfig.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-server.iessearchrequest.md) | |
| [IFieldSubType](./kibana-plugin-plugins-data-server.ifieldsubtype.md) | |
| [IFieldType](./kibana-plugin-plugins-data-server.ifieldtype.md) | |
| [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) | Interface for an index pattern saved object |
| [IScopedSessionService](./kibana-plugin-plugins-data-server.iscopedsessionservice.md) | |
| [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) | |
| [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md) | |
| [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 Expand Up @@ -110,5 +107,6 @@
| [KibanaContext](./kibana-plugin-plugins-data-server.kibanacontext.md) | |
| [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | |
| [Query](./kibana-plugin-plugins-data-server.query.md) | |
| [SearchRequestHandlerContext](./kibana-plugin-plugins-data-server.searchrequesthandlercontext.md) | |
| [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | |

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; [SearchRequestHandlerContext](./kibana-plugin-plugins-data-server.searchrequesthandlercontext.md)

## SearchRequestHandlerContext type

<b>Signature:</b>

```typescript
export declare type SearchRequestHandlerContext = IScopedSearchClient;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface SearchStrategyDependencies
| --- | --- | --- |
| [esClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.esclient.md) | <code>IScopedClusterClient</code> | |
| [savedObjectsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.savedobjectsclient.md) | <code>SavedObjectsClientContract</code> | |
| [searchSessionsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md) | <code>IScopedSearchSessionsClient</code> | |
| [uiSettingsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.uisettingsclient.md) | <code>IUiSettingsClient</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-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [SearchStrategyDependencies](./kibana-plugin-plugins-data-server.searchstrategydependencies.md) &gt; [searchSessionsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md)

## SearchStrategyDependencies.searchSessionsClient property

<b>Signature:</b>

```typescript
searchSessionsClient: IScopedSearchSessionsClient;
```

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 2 additions & 5 deletions examples/search_examples/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import type {
CoreStart,
Plugin,
Logger,
RequestHandlerContext,
} from 'src/core/server';

import type { DataApiRequestHandlerContext } from 'src/plugins/data/server';
import type { DataRequestHandlerContext } from 'src/plugins/data/server';

import {
SearchExamplesPluginSetup,
Expand Down Expand Up @@ -45,9 +44,7 @@ export class SearchExamplesPlugin
deps: SearchExamplesPluginSetupDeps
) {
this.logger.debug('search_examples: Setup');
const router = core.http.createRouter<
RequestHandlerContext & { search: DataApiRequestHandlerContext }
>();
const router = core.http.createRouter<DataRequestHandlerContext>();

core.getStartServices().then(([_, depsStart]) => {
const myStrategy = mySearchStrategyProvider(depsStart.data);
Expand Down
8 changes: 3 additions & 5 deletions examples/search_examples/server/routes/register_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
* Public License, v 1.
*/

import type { IRouter, RequestHandlerContext } from 'kibana/server';
import { DataApiRequestHandlerContext } from 'src/plugins/data/server';
import type { IRouter } from 'kibana/server';
import { DataRequestHandlerContext } from 'src/plugins/data/server';
import { registerServerSearchRoute } from './server_search_route';

export function registerRoutes(
router: IRouter<RequestHandlerContext & { search: DataApiRequestHandlerContext }>
) {
export function registerRoutes(router: IRouter<DataRequestHandlerContext>) {
registerServerSearchRoute(router);
}
8 changes: 3 additions & 5 deletions examples/search_examples/server/routes/server_search_route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import { IEsSearchRequest } from 'src/plugins/data/server';
import { schema } from '@kbn/config-schema';
import { IEsSearchResponse } from 'src/plugins/data/common';
import type { DataApiRequestHandlerContext } from 'src/plugins/data/server';
import type { IRouter, RequestHandlerContext } from 'src/core/server';
import type { DataRequestHandlerContext } from 'src/plugins/data/server';
import type { IRouter } from 'src/core/server';
import { SERVER_SEARCH_ROUTE_PATH } from '../../common';

export function registerServerSearchRoute(
router: IRouter<RequestHandlerContext & { search: DataApiRequestHandlerContext }>
) {
export function registerServerSearchRoute(router: IRouter<DataRequestHandlerContext>) {
router.get(
{
path: SERVER_SEARCH_ROUTE_PATH,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/session/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function getSessionsClientMock(): jest.Mocked<ISessionsClient> {
create: jest.fn(),
find: jest.fn(),
update: jest.fn(),
extend: jest.fn(),
delete: jest.fn(),
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/data/public/search/session/sessions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export class SessionsClient {
});
}

public extend(sessionId: string, keepAlive: string): Promise<SavedObjectsFindResponse> {
return this.http!.post(`/internal/session/${encodeURIComponent(sessionId)}/_extend`, {
body: JSON.stringify({ keepAlive }),
});
}

public delete(sessionId: string): Promise<void> {
return this.http!.delete(`/internal/session/${encodeURIComponent(sessionId)}`);
}
Expand Down
7 changes: 3 additions & 4 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ export {
searchUsageObserver,
shimAbortSignal,
SearchUsage,
SessionService,
ISessionService,
IScopedSessionService,
DataApiRequestHandlerContext,
SearchSessionService,
ISearchSessionService,
SearchRequestHandlerContext,
DataRequestHandlerContext,
} from './search';

Expand Down
Loading

0 comments on commit 25415a3

Please sign in to comment.