-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core capabilities: improve the performances of
resolveCapabilities
(#…
…170454) ## Summary Fix #146881 Introduce the concept of "capability path" to Core's capabilities API, and rely on it to perform various performance optimization during capabilities resolving. ### API Changes #### CapabilitiesSetup.registerSwitcher A new mandatory `capabilityPath` option was added to the API signature. Plugins registering capability switchers must now define the path(s) of capabilities the switcher will impact. E.g a live example with the `ml` capabilities switcher that was only mutating `ml.{something}` capabilities: *Before:* ```ts coreSetup.capabilities.registerSwitcher(getSwitcher(license$, logger, enabledFeatures)); ``` *After:* ```ts coreSetup.capabilities.registerSwitcher(getSwitcher(license$, logger, enabledFeatures), { capabilityPath: 'ml.*', }); ``` #### CapabilitiesStart.resolveCapabilities The `resolveCapabilities` was also changed accordingly, forcing API consumers to specify the path(s) of capabilities they're planning to access. E.g for the `ml` plugin's capabilities resolving *Before:* ```ts const capabilities = await this.capabilities.resolveCapabilities(request); return capabilities.ml as MlCapabilities; ``` *After:* ```ts const capabilities = await this.capabilities.resolveCapabilities(request, { capabilityPath: 'ml.*', }); return capabilities.ml as MlCapabilities; ``` ### Performance optimizations Knowing which capability path(s) the switchers are impacting and which capability path(s) the resolver wants to use allow us to optimize the way we're chaining the resolvers during the `resolveCapabilities` internal implementation: #### 1. We only apply switchers that may impact the paths the resolver requested E.g when requesting the ml capabilities, we now only apply the `ml`, `security` and `spaces` switchers. #### 2. We can call non-intersecting switchers in parallel Before, all switchers were executed in sequence. With these changes, we now group non-intersecting switchers to resolve them in parallel. E.g the `ml` (`ml.*`) and `fileUpload` (`fileUpload.*`) can be executed and applied in parallel because they're not touching the same set of capabilities. --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
7ba20f6
commit 8b7c677
Showing
34 changed files
with
1,249 additions
and
303 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
18 changes: 18 additions & 0 deletions
18
...ore/capabilities/core-capabilities-server-internal/src/resolve_capabilities.test.mocks.ts
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,18 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
const actualHelpers = jest.requireActual('./resolve_helpers'); | ||
|
||
export const splitIntoBucketsMock = jest.fn().mockImplementation(actualHelpers.splitIntoBuckets); | ||
|
||
jest.doMock('./resolve_helpers', () => { | ||
return { | ||
...actualHelpers, | ||
splitIntoBuckets: splitIntoBucketsMock, | ||
}; | ||
}); |
Oops, something went wrong.