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

Cache _xpack/usage #96726

Open
kostasb opened this issue Apr 12, 2021 · 8 comments
Open

Cache _xpack/usage #96726

kostasb opened this issue Apr 12, 2021 · 8 comments
Labels
discuss Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@kostasb
Copy link

kostasb commented Apr 12, 2021

Describe the enhancements:

Cache the output of _xpack/usage Elasticsearch API for a reasonable amount of time (i.e. 10 minutes), to avoid sending this request too often to Elasticsearch. The output could change in case there are changes to Elasticsearch but leave Kibana running, so Kibana could potentially have a stale version of that cached response, for as long as it caches it. Since this call is made from numerous places in Kibana, it makes sense to move this into core platform somewhere, as opposed to i.e. just alerting.

Describe a specific use case for the feature:

A number of views and features in Kibana perform an auth/capabilities check against Elasticsearch's _xpack/usage API.

With a high concurrent number of users in Kibana, these calls can be repeated at a high rate. In case the Elasticsearch master nodes are under load and slow to respond to those calls, Kibana may time out and fail to render the relevant views.

@kostasb kostasb added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:AppServices labels Apr 12, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@pgayvallet
Copy link
Contributor

pgayvallet commented Apr 12, 2021

it makes sense to move this into core platform somewhere

We can't easily introduce a cache mechanism at the ES client level, so this would have to be implemented by the API consumers directly.

Since this call is made from numerous places in Kibana

Seems in opposition with the issue's description, but from a quick grep, seems the only consumer of this API I could find is

export async function getXPackUsage(esClient: ElasticsearchClient) {
const { body } = await esClient.xpack.usage({ master_timeout: TIMEOUT });

@mshustov
Copy link
Contributor

mshustov commented Apr 12, 2021

It's used by Security plugin as well

.request({ method: 'GET', path: '/_xpack/usage' })

cc @elastic/kibana-security as code owner of the check

@DaveCTurner
Copy link

DaveCTurner commented Apr 12, 2021

FWIW I think there is room for improvement in Elasticsearch too (in addition to any changes in Kibana proposed here). GET _xpack/usage should be fairly lightweight but it seems it isn't in some places, particularly:

  • VectorsFeatureSet
  • FlattenedFeatureSet
  • RuntimeFieldsFeatureSet

I believe we could implement some caching in Elasticsearch for these computations, although I think the only one that's still in play in 7.13 is VectorsFeatureSet anyway, the other two have already been removed.

The cluster in question was also busy serving various get-mappings requests, which uses the same threadpool and can also be quite heavy.

In addition, today in Elasticsearch we don't cancel this work on a client-side timeout (neither get-mappings nor get-xpack-usage) which means that if a backlog builds up then working through it can take a long time and a lot of wasted effort. We have the infrastructure needed to cancel things on client-side timeouts, we just haven't applied it to these particular endpoints yet.

If you think it would help to streamline things in Elasticsearch then please feel free to open issues suggesting:

  1. caching so that VectorsFeatureSet#usage does not need to iterate all the mappings on each call, and
  2. adding support for client-side cancellability to the get-mappings and get-xpack-usage APIs.

@mikecote
Copy link
Contributor

cc @elastic/kibana-alerting-services

@legrego
Copy link
Member

legrego commented Apr 12, 2021

Not sure if this would have any performance implications, but a related request for this endpoint is to allow it to run against the local node instead of forcing the request to get routed to the master node: elastic/elasticsearch#53916

The security plugin's usage that @mshustov pointed out above would ideally use this "local" information if it was made available.

@afharo
Copy link
Member

afharo commented Apr 14, 2021

The telemetry use-case calls it once every 24h per sender. #87846 would ensure it's called only once every 24h overall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

9 participants