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

[Profiling] Add APIs to clear frame and executable caches #145499

Merged
merged 1 commit into from
Nov 17, 2022

Conversation

jbcrail
Copy link
Contributor

@jbcrail jbcrail commented Nov 17, 2022

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.

The two new endpoints will clear each respective cache.
@jbcrail jbcrail requested a review from a team as a code owner November 17, 2022 01:12
@jbcrail jbcrail added release_note:skip Skip the PR/issue when compiling release notes v8.6.0 labels Nov 17, 2022
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
profiling 13.2KB 13.3KB +110.0B
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 59 65 +6
osquery 108 113 +5
securitySolution 441 447 +6
total +19

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 67 73 +6
osquery 109 115 +6
securitySolution 518 524 +6
total +20

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dgieselaar
Copy link
Member

@jbcrail What happens if multiple kibana instances are running? Is there a way to clear the cache for all instances?

@rockdaboot
Copy link
Contributor

@jbcrail What happens if multiple kibana instances are running? Is there a way to clear the cache for all instances?

@dgieselaar How does a client find out about multiple Kibana instances ? If that is possible, the client could take care of that, in case Kibana instances doesn't know of each other.
Can you give a bit of background/details/links on how "multiple Kibana instances" work conceptually ?

@dgieselaar
Copy link
Member

@rockdaboot It's fairly simple, multiple kibana instances in a cluster can handle a request, via presumably something similar to round-robin. Cache will be local to the kibana instance, so the user has to call this endpoint multiple times in the case of multiple kibana instances. Two things we can possibly improve here:

  • use a saved object to store a cache invalidation time, and when accessing the cache, fetch the saved object first (should be very cheap, single-digit ms assuming there is no resource contention), and check the timestamp of the saved object vs the time of when the cache was created. a little costly to implement, you have to register a saved object type etc.
  • have the endpoint return whether cache was actually cleared so the user sorta knows when to stop calling the endpoint. still not great though, but cheap to implement.

@rockdaboot
Copy link
Contributor

@rockdaboot It's fairly simple, multiple kibana instances in a cluster can handle a request, via presumably something similar to round-robin. Cache will be local to the kibana instance, so the user has to call this endpoint multiple times in the case of multiple kibana instances. Two things we can possibly improve here:

* use a saved object to store a cache invalidation time, and when accessing the cache, fetch the saved object first (should be very cheap, single-digit ms assuming there is no resource contention), and check the timestamp of the saved object vs the time of when the cache was created. a little costly to implement, you have to register a saved object type etc.

* have the endpoint return whether cache was actually cleared so the user sorta knows when to stop calling the endpoint. still not great though, but cheap to implement.

Thanks Dario.
We have an invalidation time per cache record currently. It just doesn't work when a user ingests symbols and directly switches over to the UI to click 'Refresh'.
Multiple Kibana instances possibly need a shared cache in the long term, that might become pretty hairy quickly.
But given that we switch to using an ES plugin soon (Daniel is working on it, maybe for ES 8.7.0), we will likely have a central cache in ES - if needed at all.

Copy link
Contributor

@rockdaboot rockdaboot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you !

@rockdaboot rockdaboot merged commit 642ab74 into elastic:main Nov 17, 2022
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 17, 2022
…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.

(cherry picked from commit 642ab74)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Nov 17, 2022
…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.

(cherry picked from commit 642ab74)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.5
8.6

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Nov 17, 2022
) (#145525)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Profiling] Add APIs to clear frame and executable caches
(#145499)](#145499)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Joseph
Crail","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-17T10:04:58Z","message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.6.0","v8.7.0","v8.5.2"],"number":145499,"url":"https://github.com/elastic/kibana/pull/145499","mergeCommit":{"message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7"}},"sourceBranch":"main","suggestedTargetBranches":["8.6","8.5"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145499","number":145499,"mergeCommit":{"message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7"}},{"branch":"8.5","label":"v8.5.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Joseph Crail <[email protected]>
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 18, 2022
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.

kibanamachine added a commit that referenced this pull request Nov 18, 2022
) (#145524)

# Backport

This will backport the following commits from `main` to `8.5`:
- [[Profiling] Add APIs to clear frame and executable caches
(#145499)](#145499)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Joseph
Crail","email":"[email protected]"},"sourceCommit":{"committedDate":"2022-11-17T10:04:58Z","message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v8.6.0","v8.7.0","v8.5.2"],"number":145499,"url":"https://github.com/elastic/kibana/pull/145499","mergeCommit":{"message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7"}},"sourceBranch":"main","suggestedTargetBranches":["8.6","8.5"],"targetPullRequestStates":[{"branch":"8.6","label":"v8.6.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/145499","number":145499,"mergeCommit":{"message":"[Profiling]
Add APIs to clear frame and executable caches (#145499)\n\nThis PR adds
two endpoints to clear each respective cache:\r\n\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables`\r\n* `DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/stackframes`\r\n\r\nRelated to
https://github.com/elastic/prodfiler/issues/2759\r\n\r\n#### Design
choices\r\n\r\n1. The `DELETE` method was chosen instead of `PUT` or
`POST` since the\r\ngiven semantics of `DELETE` matches the expected
behavior for the\r\nrelated issue.\r\n2. Each endpoint will remove all
items from the respective cache. A\r\nseparate API for each cache allows
us to selectively clear the necessary\r\ncache without the downsides of
a catch-all endpoint to clear all caches.\r\nThis gives us the
flexibility to add more endpoints if needed. Given the\r\ntradeoff
between complexity now or later, it was decided to implement\r\ngeneral
invalidation now with the option to invalidate specific
items\r\nlater.\r\n3. The RESTful design allows us to clear specific
items later (e.g.\r\n`DELETE
{BASE_KIBANA_PATH}/api/profiling/v1/cache/executables/{ID}`\r\ncould
clear only executable `ID` from the cache).\r\n4. Each endpoint returns
an empty payload on success. However, the\r\nKibana logs reflect the
actions taken and how many cache items were\r\naffected.\r\n5. The
stacktrace cache was ignored since it was not affected by
symbols\r\nwritten to Elasticsearch.\r\n6. Each endpoint is not directly
accessible from UI since it is expected\r\nthat the endpoints will be
called outside of Kibana. However, the\r\nendpoints can be called
manually from the browser's
console.","sha":"642ab74cfc1a4ef5c0a2dfdadf00bd3792f780a7"}},{"branch":"8.5","label":"v8.5.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Joseph Crail <[email protected]>
Co-authored-by: Tim Rühsen <[email protected]>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 18, 2022
@jbcrail jbcrail deleted the api-to-clear-caches branch February 3, 2023 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes v8.5.2 v8.6.0 v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants