Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Fixes the error in the console #198307

Merged
merged 5 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
13 changes: 8 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) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it Typescript that does not allow to simply have rawResponse.timed_out here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah....

('_shards' in rawResponse && rawResponse._shards.failed > 0);
if (isPartial) {
warnings.push({
type: 'incomplete',
Expand All @@ -39,9 +42,9 @@ export function extractWarnings(
status: 'partial',
indices: '',
took: rawResponse.took,
timed_out: rawResponse.timed_out,
_shards: rawResponse._shards,
failures: rawResponse._shards.failures,
...('_shards' in rawResponse && { _shards: rawResponse._shards }),
timed_out: 'timed_out' in rawResponse && rawResponse.timed_out,
...('_shards' in rawResponse && { failures: rawResponse._shards.failures }),
stratoula marked this conversation as resolved.
Show resolved Hide resolved
},
},
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/**/*"]
}