From 08da159ccec7c37fcea4470bab7663a0b3b8e97c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 2 Nov 2024 21:12:30 +0000 Subject: [PATCH] [Traces] Return 503 if opensearch calls failed (#2238) (cherry picked from commit 8c0face1263253bda45d9f1e30cfb8de2eabc996) Signed-off-by: github-actions[bot] --- server/plugin.ts | 7 ++++++- server/routes/dsl.ts | 18 +++++++++--------- server/routes/index.ts | 6 ++++-- server/services/queryService.ts | 3 ++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/server/plugin.ts b/server/plugin.ts index 8310902ad..7cb11fc87 100644 --- a/server/plugin.ts +++ b/server/plugin.ts @@ -219,7 +219,12 @@ export class ObservabilityPlugin core.savedObjects.registerType(integrationTemplateType); // Register server side APIs - setupRoutes({ router, client: openSearchObservabilityClient, dataSourceEnabled }); + setupRoutes({ + router, + client: openSearchObservabilityClient, + dataSourceEnabled, + logger: this.logger, + }); core.savedObjects.registerType(getVisualizationSavedObject(dataSourceEnabled)); core.savedObjects.registerType(getSearchSavedObject(dataSourceEnabled)); diff --git a/server/routes/dsl.ts b/server/routes/dsl.ts index 43bec95f1..6318dccc0 100644 --- a/server/routes/dsl.ts +++ b/server/routes/dsl.ts @@ -42,7 +42,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -71,7 +71,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -95,7 +95,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -119,7 +119,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -158,7 +158,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -194,7 +194,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -230,7 +230,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -263,7 +263,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } @@ -298,7 +298,7 @@ export function registerDslRoute( } catch (error) { if (error.statusCode !== 404) console.error(error); return response.custom({ - statusCode: error.statusCode || 500, + statusCode: error.statusCode === 500 ? 503 : error.statusCode || 503, body: error.message, }); } diff --git a/server/routes/index.ts b/server/routes/index.ts index 696578ab1..d124941b2 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ILegacyClusterClient, IRouter } from '../../../../src/core/server'; +import { ILegacyClusterClient, IRouter, Logger } from '../../../../src/core/server'; import { DSLFacet } from '../services/facets/dsl_facet'; import { PPLFacet } from '../services/facets/ppl_facet'; import SavedObjectFacet from '../services/facets/saved_objects'; @@ -30,10 +30,12 @@ export function setupRoutes({ router, client, dataSourceEnabled, + logger, }: { router: IRouter; client: ILegacyClusterClient; dataSourceEnabled: boolean; + logger: Logger; }) { PanelsRouter(router); VisualizationsRouter(router); @@ -49,7 +51,7 @@ export function setupRoutes({ registerParaRoute(router); registerNoteRoute(router); registerVizRoute(router, dataSourceEnabled); - const queryService = new QueryService(client); + const queryService = new QueryService(client, logger); registerSqlRoute(router, queryService, dataSourceEnabled); registerMetricsRoute(router, dataSourceEnabled); diff --git a/server/services/queryService.ts b/server/services/queryService.ts index d11e66621..2c8a5d004 100644 --- a/server/services/queryService.ts +++ b/server/services/queryService.ts @@ -6,10 +6,11 @@ import 'core-js/stable'; import _ from 'lodash'; import 'regenerator-runtime/runtime'; +import { Logger } from '../../../../src/core/server'; export class QueryService { private client: any; - constructor(client: any) { + constructor(client: any, private readonly logger: Logger) { this.client = client; }