Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -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; [isCompleteResponse](./kibana-plugin-plugins-data-public.iscompleteresponse.md)

## isCompleteResponse variable

<b>Signature:</b>

```typescript
isCompleteResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined
```
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; [isErrorResponse](./kibana-plugin-plugins-data-public.iserrorresponse.md)

## isErrorResponse variable

<b>Signature:</b>

```typescript
isErrorResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined
```
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; [isPartialResponse](./kibana-plugin-plugins-data-public.ispartialresponse.md)

## isPartialResponse variable

<b>Signature:</b>

```typescript
isPartialResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined
```
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
| [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | |
| [FieldMappingSpec](./kibana-plugin-plugins-data-public.fieldmappingspec.md) | |
| [Filter](./kibana-plugin-plugins-data-public.filter.md) | |
| [IDataPluginServices](./kibana-plugin-plugins-data-public.idatapluginservices.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | |
| [IEsSearchResponse](./kibana-plugin-plugins-data-public.iessearchresponse.md) | |
Expand All @@ -75,7 +74,6 @@
| [ISearchStartSearchSource](./kibana-plugin-plugins-data-public.isearchstartsearchsource.md) | high level search service |
| [KueryNode](./kibana-plugin-plugins-data-public.kuerynode.md) | |
| [OptionedValueProp](./kibana-plugin-plugins-data-public.optionedvalueprop.md) | |
| [Query](./kibana-plugin-plugins-data-public.query.md) | |
| [QueryState](./kibana-plugin-plugins-data-public.querystate.md) | All query state service state |
| [QueryStateChange](./kibana-plugin-plugins-data-public.querystatechange.md) | |
| [QuerySuggestionBasic](./kibana-plugin-plugins-data-public.querysuggestionbasic.md) | \* |
Expand All @@ -90,7 +88,6 @@
| [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | search source fields |
| [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* |
| [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* |
| [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | |

## Variables

Expand All @@ -115,8 +112,11 @@
| [getKbnTypeNames](./kibana-plugin-plugins-data-public.getkbntypenames.md) | Get the esTypes known by all kbnFieldTypes {<!-- -->Array<string>} |
| [indexPatterns](./kibana-plugin-plugins-data-public.indexpatterns.md) | |
| [injectSearchSourceReferences](./kibana-plugin-plugins-data-public.injectsearchsourcereferences.md) | |
| [isCompleteResponse](./kibana-plugin-plugins-data-public.iscompleteresponse.md) | |
| [isErrorResponse](./kibana-plugin-plugins-data-public.iserrorresponse.md) | |
| [isFilter](./kibana-plugin-plugins-data-public.isfilter.md) | |
| [isFilters](./kibana-plugin-plugins-data-public.isfilters.md) | |
| [isPartialResponse](./kibana-plugin-plugins-data-public.ispartialresponse.md) | |
| [isQuery](./kibana-plugin-plugins-data-public.isquery.md) | |
| [isTimeRange](./kibana-plugin-plugins-data-public.istimerange.md) | |
| [parseSearchSourceJSON](./kibana-plugin-plugins-data-public.parsesearchsourcejson.md) | |
Expand Down Expand Up @@ -145,6 +145,7 @@
| [FieldFormatsContentType](./kibana-plugin-plugins-data-public.fieldformatscontenttype.md) | \* |
| [FieldFormatsGetConfigFn](./kibana-plugin-plugins-data-public.fieldformatsgetconfigfn.md) | |
| [FieldFormatsStart](./kibana-plugin-plugins-data-public.fieldformatsstart.md) | |
| [Filter](./kibana-plugin-plugins-data-public.filter.md) | |
| [IAggConfig](./kibana-plugin-plugins-data-public.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. |
| [IAggType](./kibana-plugin-plugins-data-public.iaggtype.md) | |
| [IFieldFormat](./kibana-plugin-plugins-data-public.ifieldformat.md) | |
Expand All @@ -162,6 +163,7 @@
| [ParsedInterval](./kibana-plugin-plugins-data-public.parsedinterval.md) | |
| [PhraseFilter](./kibana-plugin-plugins-data-public.phrasefilter.md) | |
| [PhrasesFilter](./kibana-plugin-plugins-data-public.phrasesfilter.md) | |
| [Query](./kibana-plugin-plugins-data-public.query.md) | |
| [QueryStart](./kibana-plugin-plugins-data-public.querystart.md) | |
| [QuerySuggestion](./kibana-plugin-plugins-data-public.querysuggestion.md) | \* |
| [QuerySuggestionGetFn](./kibana-plugin-plugins-data-public.querysuggestiongetfn.md) | |
Expand All @@ -173,4 +175,5 @@
| [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* |
| [TimefilterContract](./kibana-plugin-plugins-data-public.timefiltercontract.md) | |
| [TimeHistoryContract](./kibana-plugin-plugins-data-public.timehistorycontract.md) | |
| [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | |

6 changes: 4 additions & 2 deletions examples/search_examples/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import {
IndexPatternSelect,
IndexPattern,
IndexPatternField,
isCompleteResponse,
isErrorResponse,
} from '../../../../src/plugins/data/public';

interface SearchExamplesAppDeps {
Expand Down Expand Up @@ -144,7 +146,7 @@ export const SearchExamplesApp = ({
})
.subscribe({
next: (response) => {
if (!response.isPartial && !response.isRunning) {
if (isCompleteResponse(response)) {
setTimeTook(response.rawResponse.took);
const avgResult: number | undefined = response.rawResponse.aggregations
? response.rawResponse.aggregations[1].value
Expand All @@ -162,7 +164,7 @@ export const SearchExamplesApp = ({
text: mountReactNode(message),
});
searchSubscription$.unsubscribe();
} else if (response.isPartial && !response.isRunning) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know this is an actual documented error case? Is there a reliable way to reproduce this error?

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 pinged the security team, for them to consider reducing code duplication.

And this is definitely a documented error case (this is what delayed the release of 7.8 or 7.7 I remember)

} else if (isErrorResponse(response)) {
// TODO: Make response error status clearer
notifications.toasts.addWarning('An error has occurred');
searchSubscription$.unsubscribe();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/es_search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export * from './types';
export * from './utils';
41 changes: 41 additions & 0 deletions src/plugins/data/common/search/es_search/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { IEsSearchResponse } from './types';

/**
* @returns true if response had an error while executing in ES
*/
export const isErrorResponse = (response?: IEsSearchResponse) => {
return !response || (!response.isRunning && response.isPartial);
};

/**
* @returns true if response is completed successfully
*/
export const isCompleteResponse = (response?: IEsSearchResponse) => {
return response && !response.isRunning && !response.isPartial;
};

/**
* @returns true if request is still running an/d response contains partial results
*/
export const isPartialResponse = (response?: IEsSearchResponse) => {
return response && response.isRunning && response.isPartial;
};
1 change: 1 addition & 0 deletions src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './expressions';
export * from './search_source';
export * from './tabify';
export * from './types';
export * from './es_search';
2 changes: 1 addition & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export {

export type { SearchSource } from './search';

export { ISearchOptions } from '../common';
export { ISearchOptions, isErrorResponse, isCompleteResponse, isPartialResponse } from '../common';

// Search namespace
export const search = {
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,11 @@ export type InputTimeRange = TimeRange | {
to: Moment;
};

// Warning: (ae-missing-release-tag) "isCompleteResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const isCompleteResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined;

// Warning: (ae-missing-release-tag) "ISearch" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1433,6 +1438,11 @@ export interface ISearchStartSearchSource {
createEmpty: () => ISearchSource;
}

// Warning: (ae-missing-release-tag) "isErrorResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const isErrorResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined;

// Warning: (ae-missing-release-tag) "isFilter" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand All @@ -1443,6 +1453,11 @@ export const isFilter: (x: unknown) => x is Filter;
// @public (undocumented)
export const isFilters: (x: unknown) => x is Filter[];

// Warning: (ae-missing-release-tag) "isPartialResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const isPartialResponse: (response?: IEsSearchResponse<any> | undefined) => boolean | undefined;

// Warning: (ae-missing-release-tag) "isQuery" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SearchInterceptorDeps,
UI_SETTINGS,
} from '../../../../../src/plugins/data/public';
import { isErrorResponse, isCompleteResponse } from '../../../../../src/plugins/data/public';
import { AbortError, toPromise } from '../../../../../src/plugins/data/common';
import { IAsyncSearchOptions } from '.';
import { IAsyncSearchRequest, ENHANCED_ES_SEARCH_STRATEGY } from '../../common';
Expand Down Expand Up @@ -66,12 +67,12 @@ export class EnhancedSearchInterceptor extends SearchInterceptor {
return this.runSearch(request, combinedSignal, strategy).pipe(
expand((response) => {
// If the response indicates of an error, stop polling and complete the observable
if (!response || (!response.isRunning && response.isPartial)) {
if (isErrorResponse(response)) {
return throwError(new AbortError());
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to revisit the error we throw here. I think we need to forward the error returned by ES.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// If the response indicates it is complete, stop polling and complete the observable
if (!response.isRunning) {
if (isCompleteResponse(response)) {
return EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
shimHitsTotal,
} from '../../../../../src/plugins/data/server';
import { IEnhancedEsSearchRequest } from '../../common';
import { ISearchOptions, IEsSearchResponse } from '../../../../../src/plugins/data/common/search';
import {
ISearchOptions,
IEsSearchResponse,
isCompleteResponse,
} from '../../../../../src/plugins/data/common/search';

function isEnhancedEsSearchResponse(response: any): response is IEsSearchResponse {
return response.hasOwnProperty('isPartial') && response.hasOwnProperty('isRunning');
Expand Down Expand Up @@ -48,8 +52,7 @@ export const enhancedEsSearchStrategyProvider = (
usage &&
isAsync &&
isEnhancedEsSearchResponse(response) &&
!response.isRunning &&
!response.isPartial
isCompleteResponse(response)
) {
usage.trackSuccess(response.rawResponse.took);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
LastTimeDetails,
LastEventIndexKey,
} from '../../../../../common/search_strategy/timeline';
import { AbortError } from '../../../../../../../../src/plugins/data/common';
import {
AbortError,
isCompleteResponse,
isErrorResponse,
} from '../../../../../../../../src/plugins/data/common';
import { useWithSource } from '../../source';
import * as i18n from './translations';

Expand Down Expand Up @@ -80,7 +84,7 @@ export const useTimelineLastEventTime = ({
})
.subscribe({
next: (response) => {
if (!response.isPartial && !response.isRunning) {
if (isCompleteResponse(response)) {
if (!didCancel) {
setLoading(false);
setTimelineLastEventTimeResponse((prevResponse) => ({
Expand All @@ -91,7 +95,7 @@ export const useTimelineLastEventTime = ({
}));
}
searchSubscription$.unsubscribe();
} else if (response.isPartial && !response.isRunning) {
} else if (isErrorResponse(response)) {
if (!didCancel) {
setLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
MatrixHistogramStrategyResponse,
MatrixHistogramData,
} from '../../../../common/search_strategy/security_solution';
import { AbortError } from '../../../../../../../src/plugins/data/common';
import {
AbortError,
isErrorResponse,
isCompleteResponse,
} from '../../../../../../../src/plugins/data/common';
import { getInspectResponse } from '../../../helpers';
import { InspectResponse } from '../../../types';
import * as i18n from './translations';
Expand Down Expand Up @@ -90,7 +94,7 @@ export const useMatrixHistogram = ({
})
.subscribe({
next: (response) => {
if (!response.isPartial && !response.isRunning) {
if (isCompleteResponse(response)) {
if (!didCancel) {
setLoading(false);
setMatrixHistogramResponse((prevResponse) => ({
Expand All @@ -102,7 +106,7 @@ export const useMatrixHistogram = ({
}));
}
searchSubscription$.unsubscribe();
} else if (response.isPartial && !response.isRunning) {
} else if (isErrorResponse(response)) {
if (!didCancel) {
setLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { shallowEqual, useSelector } from 'react-redux';
import deepEqual from 'fast-deep-equal';

import { AbortError } from '../../../../../../../src/plugins/data/common';
import {
AbortError,
isCompleteResponse,
isErrorResponse,
} from '../../../../../../../src/plugins/data/common';

import { DEFAULT_INDEX_KEY } from '../../../../common/constants';
import { HostsQueries } from '../../../../common/search_strategy/security_solution';
Expand Down Expand Up @@ -136,7 +140,7 @@ export const useAuthentications = ({
})
.subscribe({
next: (response) => {
if (!response.isPartial && !response.isRunning) {
if (isCompleteResponse(response)) {
if (!didCancel) {
setLoading(false);
setAuthenticationsResponse((prevResponse) => ({
Expand All @@ -149,7 +153,7 @@ export const useAuthentications = ({
}));
}
searchSubscription$.unsubscribe();
} else if (response.isPartial && !response.isRunning) {
} else if (isErrorResponse(response)) {
if (!didCancel) {
setLoading(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
} from '../../../../../common/search_strategy/security_solution/hosts';

import * as i18n from './translations';
import { AbortError } from '../../../../../../../../src/plugins/data/common';
import {
AbortError,
isCompleteResponse,
isErrorResponse,
} from '../../../../../../../../src/plugins/data/common';
import { getInspectResponse } from '../../../../helpers';
import { InspectResponse } from '../../../../types';

Expand Down Expand Up @@ -93,7 +97,7 @@ export const useHostDetails = ({
})
.subscribe({
next: (response) => {
if (!response.isPartial && !response.isRunning) {
if (isCompleteResponse(response)) {
if (!didCancel) {
setLoading(false);
setHostDetailsResponse((prevResponse) => ({
Expand All @@ -104,7 +108,7 @@ export const useHostDetails = ({
}));
}
searchSubscription$.unsubscribe();
} else if (response.isPartial && !response.isRunning) {
} else if (isErrorResponse(response)) {
if (!didCancel) {
setLoading(false);
}
Expand Down
Loading