Skip to content

Commit

Permalink
[8.x] [ES|QL] Fixes the error in the console (#198307) (#198653)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Fixes the error in the console
(#198307)](#198307)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Stratoula
Kalafateli","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-01T10:49:07Z","message":"[ES|QL]
Fixes the error in the console (#198307)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/198258\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Rechkunova
<[email protected]>","sha":"c31906085024e2ae3b7a34f6b3bc80f40da9d514","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Feature:ES|QL","Team:ESQL","backport:version","v8.17.0"],"title":"[ES|QL]
Fixes the error in the
console","number":198307,"url":"https://github.com/elastic/kibana/pull/198307","mergeCommit":{"message":"[ES|QL]
Fixes the error in the console (#198307)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/198258\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Rechkunova
<[email protected]>","sha":"c31906085024e2ae3b7a34f6b3bc80f40da9d514"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198307","number":198307,"mergeCommit":{"message":"[ES|QL]
Fixes the error in the console (#198307)\n\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/198258\r\n\r\n###
Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Julia Rechkunova
<[email protected]>","sha":"c31906085024e2ae3b7a34f6b3bc80f40da9d514"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
kibanamachine and stratoula authored Nov 1, 2024
1 parent d74f8a7 commit 52f7e2b
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 52f7e2b

Please sign in to comment.