Skip to content

Commit

Permalink
[Search] Unify search plugin step 2 — Search Interceptor (#97845)
Browse files Browse the repository at this point in the history
Unify search interceptor
Deprecate TimeoutErrorMode.UPGRADE
  • Loading branch information
Dosant authored Apr 28, 2021
1 parent 66a1aff commit 18dd767
Show file tree
Hide file tree
Showing 36 changed files with 1,842 additions and 2,144 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ export declare class SearchInterceptor
| --- | --- | --- |
| [(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> | |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [getSerializableOptions(options)](./kibana-plugin-plugins-data-public.searchinterceptor.getserializableoptions.md) | | |
| [getTimeoutMode()](./kibana-plugin-plugins-data-public.searchinterceptor.gettimeoutmode.md) | | |
| [handleSearchError(e, options, isTimeout)](./kibana-plugin-plugins-data-public.searchinterceptor.handlesearcherror.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 the request times out, or when the original <code>AbortSignal</code> is aborted. Updates <code>pendingCount$</code> when the request is started/finalized. |
| [search({ id, ...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 the request times out, or when the original <code>AbortSignal</code> is aborted. Updates <code>pendingCount$</code> when the request is started/finalized. |
| [showError(e)](./kibana-plugin-plugins-data-public.searchinterceptor.showerror.md) | | |
| [stop()](./kibana-plugin-plugins-data-public.searchinterceptor.stop.md) | | |

Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ Searches using the given `search` method. Overrides the `AbortSignal` with one t
<b>Signature:</b>

```typescript
search(request: IKibanaSearchRequest, options?: ISearchOptions): Observable<IKibanaSearchResponse>;
search({ id, ...request }: IKibanaSearchRequest, options?: IAsyncSearchOptions): import("rxjs").Observable<IKibanaSearchResponse<any>>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | <code>IKibanaSearchRequest</code> | |
| options | <code>ISearchOptions</code> | |
| { id, ...request } | <code>IKibanaSearchRequest</code> | |
| options | <code>IAsyncSearchOptions</code> | |

<b>Returns:</b>

`Observable<IKibanaSearchResponse>`
`import("rxjs").Observable<IKibanaSearchResponse<any>>`

`Observable` emitting the search response or an error.

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<!-- 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; [SearchInterceptor](./kibana-plugin-plugins-data-public.searchinterceptor.md) &gt; [deps](./kibana-plugin-plugins-data-public.searchinterceptor.deps.md)
[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [SearchInterceptor](./kibana-plugin-plugins-data-public.searchinterceptor.md) &gt; [stop](./kibana-plugin-plugins-data-public.searchinterceptor.stop.md)

## SearchInterceptor.deps property
## SearchInterceptor.stop() method

<b>Signature:</b>

```typescript
protected readonly deps: SearchInterceptorDeps;
stop(): void;
```
<b>Returns:</b>

`void`

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export declare enum TimeoutErrorMode

| Member | Value | Description |
| --- | --- | --- |
| CHANGE | <code>2</code> | |
| CONTACT | <code>1</code> | |
| UPGRADE | <code>0</code> | |
| CHANGE | <code>1</code> | |
| CONTACT | <code>0</code> | |

1 change: 0 additions & 1 deletion src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const createSetupContract = (): Setup => {
search: searchServiceMock.createSetupContract(),
fieldFormats: fieldFormatsServiceMock.createSetupContract(),
query: querySetupMock,
__enhance: jest.fn(),
};
};

Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
DataPublicPluginStart,
DataSetupDependencies,
DataStartDependencies,
DataPublicPluginEnhancements,
} from './types';
import { AutocompleteService } from './autocomplete';
import { SearchService } from './search/search_service';
Expand Down Expand Up @@ -122,9 +121,6 @@ export class DataPublicPlugin
search: searchService,
fieldFormats: this.fieldFormatsService.setup(core),
query: queryService,
__enhance: (enhancements: DataPublicPluginEnhancements) => {
searchService.__enhance(enhancements.search);
},
};
}

Expand Down
36 changes: 6 additions & 30 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Adapters as Adapters_2 } from 'src/plugins/inspector/common';
import { ApiResponse } from '@elastic/elasticsearch/lib/Transport';
import { ApplicationStart } from 'kibana/public';
import { Assign } from '@kbn/utility-types';
import { BehaviorSubject } from 'rxjs';
import { BfetchPublicSetup } from 'src/plugins/bfetch/public';
import Boom from '@hapi/boom';
import { ConfigDeprecationProvider } from '@kbn/config';
Expand Down Expand Up @@ -579,10 +578,6 @@ export type CustomFilter = Filter & {
//
// @public
export interface DataPublicPluginSetup {
// Warning: (ae-forgotten-export) The symbol "DataPublicPluginEnhancements" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
__enhance: (enhancements: DataPublicPluginEnhancements) => void;
// Warning: (ae-forgotten-export) The symbol "AutocompleteSetup" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -1695,10 +1690,6 @@ export interface ISearchOptions {
//
// @public
export interface ISearchSetup {
// Warning: (ae-forgotten-export) The symbol "SearchEnhancements" needs to be exported by the entry point index.d.ts
//
// @internal (undocumented)
__enhance: (enhancements: SearchEnhancements) => void;
// Warning: (ae-forgotten-export) The symbol "AggsSetup" needs to be exported by the entry point index.d.ts
//
// (undocumented)
Expand Down Expand Up @@ -2387,25 +2378,12 @@ export interface SearchError {
// @public (undocumented)
export class SearchInterceptor {
constructor(deps: SearchInterceptorDeps);
// @internal (undocumented)
protected application: CoreStart['application'];
// (undocumented)
protected readonly deps: SearchInterceptorDeps;
// (undocumented)
protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions, "strategy" | "sessionId" | "isStored" | "isRestore" | "legacyHitsTotal">;
// (undocumented)
protected getTimeoutMode(): TimeoutErrorMode;
// Warning: (ae-forgotten-export) The symbol "AbortError" needs to be exported by the entry point index.d.ts
//
// (undocumented)
protected handleSearchError(e: KibanaServerError | AbortError, options?: ISearchOptions, isTimeout?: boolean): Error;
// @internal
protected pendingCount$: BehaviorSubject<number>;
// @internal (undocumented)
protected runSearch(request: IKibanaSearchRequest, options?: ISearchOptions): Promise<IKibanaSearchResponse>;
search(request: IKibanaSearchRequest, options?: ISearchOptions): Observable<IKibanaSearchResponse>;
// Warning: (ae-forgotten-export) The symbol "IAsyncSearchOptions" needs to be exported by the entry point index.d.ts
search({ id, ...request }: IKibanaSearchRequest, options?: IAsyncSearchOptions): import("rxjs").Observable<IKibanaSearchResponse<any>>;
// (undocumented)
showError(e: Error): void;
// (undocumented)
stop(): void;
}

// Warning: (ae-missing-release-tag) "SearchInterceptorDeps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -2643,11 +2621,9 @@ export type TimeHistoryContract = PublicMethodsOf<TimeHistory>;
// @public (undocumented)
export enum TimeoutErrorMode {
// (undocumented)
CHANGE = 2,
// (undocumented)
CONTACT = 1,
CHANGE = 1,
// (undocumented)
UPGRADE = 0
CONTACT = 0
}

// Warning: (ae-missing-release-tag) "TimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
11 changes: 0 additions & 11 deletions src/plugins/data/public/search/errors/timeout_error.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ describe('SearchTimeoutError', () => {
startMock.application.navigateToApp.mockImplementation(jest.fn());
});

it('Should navigate to upgrade', () => {
const e = new SearchTimeoutError(new AbortError(), TimeoutErrorMode.UPGRADE);
const component = mount(e.getErrorMessage(startMock.application));

expect(component.find('EuiButton').length).toBe(1);
component.find('EuiButton').simulate('click');
expect(startMock.application.navigateToUrl).toHaveBeenCalledWith(
'https://www.elastic.co/subscriptions'
);
});

it('Should create contact admin message', () => {
const e = new SearchTimeoutError(new AbortError(), TimeoutErrorMode.CONTACT);
const component = mount(e.getErrorMessage(startMock.application));
Expand Down
14 changes: 0 additions & 14 deletions src/plugins/data/public/search/errors/timeout_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ApplicationStart } from 'kibana/public';
import { KbnError } from '../../../../kibana_utils/common';

export enum TimeoutErrorMode {
UPGRADE,
CONTACT,
CHANGE,
}
Expand All @@ -31,11 +30,6 @@ export class SearchTimeoutError extends KbnError {

private getMessage() {
switch (this.mode) {
case TimeoutErrorMode.UPGRADE:
return i18n.translate('data.search.upgradeLicense', {
defaultMessage:
'Your query has timed out. With our free Basic tier, your queries never time out.',
});
case TimeoutErrorMode.CONTACT:
return i18n.translate('data.search.timeoutContactAdmin', {
defaultMessage:
Expand All @@ -51,11 +45,6 @@ export class SearchTimeoutError extends KbnError {

private getActionText() {
switch (this.mode) {
case TimeoutErrorMode.UPGRADE:
return i18n.translate('data.search.upgradeLicenseActionText', {
defaultMessage: 'Upgrade now',
});
break;
case TimeoutErrorMode.CHANGE:
return i18n.translate('data.search.timeoutIncreaseSettingActionText', {
defaultMessage: 'Edit setting',
Expand All @@ -66,9 +55,6 @@ export class SearchTimeoutError extends KbnError {

private onClick(application: ApplicationStart) {
switch (this.mode) {
case TimeoutErrorMode.UPGRADE:
application.navigateToUrl('https://www.elastic.co/subscriptions');
break;
case TimeoutErrorMode.CHANGE:
application.navigateToApp('management', {
path: `/kibana/settings`,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export {
ISearchSetup,
ISearchStart,
ISearchStartSearchSource,
SearchEnhancements,
SearchUsageCollector,
} from './types';

Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/search/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { createSearchUsageCollectorMock } from './collectors/mocks';
function createSetupContract(): jest.Mocked<ISearchSetup> {
return {
aggs: searchAggsSetupMock(),
__enhance: jest.fn(),
session: getSessionServiceMock(),
sessionsClient: getSessionsClientMock(),
usageCollector: createSearchUsageCollectorMock(),
Expand Down
Loading

0 comments on commit 18dd767

Please sign in to comment.