diff --git a/src/dev/ci_setup/setup.sh b/src/dev/ci_setup/setup.sh index 6f604f631cb0e..a9ba182836b73 100755 --- a/src/dev/ci_setup/setup.sh +++ b/src/dev/ci_setup/setup.sh @@ -16,6 +16,14 @@ echo " -- TEST_ES_SNAPSHOT_VERSION='$TEST_ES_SNAPSHOT_VERSION'" echo " -- installing node.js dependencies" yarn kbn bootstrap --prefer-offline +### +### Download es snapshots +### +echo " -- downloading es snapshot" +node scripts/es snapshot --download-only; +node scripts/es snapshot --license=oss --download-only; + + ### ### verify no git modifications ### diff --git a/test/scripts/jenkins_build_kibana.sh b/test/scripts/jenkins_build_kibana.sh index 2878af09bb1bb..efef91b8581a3 100755 --- a/test/scripts/jenkins_build_kibana.sh +++ b/test/scripts/jenkins_build_kibana.sh @@ -11,9 +11,6 @@ node scripts/build_kibana_platform_plugins \ # doesn't persist, also set in kibanaPipeline.groovy export KBN_NP_PLUGINS_BUILT=true -echo " -> downloading es snapshot" -node scripts/es snapshot --license=oss --download-only; - echo " -> Ensuring all functional tests are in a ciGroup" yarn run grunt functionalTests:ensureAllTestsInCiGroup; diff --git a/test/scripts/jenkins_xpack_build_kibana.sh b/test/scripts/jenkins_xpack_build_kibana.sh index c9796d6d6772f..808df0df73591 100755 --- a/test/scripts/jenkins_xpack_build_kibana.sh +++ b/test/scripts/jenkins_xpack_build_kibana.sh @@ -12,9 +12,6 @@ node scripts/build_kibana_platform_plugins \ # doesn't persist, also set in kibanaPipeline.groovy export KBN_NP_PLUGINS_BUILT=true -echo " -> downloading es snapshot" -node scripts/es snapshot --download-only; - echo " -> Ensuring all functional tests are in a ciGroup" cd "$XPACK_DIR" node scripts/functional_tests --assert-none-excluded \ diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 57d31553382bf..301f184af7d81 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -19,6 +19,7 @@ import { getTotalLoaded, } from '../../../../../src/plugins/data/server'; import { IEnhancedEsSearchRequest } from '../../common'; +import { shimHitsTotal } from './shim_hits_total'; export interface AsyncSearchResponse { id: string; @@ -56,22 +57,27 @@ async function asyncSearch( request: IEnhancedEsSearchRequest, options?: ISearchOptions ) { - const { body = undefined, index = undefined, ...params } = request.id ? {} : request.params; + const { timeout = undefined, restTotalHitsAsInt = undefined, ...params } = { + trackTotalHits: true, // Get the exact count of hits + ...request.params, + }; // If we have an ID, then just poll for that ID, otherwise send the entire request body + const { body = undefined, index = undefined, ...queryParams } = request.id ? {} : params; + const method = request.id ? 'GET' : 'POST'; const path = encodeURI(request.id ? `_async_search/${request.id}` : `${index}/_async_search`); // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...params }); + const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...queryParams }); - const { response: rawResponse, id } = (await caller( + const { response, id } = (await caller( 'transport.request', { method, path, body, query }, options )) as AsyncSearchResponse; - return { id, rawResponse, ...getTotalLoaded(rawResponse._shards) }; + return { id, rawResponse: shimHitsTotal(response), ...getTotalLoaded(response._shards) }; } async function rollupSearch( diff --git a/x-pack/plugins/data_enhanced/server/search/shim_hits_total.test.ts b/x-pack/plugins/data_enhanced/server/search/shim_hits_total.test.ts new file mode 100644 index 0000000000000..61740b97299da --- /dev/null +++ b/x-pack/plugins/data_enhanced/server/search/shim_hits_total.test.ts @@ -0,0 +1,56 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { shimHitsTotal } from './shim_hits_total'; + +describe('shimHitsTotal', () => { + test('returns the total if it is already numeric', () => { + const result = shimHitsTotal({ + hits: { + total: 5, + }, + } as any); + expect(result).toEqual({ + hits: { + total: 5, + }, + }); + }); + + test('returns the total if it is inside `value`', () => { + const result = shimHitsTotal({ + hits: { + total: { + value: 5, + }, + }, + } as any); + expect(result).toEqual({ + hits: { + total: 5, + }, + }); + }); + + test('returns other properties from the response', () => { + const result = shimHitsTotal({ + _shards: {}, + hits: { + hits: [], + total: { + value: 5, + }, + }, + } as any); + expect(result).toEqual({ + _shards: {}, + hits: { + hits: [], + total: 5, + }, + }); + }); +}); diff --git a/x-pack/plugins/data_enhanced/server/search/shim_hits_total.ts b/x-pack/plugins/data_enhanced/server/search/shim_hits_total.ts new file mode 100644 index 0000000000000..10d45be01563a --- /dev/null +++ b/x-pack/plugins/data_enhanced/server/search/shim_hits_total.ts @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SearchResponse } from 'elasticsearch'; + +/** + * Temporary workaround until https://github.com/elastic/kibana/issues/26356 is addressed. + * Since we are setting `track_total_hits` in the request, `hits.total` will be an object + * containing the `value`. + */ +export function shimHitsTotal(response: SearchResponse) { + const total = (response.hits?.total as any)?.value ?? response.hits?.total; + const hits = { ...response.hits, total }; + return { ...response, hits }; +} diff --git a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/utils.ts b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/utils.ts index f1404b79a07af..7b725a7830c56 100644 --- a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/utils.ts +++ b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/utils.ts @@ -18,6 +18,8 @@ export const removeServerGeneratedProperties = ( created_at, updated_at, id, + last_failure_at, + last_failure_message, last_success_at, last_success_message, status,