Skip to content

Commit

Permalink
updating trace DSL request handler (opensearch-project#494)
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 authored May 26, 2023
1 parent 1a69765 commit d282d40
Showing 1 changed file with 33 additions and 17 deletions.
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

0 comments on commit d282d40

Please sign in to comment.