Skip to content

Commit

Permalink
[Search] Add a new advanced setting searchTimeout (#75728) (#77011)
Browse files Browse the repository at this point in the history
* Add new x-pack advanced setting searchTimeout and use it in the EnhancedSearchInterceptor

* docs

* Rely on server timeout in OSS (?)
Use UI setting in xpack.

* Rename function

* doc

* Remove esShard from client

* cleanup request parameters from FE

* doc

* doc

* Align request parameters on server,
Remove leftover parameters from client
Shim responses for search and msearch routes

* docs
Stop using toSnakeCase
Updates jest tests

* add management docs

* docs

* Remove import

* Break circular dep + fix msearch test

* Remove deleted type

* Fix jest

* Bring toSnakeCase back

* docs

* fix jest

* Fix merge

* Fix types

* Allow timeout to be undefined

* Fix jest test

* Upldate docs

* Fix msearch jest

* docs

* Fix rollup search merge

* docs

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	src/legacy/core_plugins/elasticsearch/index.js
  • Loading branch information
lizozom committed Sep 9, 2020
1 parent 445920f commit ba150f7
Show file tree
Hide file tree
Showing 60 changed files with 539 additions and 443 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

```typescript
export declare function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
esShardTimeout: number;
getConfig: GetConfigFn;
}): ISearchRequestParams;
```
Expand All @@ -19,7 +18,7 @@ export declare function getSearchParamsFromRequest(searchRequest: SearchRequest,
| Parameter | Type | Description |
| --- | --- | --- |
| searchRequest | <code>SearchRequest</code> | |
| dependencies | <code>{</code><br/><code> esShardTimeout: number;</code><br/><code> getConfig: GetConfigFn;</code><br/><code>}</code> | |
| dependencies | <code>{</code><br/><code> getConfig: GetConfigFn;</code><br/><code>}</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

## SearchInterceptor.(constructor)

This class should be instantiated with a `requestTimeout` corresponding with how many ms after requests are initiated that they should automatically cancel.
Constructs a new instance of the `SearchInterceptor` class

<b>Signature:</b>

```typescript
constructor(deps: SearchInterceptorDeps, requestTimeout?: number | undefined);
constructor(deps: SearchInterceptorDeps);
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| deps | <code>SearchInterceptorDeps</code> | |
| requestTimeout | <code>number &#124; undefined</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ export declare class SearchInterceptor

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(deps, requestTimeout)](./kibana-plugin-plugins-data-public.searchinterceptor._constructor_.md) | | This class should be instantiated with a <code>requestTimeout</code> corresponding with how many ms after requests are initiated that they should automatically cancel. |
| [(constructor)(deps)](./kibana-plugin-plugins-data-public.searchinterceptor._constructor_.md) | | Constructs a new instance of the <code>SearchInterceptor</code> class |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [deps](./kibana-plugin-plugins-data-public.searchinterceptor.deps.md) | | <code>SearchInterceptorDeps</code> | |
| [requestTimeout](./kibana-plugin-plugins-data-public.searchinterceptor.requesttimeout.md) | | <code>number &#124; undefined</code> | |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [getPendingCount$()](./kibana-plugin-plugins-data-public.searchinterceptor.getpendingcount_.md) | | Returns an <code>Observable</code> over the current number of pending searches. This could mean that one of the search requests is still in flight, or that it has only received partial responses. |
| [runSearch(request, signal, strategy)](./kibana-plugin-plugins-data-public.searchinterceptor.runsearch.md) | | |
| [search(request, options)](./kibana-plugin-plugins-data-public.searchinterceptor.search.md) | | Searches using the given <code>search</code> method. Overrides the <code>AbortSignal</code> with one that will abort either when <code>cancelPending</code> is called, when the request times out, or when the original <code>AbortSignal</code> is aborted. Updates <code>pendingCount$</code> when the request is started/finalized. |
| [setupTimers(options)](./kibana-plugin-plugins-data-public.searchinterceptor.setuptimers.md) | | |

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ UI_SETTINGS: {
readonly COURIER_MAX_CONCURRENT_SHARD_REQUESTS: "courier:maxConcurrentShardRequests";
readonly COURIER_BATCH_SEARCHES: "courier:batchSearches";
readonly SEARCH_INCLUDE_FROZEN: "search:includeFrozen";
readonly SEARCH_TIMEOUT: "search:timeout";
readonly HISTOGRAM_BAR_TARGET: "histogram:barTarget";
readonly HISTOGRAM_MAX_BARS: "histogram:maxBars";
readonly HISTORY_LIMIT: "history:limit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,26 @@
<b>Signature:</b>

```typescript
export declare function getDefaultSearchParams(config: SharedGlobalConfig): {
timeout: string;
export declare function getDefaultSearchParams(uiSettingsClient: IUiSettingsClient): Promise<{
maxConcurrentShardRequests: number | undefined;
ignoreThrottled: boolean;
ignoreUnavailable: boolean;
restTotalHitsAsInt: boolean;
};
trackTotalHits: boolean;
}>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| config | <code>SharedGlobalConfig</code> | |
| uiSettingsClient | <code>IUiSettingsClient</code> | |

<b>Returns:</b>

`{
timeout: string;
`Promise<{
maxConcurrentShardRequests: number | undefined;
ignoreThrottled: boolean;
ignoreUnavailable: boolean;
restTotalHitsAsInt: boolean;
}`
trackTotalHits: boolean;
}>`

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

## getShardTimeout() function

<b>Signature:</b>

```typescript
export declare function getShardTimeout(config: SharedGlobalConfig): {
timeout: string;
} | {
timeout?: undefined;
};
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| config | <code>SharedGlobalConfig</code> | |

<b>Returns:</b>

`{
timeout: string;
} | {
timeout?: undefined;
}`

Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

| Function | Description |
| --- | --- |
| [getDefaultSearchParams(config)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | |
| [getTime(indexPattern, timeRange, options)](./kibana-plugin-plugins-data-server.gettime.md) | |
| [parseInterval(interval)](./kibana-plugin-plugins-data-server.parseinterval.md) | |
| [plugin(initializerContext)](./kibana-plugin-plugins-data-server.plugin.md) | Static code to be shared externally |
| [shouldReadFieldFromDocValues(aggregatable, esType)](./kibana-plugin-plugins-data-server.shouldreadfieldfromdocvalues.md) | |
| [toSnakeCase(obj)](./kibana-plugin-plugins-data-server.tosnakecase.md) | |
| [usageProvider(core)](./kibana-plugin-plugins-data-server.usageprovider.md) | |

## Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```typescript
start(core: CoreStart): {
search: ISearchStart<import(".").IEsSearchRequest, import(".").IEsSearchResponse<any>>;
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
Expand All @@ -27,7 +27,7 @@ start(core: CoreStart): {
<b>Returns:</b>

`{
search: ISearchStart<import(".").IEsSearchRequest, import(".").IEsSearchResponse<any>>;
search: ISearchStart<import("./search").IEsSearchRequest, import("./search").IEsSearchResponse<any>>;
fieldFormats: {
fieldFormatServiceFactory: (uiSettings: import("../../../core/server").IUiSettingsClient) => Promise<import("../common").FieldFormatsRegistry>;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- 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; [toSnakeCase](./kibana-plugin-plugins-data-server.tosnakecase.md)

## toSnakeCase() function

<b>Signature:</b>

```typescript
export declare function toSnakeCase(obj: Record<string, any>): import("lodash").Dictionary<any>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| obj | <code>Record&lt;string, any&gt;</code> | |

<b>Returns:</b>

`import("lodash").Dictionary<any>`

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ UI_SETTINGS: {
readonly COURIER_MAX_CONCURRENT_SHARD_REQUESTS: "courier:maxConcurrentShardRequests";
readonly COURIER_BATCH_SEARCHES: "courier:batchSearches";
readonly SEARCH_INCLUDE_FROZEN: "search:includeFrozen";
readonly SEARCH_TIMEOUT: "search:timeout";
readonly HISTOGRAM_BAR_TARGET: "histogram:barTarget";
readonly HISTOGRAM_MAX_BARS: "histogram:maxBars";
readonly HISTORY_LIMIT: "history:limit";
Expand Down
1 change: 1 addition & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ be inconsistent because different shards might be in different refresh states.
`search:includeFrozen`:: Includes {ref}/frozen-indices.html[frozen indices] in results.
Searching through frozen indices
might increase the search time. This setting is off by default. Users must opt-in to include frozen indices.
`search:timeout`:: Change the maximum timeout for a search session or set to 0 to disable the timeout and allow queries to run to completion.

[float]
[[kibana-siem-settings]]
Expand Down
15 changes: 0 additions & 15 deletions src/legacy/core_plugins/elasticsearch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { first } from 'rxjs/operators';
import { Cluster } from './lib/cluster';
import { createProxy } from './lib/create_proxy';

export default function (kibana) {
let defaultVars;

return new kibana.Plugin({
require: [],

uiExports: { injectDefaultVars: () => defaultVars },

async init(server) {
// All methods that ES plugin exposes are synchronous so we should get the first
// value from all observables here to be able to synchronously return and create
Expand All @@ -36,16 +31,6 @@ export default function (kibana) {
const adminCluster = new Cluster(client);
const dataCluster = new Cluster(client);

const esConfig = await server.newPlatform.__internals.elasticsearch.legacy.config$
.pipe(first())
.toPromise();

defaultVars = {
esRequestTimeout: esConfig.requestTimeout.asMilliseconds(),
esShardTimeout: esConfig.shardTimeout.asMilliseconds(),
esApiVersion: esConfig.apiVersion,
};

const clusters = new Map();
server.expose('getCluster', (name) => {
if (name === 'admin') {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const UI_SETTINGS = {
COURIER_MAX_CONCURRENT_SHARD_REQUESTS: 'courier:maxConcurrentShardRequests',
COURIER_BATCH_SEARCHES: 'courier:batchSearches',
SEARCH_INCLUDE_FROZEN: 'search:includeFrozen',
SEARCH_TIMEOUT: 'search:timeout',
HISTOGRAM_BAR_TARGET: 'histogram:barTarget',
HISTOGRAM_MAX_BARS: 'histogram:maxBars',
HISTORY_LIMIT: 'history:limit',
Expand Down
8 changes: 1 addition & 7 deletions src/plugins/data/common/search/es_search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,4 @@
* under the License.
*/

export {
ISearchRequestParams,
IEsSearchRequest,
IEsSearchResponse,
ES_SEARCH_STRATEGY,
ISearchOptions,
} from './types';
export * from './types';
3 changes: 3 additions & 0 deletions src/plugins/data/common/search/es_search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ export interface IEsSearchResponse<Source = any> extends IKibanaSearchResponse {
isPartial?: boolean;
rawResponse: SearchResponse<Source>;
}

export const isEsResponse = (response: any): response is IEsSearchResponse =>
response && response.rawResponse;
9 changes: 1 addition & 8 deletions src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,4 @@ export * from './es_search';
export * from './expressions';
export * from './tabify';
export * from './types';

export {
IEsSearchRequest,
IEsSearchResponse,
ES_SEARCH_STRATEGY,
ISearchRequestParams,
ISearchOptions,
} from './es_search';
export * from './es_search';
15 changes: 8 additions & 7 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ export const getKbnTypeNames: () => string[];
//
// @public (undocumented)
export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
esShardTimeout: number;
getConfig: GetConfigFn;
}): ISearchRequestParams;

Expand Down Expand Up @@ -1734,7 +1733,7 @@ export interface SearchError {
//
// @public (undocumented)
export class SearchInterceptor {
constructor(deps: SearchInterceptorDeps, requestTimeout?: number | undefined);
constructor(deps: SearchInterceptorDeps);
// @internal
protected abortController: AbortController;
// @internal (undocumented)
Expand All @@ -1748,13 +1747,14 @@ export class SearchInterceptor {
protected longRunningToast?: Toast;
// @internal
protected pendingCount$: BehaviorSubject<number>;
// (undocumented)
protected readonly requestTimeout?: number | undefined;
// (undocumented)
// @internal (undocumented)
protected runSearch(request: IEsSearchRequest, signal: AbortSignal, strategy?: string): Observable<IEsSearchResponse>;
search(request: IEsSearchRequest, options?: ISearchOptions): Observable<IEsSearchResponse>;
// (undocumented)
protected setupTimers(options?: ISearchOptions): {
// @internal (undocumented)
protected setupAbortSignal({ abortSignal, timeout, }: {
abortSignal?: AbortSignal;
timeout?: number;
}): {
combinedSignal: AbortSignal;
cleanup: () => void;
};
Expand Down Expand Up @@ -1925,6 +1925,7 @@ export const UI_SETTINGS: {
readonly COURIER_MAX_CONCURRENT_SHARD_REQUESTS: "courier:maxConcurrentShardRequests";
readonly COURIER_BATCH_SEARCHES: "courier:batchSearches";
readonly SEARCH_INCLUDE_FROZEN: "search:includeFrozen";
readonly SEARCH_TIMEOUT: "search:timeout";
readonly HISTOGRAM_BAR_TARGET: "histogram:barTarget";
readonly HISTOGRAM_MAX_BARS: "histogram:maxBars";
readonly HISTORY_LIMIT: "history:limit";
Expand Down
Loading

0 comments on commit ba150f7

Please sign in to comment.