Skip to content

Commit

Permalink
[ES|QL] Fixes the error in the console (elastic#198307)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#198258

### Checklist

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Julia Rechkunova <julia.rechkunova@gmail.com>
(cherry picked from commit c319060)
  • Loading branch information
stratoula committed Nov 1, 2024
1 parent 937bfd5 commit 2db302c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/kbn-es-types/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ export interface ESQLSearchResponse {
all_columns?: ESQLColumn[];
values: ESQLRow[];
took?: number;
_clusters?: estypes.ClusterStatistics;
}

export interface ESQLSearchParams {
Expand Down
17 changes: 17 additions & 0 deletions packages/kbn-search-response-warnings/src/extract_warnings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { estypes } from '@elastic/elasticsearch';
import type { Start as InspectorStartContract } from '@kbn/inspector-plugin/public';
import type { ESQLSearchResponse } from '@kbn/es-types';
import type { RequestAdapter } from '@kbn/inspector-plugin/common/adapters/request';
import { extractWarnings } from './extract_warnings';

Expand Down Expand Up @@ -108,6 +109,22 @@ describe('extract search response warnings', () => {

expect(warnings).toEqual([]);
});

it('should not include warnings when there is no _clusters or _shards information', () => {
const warnings = extractWarnings(
{
took: 46,
all_columns: [{ name: 'field1', type: 'string' }],
columns: [{ name: 'field1', type: 'string' }],
values: [['value1']],
} as ESQLSearchResponse,
mockInspectorService,
mockRequestAdapter,
'My request'
);

expect(warnings).toEqual([]);
});
});

describe('remote clusters', () => {
Expand Down
14 changes: 9 additions & 5 deletions packages/kbn-search-response-warnings/src/extract_warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@
*/

import { estypes } from '@elastic/elasticsearch';
import type { ESQLSearchResponse } from '@kbn/es-types';
import type { Start as InspectorStartContract, RequestAdapter } from '@kbn/inspector-plugin/public';
import type { SearchResponseWarning } from './types';

/**
* @internal
*/
export function extractWarnings(
rawResponse: estypes.SearchResponse,
rawResponse: estypes.SearchResponse | ESQLSearchResponse,
inspectorService: InspectorStartContract,
requestAdapter: RequestAdapter,
requestName: string,
requestId?: string
): SearchResponseWarning[] {
const warnings: SearchResponseWarning[] = [];

// ES|QL supports _clusters in case of CCS but doesnt support _shards and timed_out (yet)
const isPartial = rawResponse._clusters
? rawResponse._clusters.partial > 0 ||
rawResponse._clusters.skipped > 0 ||
rawResponse._clusters.running > 0
: rawResponse.timed_out || rawResponse._shards.failed > 0;
: ('timed_out' in rawResponse && rawResponse.timed_out) ||
('_shards' in rawResponse && rawResponse._shards.failed > 0);
if (isPartial) {
warnings.push({
type: 'incomplete',
Expand All @@ -39,9 +42,10 @@ export function extractWarnings(
status: 'partial',
indices: '',
took: rawResponse.took,
timed_out: rawResponse.timed_out,
_shards: rawResponse._shards,
failures: rawResponse._shards.failures,
timed_out: 'timed_out' in rawResponse && rawResponse.timed_out,
...('_shards' in rawResponse
? { _shards: rawResponse._shards, failures: rawResponse._shards.failures }
: {}),
},
},
openInInspector: () => {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-search-response-warnings/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@kbn/core",
"@kbn/react-kibana-mount",
"@kbn/core-i18n-browser",
"@kbn/es-types",
],
"exclude": ["target/**/*"]
}

0 comments on commit 2db302c

Please sign in to comment.