Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] fix PPL to not throw error if aggregation query fails #8992

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading