Skip to content

Commit

Permalink
updating trace DSL request handler (opensearch-project#494) (opensear…
Browse files Browse the repository at this point in the history
…ch-project#495)

Signed-off-by: Shenoy Pratik <[email protected]>
(cherry picked from commit d282d40)

Co-authored-by: Shenoy Pratik <[email protected]>
(cherry picked from commit eaa3c15)
  • Loading branch information
opensearch-trigger-bot[bot] authored and A9 Swift Project User committed Aug 9, 2023
1 parent 856d333 commit ea710b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions auto_sync_commit_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"last_github_commit": "da169ae280bba79fc770145d9d24e7da375db13a",
"last_gitfarm_commit": "1d38abc963aecb4914379726031f9e51b94bd69c"
"last_github_commit": "eaa3c153ce678b18481a00e355243047b70aa5d4",
"last_gitfarm_commit": "587df0d03e4cd61ffcf2e03518ea40b738538bd2"
}
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 ea710b5

Please sign in to comment.