-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Spaces - NP updates for usage collection and capabilities #57693
Conversation
Pinging @elastic/kibana-security (Team:Security) |
@elasticmachine merge upstream |
const isAnonymousRequest = !request.route.options.authRequired; | ||
|
||
if (isAnonymousRequest) { | ||
return capabilities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing implementation behaved this way, but it wasn't explicit. We used to silently return the capabilities unmodified if an error was thrown here. If an unauthenticated route attempts to retrieve the active space, the request fails because auth headers aren't attached to the request.
There's a subtle distinction though. The existing implementation would still toggle capabilities for anonymous requests when security was disabled. Now, we will always skip this step. I think this is actually preferred, because we'll have consistent behavior between the two setups (spaces, spaces + security)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree, thanks for explaining!
ACK: sorry for the delay, will review tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes look good and thanks for adding more tests! PR is marked as Draft
so I haven't tested changes locally yet, but let me know if you just forgot to toggle PR state and it's ready to be tested.
deps.features, | ||
available | ||
); | ||
const kibanaIndex = (await deps.kibanaIndexConfig.pipe(take(1)).toPromise()).kibana.index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional nit: we can combine license$
and deps.kibanaIndexConfig$
to have just one pipe(take(1)).toPromise()
, but it's not a big deal at all. Both approaches has benefits and drawbacks.
x-pack/plugins/spaces/server/capabilities/capabilities_switcher.ts
Outdated
Show resolved
Hide resolved
const isAnonymousRequest = !request.route.options.authRequired; | ||
|
||
if (isAnonymousRequest) { | ||
return capabilities; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree, thanks for explaining!
x-pack/plugins/spaces/server/lib/request_interceptors/on_request_interceptor.ts
Show resolved
Hide resolved
@azasypkin thanks for your initial feedback - ready for final review! |
ACK: will review tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for platform changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulse changes LGTM!
Thank you for adding the mock!
logger: loggingServiceMock.createLogger(), | ||
maximumWaitTimeForAllCollectorsInS: 1, | ||
}), | ||
registerLegacySavedObjects: jest.fn() as jest.Mocked< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating the mock for us!
FYI: This method is about to be removed in #58401 😉
Which is about to be merged (waiting for a second review from another Pulse team member to merge it. Sometime today or tomorrow) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads-up. It looks like this will merge before #58401, so would you be ok removing the mock in your PR? I could drop it now, but then I'd have to suppress a TS warning about an incompatible interface, so you'd have to alter this file no matter what :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely! It's a simple removal :)
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
) * remove kibanaIndex from LegacyAPI * moving capabilities, adding tests * moving usage collection * cleanup * don't toggle capabilities on unauthenticated routes * reintroduce exception handling * pipe dat config * start addressing PR feedback * fix CoreSetup's generic type * fix usage collector tests * PR review updates Co-authored-by: Elastic Machine <[email protected]>
* [Telemetry] Report the Application Usage (time of usage + number of clicks) * Add Unit tests to the server side * Do not use optional chaining in JS * Add tests on the public end * Fix jslint errors * jest.useFakeTimers() + jest.clearAllTimers() * Remove Jest timer handlers from my tests (only affecting to a minimum coverage bit) * Catch ES actions in the setup/start steps because it broke core_services tests * Fix boolean check * Use core's ES.adminCLient over .createClient * Fix tests after ES.adminClient * [Telemetry] Application Usage implemented in kbn-analytics * Use bulkCreate in store_report * ApplicationUsagePluginStart does not exist anymore * Fix usage_collection mock interface * Check there is something to store before calling the bulkCreate method * Add unit tests * Fix types in tests * Unit tests for rollTotals and actual fix for the bug found * Fix usage_collection mock after #57693 got merged Co-authored-by: Elastic Machine <[email protected]>
…58401) * [Telemetry] Report the Application Usage (time of usage + number of clicks) * Add Unit tests to the server side * Do not use optional chaining in JS * Add tests on the public end * Fix jslint errors * jest.useFakeTimers() + jest.clearAllTimers() * Remove Jest timer handlers from my tests (only affecting to a minimum coverage bit) * Catch ES actions in the setup/start steps because it broke core_services tests * Fix boolean check * Use core's ES.adminCLient over .createClient * Fix tests after ES.adminClient * [Telemetry] Application Usage implemented in kbn-analytics * Use bulkCreate in store_report * ApplicationUsagePluginStart does not exist anymore * Fix usage_collection mock interface * Check there is something to store before calling the bulkCreate method * Add unit tests * Fix types in tests * Unit tests for rollTotals and actual fix for the bug found * Fix usage_collection mock after elastic#57693 got merged Co-authored-by: Elastic Machine <[email protected]>
…58904) * [Telemetry] Report the Application Usage (time of usage + number of clicks) * Add Unit tests to the server side * Do not use optional chaining in JS * Add tests on the public end * Fix jslint errors * jest.useFakeTimers() + jest.clearAllTimers() * Remove Jest timer handlers from my tests (only affecting to a minimum coverage bit) * Catch ES actions in the setup/start steps because it broke core_services tests * Fix boolean check * Use core's ES.adminCLient over .createClient * Fix tests after ES.adminClient * [Telemetry] Application Usage implemented in kbn-analytics * Use bulkCreate in store_report * ApplicationUsagePluginStart does not exist anymore * Fix usage_collection mock interface * Check there is something to store before calling the bulkCreate method * Add unit tests * Fix types in tests * Unit tests for rollTotals and actual fix for the bug found * Fix usage_collection mock after #57693 got merged Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
…) (#58872) * Spaces - NP updates for usage collection and capabilities (#57693) * remove kibanaIndex from LegacyAPI * moving capabilities, adding tests * moving usage collection * cleanup * don't toggle capabilities on unauthenticated routes * reintroduce exception handling * pipe dat config * start addressing PR feedback * fix CoreSetup's generic type * fix usage collector tests * PR review updates Co-authored-by: Elastic Machine <[email protected]> * fix mock Co-authored-by: Elastic Machine <[email protected]>
Summary
Removes
legacyConfig.kibanaIndex
Replaces this entry with the kibana index sourced from the NP
initializerContext
, consistent with the waylens
accomplishes this.This was being used by our usage collector. Since this was getting updated anyway, I moved the collector files to a more logical location (and out of the
lib
dumping ground).Moves
uiCapabilities
providerThe NP has support for capability providers. This removes the spaces capabilities definition from the LP to the NP. Since this was getting updated anyway, I moved the capability files to a more logical location (and out of the
lib
dumping ground)Exposes
features
plugin start contractThe
features
plugin did not have a start contract. This adds one to retrieve the available features.This is a more logical location than
setup
, because features can no longer be registered oncegetFeatures()
is called.Mocks
Additional tests were added, which rely on plugins which did not have mocks in place. This PR added mocks as appropriate.