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

[Backport 2.7] Updating trace DSL request handler #519

Closed
wants to merge 1 commit into from
Closed
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
50 changes: 33 additions & 17 deletions public/components/trace_analytics/requests/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable no-console */

import { CoreStart } from '../../../../../../src/core/public';
import {
TRACE_ANALYTICS_DSL_ROUTE,
TRACE_ANALYTICS_DATA_PREPPER_INDICES_ROUTE,
TRACE_ANALYTICS_JAEGER_INDICES_ROUTE,
JAEGER_INDEX_NAME,
DATA_PREPPER_INDEX_NAME
DATA_PREPPER_INDEX_NAME,
} from '../../../../common/constants/trace_analytics';
import { TraceAnalyticsMode } from '../home';

export function handleDslRequest(http: CoreStart['http'], DSL: any, bodyQuery: any, mode: TraceAnalyticsMode, timeout?: boolean, setShowTimeoutToast?: () => void) {
export async function handleDslRequest(
http: CoreStart['http'],
DSL: any,
bodyQuery: any,
mode: TraceAnalyticsMode,
timeout?: boolean,
setShowTimeoutToast?: () => void
) {
if (DSL?.query) {
bodyQuery.query.bool.must.push(...DSL.query.bool.must);
bodyQuery.query.bool.filter.push(...DSL.query.bool.filter);
Expand All @@ -25,35 +31,45 @@ export function handleDslRequest(http: CoreStart['http'], DSL: any, bodyQuery: a
}
let body = bodyQuery;
if (!bodyQuery.index) {
body = {...bodyQuery, index: ((mode === 'jaeger' ? JAEGER_INDEX_NAME : DATA_PREPPER_INDEX_NAME)) }
body = { ...bodyQuery, index: mode === 'jaeger' ? JAEGER_INDEX_NAME : DATA_PREPPER_INDEX_NAME };
}
if (timeout) {
const id = setTimeout(() => setShowTimeoutToast!(), 30000);
return http
.post(TRACE_ANALYTICS_DSL_ROUTE, {

try {
return await http.post(TRACE_ANALYTICS_DSL_ROUTE, {
body: JSON.stringify(body),
})
.catch((error) => {
console.error(error)
})
.finally(() => clearTimeout(id));
});
} catch (error) {
console.error(error);
} finally {
clearTimeout(id);
}
}

return http
.post(TRACE_ANALYTICS_DSL_ROUTE, {
try {
return await http.post(TRACE_ANALYTICS_DSL_ROUTE, {
body: JSON.stringify(body),
})
.catch((error) => console.error(error));
});
} catch (error_1) {
console.error(error_1);
}
}

export async function handleJaegerIndicesExistRequest(http: CoreStart['http'], setJaegerIndicesExist) {
export async function handleJaegerIndicesExistRequest(
http: CoreStart['http'],
setJaegerIndicesExist
) {
http
.post(TRACE_ANALYTICS_JAEGER_INDICES_ROUTE)
.then((exists) => setJaegerIndicesExist(exists))
.catch(() => setJaegerIndicesExist(false));
}

export async function handleDataPrepperIndicesExistRequest(http: CoreStart['http'], setDataPrepperIndicesExist) {
export async function handleDataPrepperIndicesExistRequest(
http: CoreStart['http'],
setDataPrepperIndicesExist
) {
http
.post(TRACE_ANALYTICS_DATA_PREPPER_INDICES_ROUTE)
.then((exists) => setDataPrepperIndicesExist(exists))
Expand Down