-
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
Licensing plugin and XPackInfo uses the same license data #52507
Conversation
Pinging @elastic/kibana-platform (Team:Platform) |
otherwise new license won't be re-fetched when signature changed. was deleted by mistake
const currentSignature = response.headers('kbn-xpack-sig'); | ||
const cachedSignature = xpackInfoSignature.get(); | ||
|
||
if (currentSignature && cachedSignature !== currentSignature) { |
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.
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
- axios
https://github.com/restrry/kibana/blob/354a152caa94d856b8ffe1fa4df0981421c1e134/x-pack/legacy/plugins/canvas/common/lib/fetch.ts#L10 - graphql-apollo https://github.com/restrry/kibana/blob/354a152caa94d856b8ffe1fa4df0981421c1e134/x-pack/legacy/plugins/infra/public/pages/metrics/containers/with_metrics.tsx#L6-L8
We need to talk to solution teams about unifying the network stack.
@elastic/kibana-platform
Should we create a separate issue to track?
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.
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.
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.
It seems we need to solve several problems:
- to unify the network stack whenever possible
- to investigate and document how we can integrate http interceptors in any network library. Apollo supports middlewares and afterwares https://www.apollographql.com/docs/react/networking/network-layer/#afterware
That could require adjusting interceptor API.
|
||
server.expose('info', info); | ||
server.expose('createXPackInfo', (options) => new XPackInfo(server, options)); | ||
server.expose('createXPackInfo', (options) => { |
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.
@chrisronline I need your help to test that it doesn't break https://github.com/elastic/kibana/blob/master/x-pack/legacy/plugins/monitoring/server/init_monitoring_xpack_info.js#L15
There are no tests to verify it
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.
@restrry This LGTM. I pulled down the PR and the behavior seems consistent
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.
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$; |
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.
I removed all fetching tests. All remaining tests in the file are supposed to prove the xpack plugin contract.
const { | ||
body: legacyInitialLicense, | ||
headers: legacyInitialLicenseHeaders, | ||
} = await supertest.get('/api/xpack/v1/info').expect(200); |
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.
temporarily adds tests for Legacy Licensing to have at least smoke-tests
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.
Should we move this to a separate legacy test so it can be more easily deleted?
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.
I wish we could. I need to add a comment in tests #51818 (comment)
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.
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) { |
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.
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.
newPlatform: { setup: { plugins: { features: {} } } }, | ||
newPlatform: { setup: { plugins: { features: {}, licensing: { license$: new BehaviorSubject() } } } }, |
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.
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
.
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.
- I will add a mock for NP the plugin.
- 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.
if (license.isActive) { | ||
this._cache = { | ||
license, | ||
error: undefined, |
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.
Is this branch really needed? I would expect that license.error
would be undefined when license.isActive
is true anyways.
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.
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
const { | ||
body: legacyInitialLicense, | ||
headers: legacyInitialLicenseHeaders, | ||
} = await supertest.get('/api/xpack/v1/info').expect(200); |
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.
Should we move this to a separate legacy test so it can be more easily deleted?
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
) * 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
) * 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
* 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
* 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
* 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
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 mergedChecklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers