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 1 commit
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
26 changes: 12 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,25 @@ export class MapsPlugin implements Plugin {
return;
}

let routesInitialized = false;
let isEnterprisePlus = false;
let lastLicenseId: string;
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(),
() => {
return lastLicenseId;
},
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
emsSettings,
this.kibanaVersion,
this._logger
);

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

features.registerKibanaFeature({
Expand Down
40 changes: 24 additions & 16 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,31 @@ 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() {
const currentLicenseId = getLicenseId();
if (emsClient && 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 });
} else {
emsClient = EMPTY_EMS_CLIENT;
}
return emsSettings.isEMSEnabled() ? emsClient : EMPTY_EMS_CLIENT;
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -547,6 +553,8 @@ export function initRoutes(router, licenseUid, emsSettings, kbnVersion, logger)
},
},
async (context, request, response) => {
console.log('Load index settings');

const { query } = request;

if (!query.indexPatternTitle) {
Expand Down