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.x] [Traces] Return 503 if opensearch calls failed #2243

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
18 changes: 9 additions & 9 deletions server/routes/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand All @@ -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,
});
}
Expand All @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand Down Expand Up @@ -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,
});
}
Expand Down
6 changes: 4 additions & 2 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,10 +30,12 @@ export function setupRoutes({
router,
client,
dataSourceEnabled,
logger,
}: {
router: IRouter;
client: ILegacyClusterClient;
dataSourceEnabled: boolean;
logger: Logger;
}) {
PanelsRouter(router);
VisualizationsRouter(router);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion server/services/queryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
import 'core-js/stable';
import _ from 'lodash';
import 'regenerator-runtime/runtime';
import { Logger } from '../../../../src/core/server';

export class QueryService {
private client: any;

Check warning on line 12 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
constructor(client: any) {
constructor(client: any, private readonly logger: Logger) {

Check warning on line 13 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
this.client = client;
}

describeQueryInternal = async (
request: any,

Check warning on line 18 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
format: string,
responseFormat: string,
context: any

Check warning on line 21 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
) => {
try {
const queryRequest = {
Expand Down Expand Up @@ -57,11 +58,11 @@
}
};

describeSQLQuery = async (context: any, request: any) => {

Check warning on line 61 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 61 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.describeQueryInternal(request, 'ppl.sqlQuery', 'json', context);
};

describePPLQuery = async (context: any, request: any) => {

Check warning on line 65 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 65 in server/services/queryService.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return this.describeQueryInternal(request, 'ppl.pplQuery', 'json', context);
};
}
Loading