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

Licensing plugin and XPackInfo uses the same license data #52507

Merged
merged 20 commits into from
Dec 13, 2019

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Dec 9, 2019

Summary

Closes: #52502
With this PR XPack doesn't fetch license data anymore, but consume them from NP Licensing plugin. To facilitate migration I converted XPack code into TypeScript.
I tested locally, but I would appreciate a review help to verify changes locally.
My main concern is createXPackInfo, which hasn't got any tests.

TODO: deprecate xpack.xpack_main.xpack_api_polling_frequency_millis when #52251 merged

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform labels Dec 9, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

const currentSignature = response.headers('kbn-xpack-sig');
const cachedSignature = xpackInfoSignature.get();

if (currentSignature && cachedSignature !== currentSignature) {
Copy link
Contributor Author

@mshustov mshustov Dec 10, 2019

Choose a reason for hiding this comment

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

That was removed in #51818 by mistake.
Xpack cannot detect license update without it. I also noticed that it doesn't work well with different fetching mechanism. Some plugins use NP fetch, some custom fetching mechanism, for example

We need to talk to solution teams about unifying the network stack.
@elastic/kibana-platform
Should we create a separate issue to track?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want an issue, or should we 'just' add in our guidelines that the fetching mecanism in kibana should be core.http?

Apollo can be hard to migrate though, as it's not 'only' a fetch.

Copy link
Contributor Author

@mshustov mshustov Dec 11, 2019

Choose a reason for hiding this comment

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

It seems we need to solve several problems:


server.expose('info', info);
server.expose('createXPackInfo', (options) => new XPackInfo(server, options));
server.expose('createXPackInfo', (options) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@restrry This LGTM. I pulled down the PR and the behavior seems consistent

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so this actually wasn't the case. I missed something and this is causing a problem in 7.6

@@ -383,18 +158,20 @@ describe('XPackInfo', () => {

describe('feature', () => {
let xPackInfo;
let license$;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed all fetching tests. All remaining tests in the file are supposed to prove the xpack plugin contract.

@mshustov mshustov added chore v7.6.0 release_note:skip Skip the PR/issue when compiling release notes labels Dec 10, 2019
@mshustov mshustov marked this pull request as ready for review December 10, 2019 14:42
@mshustov mshustov requested a review from a team as a code owner December 10, 2019 14:42
@mshustov mshustov requested a review from a team December 10, 2019 14:42
const {
body: legacyInitialLicense,
headers: legacyInitialLicenseHeaders,
} = await supertest.get('/api/xpack/v1/info').expect(200);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

temporarily adds tests for Legacy Licensing to have at least smoke-tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this to a separate legacy test so it can be more easily deleted?

Copy link
Contributor Author

@mshustov mshustov Dec 12, 2019

Choose a reason for hiding this comment

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

I wish we could. I need to add a comment in tests #51818 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to add a client side tests in the followup PR. Probably I just create 2 separate FTR configs for NP & LP

const currentSignature = response.headers('kbn-xpack-sig');
const cachedSignature = xpackInfoSignature.get();

if (currentSignature && cachedSignature !== currentSignature) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want an issue, or should we 'just' add in our guidelines that the fetching mecanism in kibana should be core.http?

Apollo can be hard to migrate though, as it's not 'only' a fetch.

Comment on lines -42 to +44
newPlatform: { setup: { plugins: { features: {} } } },
newPlatform: { setup: { plugins: { features: {}, licensing: { license$: new BehaviorSubject() } } } },
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a licensingPluginMock in the licensing plugin and use it instead of inline declaration ? something like what's done in src/legacy/ui/public/new_platform/__mocks__/helpers.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I will add a mock for NP the plugin.
  2. This file uses Sinon instead of Jest. I don't want to provide the full mock because we are about to delete this setup completely.

x-pack/plugins/licensing/common/types.ts Outdated Show resolved Hide resolved
x-pack/plugins/licensing/common/types.ts Outdated Show resolved Hide resolved
@mshustov mshustov requested a review from a team December 12, 2019 16:34
if (license.isActive) {
this._cache = {
license,
error: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this branch really needed? I would expect that license.error would be undefined when license.isActive is true anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but this is this.cache._error, which is used by the legacy xpack plugin. Although it's not 1:1 mapping. The legacy plugin updated error whenever fetcher throws
https://github.com/elastic/kibana/pull/52507/files#diff-949ac00938b10918e9232965106cd7e1L186

x-pack/plugins/licensing/server/types.ts Show resolved Hide resolved
const {
body: legacyInitialLicense,
headers: legacyInitialLicenseHeaders,
} = await supertest.get('/api/xpack/v1/info').expect(200);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move this to a separate legacy test so it can be more easily deleted?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

History

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

@mshustov mshustov merged commit 2b88256 into elastic:master Dec 13, 2019
@mshustov mshustov deleted the issue-52502 branch December 13, 2019 12:46
mshustov added a commit to mshustov/kibana that referenced this pull request Dec 13, 2019
)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config
spalger pushed a commit that referenced this pull request Dec 13, 2019
mshustov added a commit to mshustov/kibana that referenced this pull request Dec 13, 2019
)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config
mshustov added a commit that referenced this pull request Dec 13, 2019
* Licensing plugin and XPackInfo uses the same license data (#52507)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config

* fix wrong import
mshustov added a commit to mshustov/kibana that referenced this pull request Dec 16, 2019
* Licensing plugin and XPackInfo uses the same license data (elastic#52507)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config

* fix wrong import
mshustov added a commit that referenced this pull request Dec 16, 2019
* Fix wrong impor (#52994)

* Licensing plugin and XPackInfo uses the same license data (#52507)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config

* fix wrong import

* prevent eslint error with renaming mock file
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
timductive pushed a commit to timductive/kibana that referenced this pull request Dec 16, 2019
* Licensing plugin and XPackInfo uses the same license data (elastic#52507)

* convert xpackinfo to TS

* use NP Licensing plugin in XPackInfo

* update mocks

* put license regresh hack back.

otherwise new license won't be re-fetched when signature changed. was deleted by mistake

* add functional test for legacy xpackmain

* declare setup types on client & server explicitly

* rename mock license --> licensing to match plugin name

* add tests for createLicensePoller

* fix type error

* adopt tests for xpack_info

* createXPackInfo uses new platform API

* put back error mute

* address comments

* fix renamed import

* address comment

* update tests to reduce delays

* deprecate xpack.xpack_main.xpack_api_polling_frequency_millis

* use snake_case in config

* fix wrong import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Feature:New Platform release_note:skip Skip the PR/issue when compiling release notes reverted Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync licenses in NP licensing plugin and XPackMain
5 participants