From 2aa590a8e59f3cbd9c8581afa954b9d75796eafc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 5 Sep 2024 16:31:06 +0000 Subject: [PATCH] [query assist] update ml-commons response schema (#2124) * [query assist] update ml-commons response schema processing Signed-off-by: Joshua Li * disable query assist routes when data source is enabled Signed-off-by: Joshua Li --------- Signed-off-by: Joshua Li (cherry picked from commit acff04b9249359a0f7ab11fbdd4aa9965dc09b67) Signed-off-by: github-actions[bot] --- server/routes/index.ts | 7 ++++++- server/routes/query_assist/routes.ts | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/routes/index.ts b/server/routes/index.ts index ef1082993..696578ab1 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -56,6 +56,11 @@ export function setupRoutes({ registerIntegrationsRoute(router); registerDataConnectionsRoute(router, dataSourceEnabled); registerDatasourcesRoute(router, dataSourceEnabled); - registerQueryAssistRoutes(router); + + // query assist is part of log explorer, which will be disabled if datasource is enabled + if (!dataSourceEnabled) { + registerQueryAssistRoutes(router); + } + registerGettingStartedRoutes(router); } diff --git a/server/routes/query_assist/routes.ts b/server/routes/query_assist/routes.ts index a3e5b0bed..d34d5256d 100644 --- a/server/routes/query_assist/routes.ts +++ b/server/routes/query_assist/routes.ts @@ -83,11 +83,15 @@ export function registerQueryAssistRoutes(router: IRouter) { if ( isResponseError(error) && error.statusCode === 400 && - error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED) + // on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858 + JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED) ) { return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED }); } - return response.custom({ statusCode: error.statusCode || 500, body: error.message }); + return response.custom({ + statusCode: error.statusCode || 500, + body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body), + }); } } ); @@ -155,11 +159,15 @@ export function registerQueryAssistRoutes(router: IRouter) { if ( isResponseError(error) && error.statusCode === 400 && - error.body.includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED) + // on opensearch >= 2.17, error.body is an object https://github.com/opensearch-project/ml-commons/pull/2858 + JSON.stringify(error.body).includes(ERROR_DETAILS.GUARDRAILS_TRIGGERED) ) { return response.badRequest({ body: ERROR_DETAILS.GUARDRAILS_TRIGGERED }); } - return response.custom({ statusCode: error.statusCode || 500, body: error.message }); + return response.custom({ + statusCode: error.statusCode || 500, + body: typeof error.body === 'string' ? error.body : JSON.stringify(error.body), + }); } } );