Skip to content

Commit

Permalink
[Discover] fix PPL to not throw error if aggregation query fails (ope…
Browse files Browse the repository at this point in the history
…nsearch-project#8992)

Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 authored and wanglam committed Dec 4, 2024
1 parent c679f68 commit 1222bff
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/plugins/query_enhancements/common/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { handleFacetError } from './utils';
import { throwFacetError } from './utils';

describe('handleFacetError', () => {
const error = new Error('mock-error');
Expand All @@ -16,9 +16,9 @@ describe('handleFacetError', () => {
data: error,
};

expect(() => handleFacetError(response)).toThrowError();
expect(() => throwFacetError(response)).toThrowError();
try {
handleFacetError(response);
throwFacetError(response);
} catch (err: any) {
expect(err.message).toBe('test error message');
expect(err.name).toBe('400');
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/query_enhancements/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const removeKeyword = (queryString: string | undefined) => {
return queryString?.replace(new RegExp('.keyword'), '') ?? '';
};

export const handleFacetError = (response: any) => {
export const throwFacetError = (response: any) => {
const error = new Error(response.data.body?.message ?? response.data.body ?? response.data);
error.name = response.data.status ?? response.status ?? response.data.statusCode;
(error as any).status = error.name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Query,
} from '../../../data/common';
import { ISearchStrategy, SearchUsage } from '../../../data/server';
import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common';
import { buildQueryStatusConfig, getFields, throwFacetError, SEARCH_STRATEGY } from '../../common';
import { Facet } from '../utils';

export const pplAsyncSearchStrategyProvider = (
Expand Down Expand Up @@ -45,7 +45,7 @@ export const pplAsyncSearchStrategyProvider = (
request.body = { ...request.body, lang: SEARCH_STRATEGY.PPL };
const rawResponse: any = await pplAsyncFacet.describeQuery(context, request);

if (!rawResponse.success) handleFacetError(rawResponse);
if (!rawResponse.success) throwFacetError(rawResponse);

const statusConfig = buildQueryStatusConfig(rawResponse);

Expand All @@ -60,7 +60,7 @@ export const pplAsyncSearchStrategyProvider = (
request.params = { queryId: inProgressQueryId };
const queryStatusResponse = await pplAsyncJobsFacet.describeQuery(context, request);

if (!queryStatusResponse.success) handleFacetError(queryStatusResponse);
if (!queryStatusResponse.success) throwFacetError(queryStatusResponse);

const queryStatus = queryStatusResponse.data?.status;
logger.info(`pplAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`);
Expand Down
Loading

0 comments on commit 1222bff

Please sign in to comment.