mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Profiling] Auto-abort requests (#142750)
This commit is contained in:
parent
115039d452
commit
c05190e516
11 changed files with 204 additions and 134 deletions
|
@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { RouteRegisterParameters } from '.';
|
||||
import { getRoutePaths } from '../../common';
|
||||
import { createCalleeTree } from '../../common/callee';
|
||||
import { handleRouteHandlerError } from '../utils/handle_route_error_handler';
|
||||
import { createBaseFlameGraph } from '../../common/flamegraph';
|
||||
import { createProfilingEsClient } from '../utils/create_profiling_es_client';
|
||||
import { withProfilingSpan } from '../utils/with_profiling_span';
|
||||
|
@ -71,14 +72,8 @@ export function registerFlameChartSearchRoute({ router, logger }: RouteRegisterP
|
|||
logger.info('returning payload response to client');
|
||||
|
||||
return response.ok({ body: flamegraph });
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return response.customError({
|
||||
statusCode: e.statusCode ?? 500,
|
||||
body: {
|
||||
message: e.message,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return handleRouteHandlerError({ error, logger, response });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -9,6 +9,7 @@ import { schema, TypeOf } from '@kbn/config-schema';
|
|||
import { RouteRegisterParameters } from '.';
|
||||
import { getRoutePaths } from '../../common';
|
||||
import { createTopNFunctions } from '../../common/functions';
|
||||
import { handleRouteHandlerError } from '../utils/handle_route_error_handler';
|
||||
import { createProfilingEsClient } from '../utils/create_profiling_es_client';
|
||||
import { withProfilingSpan } from '../utils/with_profiling_span';
|
||||
import { getClient } from './compat';
|
||||
|
@ -72,14 +73,8 @@ export function registerTopNFunctionsSearchRoute({ router, logger }: RouteRegist
|
|||
return response.ok({
|
||||
body: topNFunctions,
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
return response.customError({
|
||||
statusCode: e.statusCode ?? 500,
|
||||
body: {
|
||||
message: e.message,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return handleRouteHandlerError({ error, logger, response });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ import { computeBucketWidthFromTimeRangeAndBucketCount } from '../../common/hist
|
|||
import { groupStackFrameMetadataByStackTrace, StackTraceID } from '../../common/profiling';
|
||||
import { getFieldNameForTopNType, TopNType } from '../../common/stack_traces';
|
||||
import { createTopNSamples, getTopNAggregationRequest, TopNResponse } from '../../common/topn';
|
||||
import { handleRouteHandlerError } from '../utils/handle_route_error_handler';
|
||||
import { ProfilingRequestHandlerContext } from '../types';
|
||||
import { createProfilingEsClient, ProfilingESClient } from '../utils/create_profiling_es_client';
|
||||
import { withProfilingSpan } from '../utils/with_profiling_span';
|
||||
|
@ -189,15 +190,8 @@ export function queryTopNCommon(
|
|||
kuery,
|
||||
}),
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
|
||||
return response.customError({
|
||||
statusCode: e.statusCode ?? 500,
|
||||
body: {
|
||||
message: 'Profiling TopN request failed: ' + e.message + '; full error ' + e.toString(),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return handleRouteHandlerError({ error, logger, response });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { KibanaResponseFactory } from '@kbn/core-http-server';
|
||||
import { Logger } from '@kbn/logging';
|
||||
import { WrappedElasticsearchClientError } from '@kbn/observability-plugin/server';
|
||||
import { errors } from '@elastic/elasticsearch';
|
||||
|
||||
export function handleRouteHandlerError({
|
||||
error,
|
||||
logger,
|
||||
response,
|
||||
}: {
|
||||
error: any;
|
||||
response: KibanaResponseFactory;
|
||||
logger: Logger;
|
||||
}) {
|
||||
if (
|
||||
error instanceof WrappedElasticsearchClientError &&
|
||||
error.originalError instanceof errors.RequestAbortedError
|
||||
) {
|
||||
return response.custom({
|
||||
statusCode: 499,
|
||||
body: {
|
||||
message: 'Client closed request',
|
||||
},
|
||||
});
|
||||
}
|
||||
logger.error(error);
|
||||
|
||||
return response.customError({
|
||||
statusCode: error.statusCode ?? 500,
|
||||
body: {
|
||||
message: error.message,
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue