forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Profiling] Add APIs to clear frame and executable caches (elastic#14…
…5499) This PR adds two endpoints to clear each respective cache: * `DELETE {BASE_KIBANA_PATH}/api/profiling/v1/cache/executables` * `DELETE {BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes` Related to https://github.com/elastic/prodfiler/issues/2759 #### Design choices 1. The `DELETE` method was chosen instead of `PUT` or `POST` since the given semantics of `DELETE` matches the expected behavior for the related issue. 2. Each endpoint will remove all items from the respective cache. A separate API for each cache allows us to selectively clear the necessary cache without the downsides of a catch-all endpoint to clear all caches. This gives us the flexibility to add more endpoints if needed. Given the tradeoff between complexity now or later, it was decided to implement general invalidation now with the option to invalidate specific items later. 3. The RESTful design allows us to clear specific items later (e.g. `DELETE {BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}` could clear only executable `ID` from the cache). 4. Each endpoint returns an empty payload on success. However, the Kibana logs reflect the actions taken and how many cache items were affected. 5. The stacktrace cache was ignored since it was not affected by symbols written to Elasticsearch. 6. Each endpoint is not directly accessible from UI since it is expected that the endpoints will be called outside of Kibana. However, the endpoints can be called manually from the browser's console.
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { RouteRegisterParameters } from '.'; | ||
import { getRoutePaths } from '../../common'; | ||
import { handleRouteHandlerError } from '../utils/handle_route_error_handler'; | ||
import { clearExecutableCache, clearStackFrameCache } from './stacktrace'; | ||
|
||
export function registerCacheExecutablesRoute({ router, logger }: RouteRegisterParameters) { | ||
const paths = getRoutePaths(); | ||
router.delete( | ||
{ | ||
path: paths.CacheExecutables, | ||
validate: {}, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
logger.info(`clearing executable cache`); | ||
const numDeleted = clearExecutableCache(); | ||
logger.info(`removed ${numDeleted} executables from cache`); | ||
|
||
return response.ok({}); | ||
} catch (error) { | ||
return handleRouteHandlerError({ error, logger, response }); | ||
} | ||
} | ||
); | ||
} | ||
|
||
export function registerCacheStackFramesRoute({ router, logger }: RouteRegisterParameters) { | ||
const paths = getRoutePaths(); | ||
router.delete( | ||
{ | ||
path: paths.CacheStackFrames, | ||
validate: {}, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
logger.info(`clearing stackframe cache`); | ||
const numDeleted = clearStackFrameCache(); | ||
logger.info(`removed ${numDeleted} stackframes from cache`); | ||
|
||
return response.ok({}); | ||
} catch (error) { | ||
return handleRouteHandlerError({ error, logger, response }); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters