allows to disable automatic handling of shard warnings on expressions (#139824)

This commit is contained in:
Peter Pisljar 2022-09-01 07:33:57 +02:00 committed by GitHub
parent 235679aeaa
commit 64050167af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 3 deletions

View file

@ -53,6 +53,7 @@ describe('esaggs expression function - public', () => {
query: undefined,
searchSessionId: 'abc123',
searchSourceService: searchSourceCommonMock,
disableShardWarnings: false,
timeFields: ['@timestamp', 'utc_time'],
timeRange: undefined,
};
@ -138,6 +139,7 @@ describe('esaggs expression function - public', () => {
description: 'This request queries Elasticsearch to fetch the data for the visualization.',
adapter: undefined,
},
disableShardFailureWarning: false,
});
});

View file

@ -30,6 +30,7 @@ export interface RequestHandlerParams {
searchSourceService: ISearchStartSearchSource;
timeFields?: string[];
timeRange?: TimeRange;
disableShardWarnings?: boolean;
getNow?: () => Date;
executionContext?: KibanaExecutionContext;
}
@ -45,6 +46,7 @@ export const handleRequest = ({
searchSourceService,
timeFields,
timeRange,
disableShardWarnings,
getNow,
executionContext,
}: RequestHandlerParams) => {
@ -111,6 +113,7 @@ export const handleRequest = ({
requestSearchSource
.fetch$({
abortSignal,
disableShardFailureWarning: disableShardWarnings,
sessionId: searchSessionId,
inspector: {
adapter: inspectorAdapters.requests,

View file

@ -15,6 +15,7 @@ export type ExecutionContextSearch = {
filters?: Filter[];
query?: Query | Query[];
timeRange?: TimeRange;
disableShardWarnings?: boolean;
};
export type ExpressionValueSearchContext = ExpressionValueBoxed<

View file

@ -56,7 +56,7 @@ describe('esaggs expression function - public', () => {
jest.clearAllMocks();
mockHandlers = {
abortSignal: jest.fn() as unknown as jest.Mocked<AbortSignal>,
getSearchContext: jest.fn(),
getSearchContext: jest.fn().mockReturnValue({}),
getSearchSessionId: jest.fn().mockReturnValue('abc123'),
getExecutionContext: jest.fn(),
inspectorAdapters: jest.fn(),
@ -123,6 +123,7 @@ describe('esaggs expression function - public', () => {
searchSessionId: 'abc123',
searchSourceService: startDependencies.searchSource,
timeFields: args.timeFields,
disableShardWarnings: false,
timeRange: undefined,
getNow: undefined,
});

View file

@ -36,7 +36,11 @@ export function getFunctionDefinition({
}) {
return (): EsaggsExpressionFunctionDefinition => ({
...getEsaggsMeta(),
fn(input, args, { inspectorAdapters, abortSignal, getSearchSessionId, getExecutionContext }) {
fn(
input,
args,
{ inspectorAdapters, abortSignal, getSearchSessionId, getExecutionContext, getSearchContext }
) {
return defer(async () => {
const { aggs, indexPatterns, searchSource, getNow } = await getStartDependencies();
@ -52,6 +56,8 @@ export function getFunctionDefinition({
return { aggConfigs, indexPattern, searchSource, getNow, handleEsaggsRequest };
}).pipe(
switchMap(({ aggConfigs, indexPattern, searchSource, getNow, handleEsaggsRequest }) => {
const { disableShardWarnings } = getSearchContext();
return handleEsaggsRequest({
abortSignal,
aggs: aggConfigs,
@ -63,6 +69,7 @@ export function getFunctionDefinition({
searchSourceService: searchSource,
timeFields: args.timeFields,
timeRange: get(input, 'timeRange', undefined),
disableShardWarnings: (disableShardWarnings || false) as boolean,
getNow,
executionContext: getExecutionContext(),
});

View file

@ -58,7 +58,7 @@ describe('esaggs expression function - server', () => {
mockHandlers = {
abortSignal: jest.fn() as unknown as jest.Mocked<AbortSignal>,
getKibanaRequest: jest.fn().mockReturnValue({ id: 'hi' } as KibanaRequest),
getSearchContext: jest.fn(),
getSearchContext: jest.fn().mockReturnValue({}),
getSearchSessionId: jest.fn().mockReturnValue('abc123'),
getExecutionContext: jest.fn(),
inspectorAdapters: jest.fn(),
@ -130,6 +130,7 @@ describe('esaggs expression function - server', () => {
query: undefined,
searchSessionId: 'abc123',
searchSourceService: startDependencies.searchSource,
disableShardWarnings: false,
timeFields: args.timeFields,
timeRange: undefined,
});

View file

@ -72,6 +72,7 @@ export function getFunctionDefinition({
query: get(input, 'query', undefined) as any,
searchSessionId: getSearchSessionId(),
searchSourceService: searchSource,
disableShardWarnings: false,
timeFields: args.timeFields,
timeRange: get(input, 'timeRange', undefined),
})