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

Spaces - NP updates for usage collection and capabilities #57693

Merged
merged 18 commits into from
Feb 28, 2020

Conversation

legrego
Copy link
Member

@legrego legrego commented Feb 14, 2020

Summary

Removes legacyConfig.kibanaIndex

Replaces this entry with the kibana index sourced from the NP initializerContext, consistent with the way lens 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 provider

The 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 contract

The 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 once getFeatures() is called.

Mocks

Additional tests were added, which rely on plugins which did not have mocks in place. This PR added mocks as appropriate.

@legrego legrego added Feature:NP Migration Feature:Security/Spaces Platform Security - Spaces feature release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.7.0 v8.0.0 labels Feb 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@legrego
Copy link
Member Author

legrego commented Feb 14, 2020

@elasticmachine merge upstream

const isAnonymousRequest = !request.route.options.authRequired;

if (isAnonymousRequest) {
return capabilities;
Copy link
Member Author

@legrego legrego Feb 14, 2020

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)

Copy link
Member

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!

@legrego legrego requested a review from azasypkin February 14, 2020 23:46
@azasypkin
Copy link
Member

ACK: sorry for the delay, will review tomorrow

Copy link
Member

@azasypkin azasypkin left a 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.

src/core/server/http/http_server.mocks.ts Show resolved Hide resolved
src/plugins/usage_collection/server/mocks.ts Outdated Show resolved Hide resolved
src/plugins/usage_collection/server/mocks.ts Outdated Show resolved Hide resolved
x-pack/plugins/features/server/plugin.ts Show resolved Hide resolved
x-pack/plugins/features/server/mocks.ts Show resolved Hide resolved
x-pack/plugins/spaces/server/plugin.ts Outdated Show resolved Hide resolved
deps.features,
available
);
const kibanaIndex = (await deps.kibanaIndexConfig.pipe(take(1)).toPromise()).kibana.index;
Copy link
Member

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.

const isAnonymousRequest = !request.route.options.authRequired;

if (isAnonymousRequest) {
return capabilities;
Copy link
Member

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!

@legrego legrego marked this pull request as ready for review February 25, 2020 19:08
@legrego legrego requested review from a team as code owners February 25, 2020 19:08
@legrego
Copy link
Member Author

legrego commented Feb 26, 2020

@azasypkin thanks for your initial feedback - ready for final review!

@azasypkin
Copy link
Member

ACK: will review tomorrow

Copy link
Contributor

@pgayvallet pgayvallet left a 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

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

Looks good!

x-pack/plugins/features/server/plugin.ts Outdated Show resolved Hide resolved
x-pack/plugins/features/server/plugin.ts Outdated Show resolved Hide resolved
Copy link
Member

@afharo afharo left a 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<
Copy link
Member

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) :)

Copy link
Member Author

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 :/

Copy link
Member

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 :)

@legrego
Copy link
Member Author

legrego commented Feb 27, 2020

@elasticmachine merge upstream

@legrego
Copy link
Member Author

legrego commented Feb 28, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

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

@legrego legrego merged commit 91330d2 into elastic:master Feb 28, 2020
@legrego legrego deleted the spaces/moar-np branch February 28, 2020 14:06
legrego added a commit to legrego/kibana that referenced this pull request Feb 28, 2020
)

* 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]>
afharo added a commit to afharo/kibana that referenced this pull request Feb 28, 2020
afharo added a commit that referenced this pull request Feb 28, 2020
* [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]>
afharo added a commit to afharo/kibana that referenced this pull request Feb 28, 2020
…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]>
afharo added a commit that referenced this pull request Feb 28, 2020
…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]>
legrego added a commit that referenced this pull request Feb 28, 2020
…) (#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration Feature:Security/Spaces Platform Security - Spaces feature release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants