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

[Maps] Always initialize routes on server-startup #84806

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions x-pack/plugins/maps/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,23 @@ export class MapsPlugin implements Plugin {
return;
}

let routesInitialized = false;
let isEnterprisePlus = false;
let lastLicenseId: string | undefined;
const emsSettings = new EMSSettings(mapsLegacyConfig, () => isEnterprisePlus);
licensing.license$.subscribe((license: ILicense) => {
const basic = license.check(APP_ID, 'basic');

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';

if (basic.state === 'valid' && !routesInitialized) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checking for validity is not necessary. Other plugins do not check license-validity before registering the routes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be carryover from legacy patterns? Thanks for the clean up

routesInitialized = true;
initRoutes(
core.http.createRouter(),
license.uid,
emsSettings,
this.kibanaVersion,
this._logger
);
}
lastLicenseId = license.uid;
});

initRoutes(
core.http.createRouter(),
() => lastLicenseId,
emsSettings,
this.kibanaVersion,
this._logger
);

this._initHomeData(home, core.http.basePath.prepend, emsSettings);

features.registerKibanaFeature({
Expand Down
40 changes: 23 additions & 17 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,32 @@ const EMPTY_EMS_CLIENT = {
addQueryParams() {},
};

export function initRoutes(router, licenseUid, emsSettings, kbnVersion, logger) {
export function initRoutes(router, getLicenseId, emsSettings, kbnVersion, logger) {
let emsClient;

if (emsSettings.isIncludeElasticMapsService()) {
emsClient = new EMSClient({
language: i18n.getLocale(),
appVersion: kbnVersion,
appName: EMS_APP_NAME,
fileApiUrl: emsSettings.getEMSFileApiUrl(),
tileApiUrl: emsSettings.getEMSTileApiUrl(),
landingPageUrl: emsSettings.getEMSLandingPageUrl(),
fetchFunction: fetch,
});
emsClient.addQueryParams({ license: licenseUid });
} else {
emsClient = EMPTY_EMS_CLIENT;
}
let lastLicenseId;

function getEMSClient() {
return emsSettings.isEMSEnabled() ? emsClient : EMPTY_EMS_CLIENT;
const currentLicenseId = getLicenseId();
if (emsClient && emsSettings.isEMSEnabled() && lastLicenseId === currentLicenseId) {
return emsClient;
}

lastLicenseId = currentLicenseId;
if (emsSettings.isIncludeElasticMapsService()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this include a check for lastLicenseId being undefined? What happens if getLicenseId returns undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

EMS has a license validation on the backend as well. This will fallback to as-if OSS EMS would be used.

emsClient = new EMSClient({
language: i18n.getLocale(),
appVersion: kbnVersion,
appName: EMS_APP_NAME,
fileApiUrl: emsSettings.getEMSFileApiUrl(),
tileApiUrl: emsSettings.getEMSTileApiUrl(),
landingPageUrl: emsSettings.getEMSLandingPageUrl(),
fetchFunction: fetch,
});
emsClient.addQueryParams({ license: currentLicenseId });
return emsClient;
} else {
return EMPTY_EMS_CLIENT;
}
}

router.get(
Expand Down