Skip to content

Commit

Permalink
Merge branch '7.7' into backport/7.7/pr-61641
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Apr 1, 2020
2 parents fb9969f + 43c052f commit 8b054d1
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/dev/ci_setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
Expand Down
3 changes: 0 additions & 3 deletions test/scripts/jenkins_build_kibana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions test/scripts/jenkins_xpack_build_kibana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
14 changes: 10 additions & 4 deletions x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getTotalLoaded,
} from '../../../../../src/plugins/data/server';
import { IEnhancedEsSearchRequest } from '../../common';
import { shimHitsTotal } from './shim_hits_total';

export interface AsyncSearchResponse<T> {
id: string;
Expand Down Expand Up @@ -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<any>;

return { id, rawResponse, ...getTotalLoaded(rawResponse._shards) };
return { id, rawResponse: shimHitsTotal(response), ...getTotalLoaded(response._shards) };
}

async function rollupSearch(
Expand Down
56 changes: 56 additions & 0 deletions x-pack/plugins/data_enhanced/server/search/shim_hits_total.test.ts
Original file line number Diff line number Diff line change
@@ -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,
},
});
});
});
18 changes: 18 additions & 0 deletions x-pack/plugins/data_enhanced/server/search/shim_hits_total.ts
Original file line number Diff line number Diff line change
@@ -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<any>) {
const total = (response.hits?.total as any)?.value ?? response.hits?.total;
const hits = { ...response.hits, total };
return { ...response, hits };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8b054d1

Please sign in to comment.