Skip to content

Commit

Permalink
[Maps] add on-prem EMS config (#82525)
Browse files Browse the repository at this point in the history
Adds.a new `map.emsUrl` setting. User can configure this to the location of a local on-prem installation of EMS. For this setting to take effect, the cluster must be configured with an enterprise license.
  • Loading branch information
thomasneirynck authored Nov 10, 2020
1 parent f49ee06 commit e909cee
Show file tree
Hide file tree
Showing 21 changed files with 532 additions and 97 deletions.
25 changes: 25 additions & 0 deletions src/plugins/maps_legacy/common/ems_defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// Default config for the elastic hosted EMS endpoints
export const DEFAULT_EMS_FILE_API_URL = 'https://vector.maps.elastic.co';
export const DEFAULT_EMS_TILE_API_URL = 'https://tiles.maps.elastic.co';
export const DEFAULT_EMS_LANDING_PAGE_URL = 'https://maps.elastic.co/v7.10';
export const DEFAULT_EMS_FONT_LIBRARY_URL =
'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf';
20 changes: 20 additions & 0 deletions src/plugins/maps_legacy/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './ems_defaults';
19 changes: 15 additions & 4 deletions src/plugins/maps_legacy/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ import { schema, TypeOf } from '@kbn/config-schema';
import { configSchema as tilemapSchema } from '../tile_map/config';
import { configSchema as regionmapSchema } from '../region_map/config';

import {
DEFAULT_EMS_FONT_LIBRARY_URL,
DEFAULT_EMS_LANDING_PAGE_URL,
DEFAULT_EMS_TILE_API_URL,
DEFAULT_EMS_FILE_API_URL,
} from './common/ems_defaults';

export const configSchema = schema.object({
includeElasticMapsService: schema.boolean({ defaultValue: true }),
proxyElasticMapsServiceInMaps: schema.boolean({ defaultValue: false }),
tilemap: tilemapSchema,
regionmap: regionmapSchema,
manifestServiceUrl: schema.string({ defaultValue: '' }),
emsFileApiUrl: schema.string({ defaultValue: 'https://vector.maps.elastic.co' }),
emsTileApiUrl: schema.string({ defaultValue: 'https://tiles.maps.elastic.co' }),
emsLandingPageUrl: schema.string({ defaultValue: 'https://maps.elastic.co/v7.10' }),

emsUrl: schema.string({ defaultValue: '' }),

emsFileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_FILE_API_URL }),
emsTileApiUrl: schema.string({ defaultValue: DEFAULT_EMS_TILE_API_URL }),
emsLandingPageUrl: schema.string({ defaultValue: DEFAULT_EMS_LANDING_PAGE_URL }),
emsFontLibraryUrl: schema.string({
defaultValue: 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf',
defaultValue: DEFAULT_EMS_FONT_LIBRARY_URL,
}),

emsTileLayerId: schema.object({
bright: schema.string({ defaultValue: 'road_map' }),
desaturated: schema.string({ defaultValue: 'road_map_desaturated' }),
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"configPath": ["map"],
"ui": true,
"server": true,
"extraPublicDirs": ["common"],
"requiredBundles": ["kibanaReact", "charts"]
}
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export {
mapTooltipProvider,
};

export * from '../common';
export * from './common/types';
export { ORIGIN } from './common/constants/origin';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/maps_legacy/public/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ServiceSettings {
allServices.push(tmsService);
}

if (this._mapConfig.includeElasticMapsService) {
if (this._mapConfig.includeElasticMapsService && !this._mapConfig.emsUrl) {
const servicesFromManifest = await this._emsClient.getTMSServices();
const strippedServiceFromManifest = await Promise.all(
servicesFromManifest
Expand Down
1 change: 1 addition & 0 deletions src/plugins/maps_legacy/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const config: PluginConfigDescriptor<MapsLegacyConfig> = {
tilemap: true,
regionmap: true,
manifestServiceUrl: true,
emsUrl: true,
emsFileApiUrl: true,
emsTileApiUrl: true,
emsLandingPageUrl: true,
Expand Down
221 changes: 221 additions & 0 deletions x-pack/plugins/maps/common/ems_settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { EMSSettings, IEMSConfig } from './ems_settings';
import {
DEFAULT_EMS_FILE_API_URL,
DEFAULT_EMS_FONT_LIBRARY_URL,
DEFAULT_EMS_LANDING_PAGE_URL,
DEFAULT_EMS_TILE_API_URL,
} from '../../../../src/plugins/maps_legacy/common';

const IS_ENTERPRISE_PLUS = () => true;

describe('EMSSettings', () => {
const mockConfig: IEMSConfig = {
includeElasticMapsService: true,
proxyElasticMapsServiceInMaps: false,
emsUrl: '',
emsFileApiUrl: DEFAULT_EMS_FILE_API_URL,
emsTileApiUrl: DEFAULT_EMS_TILE_API_URL,
emsLandingPageUrl: DEFAULT_EMS_LANDING_PAGE_URL,
emsFontLibraryUrl: DEFAULT_EMS_FONT_LIBRARY_URL,
isEMSEnabled: true,
};

describe('isEMSEnabled/isOnPrem', () => {
test('should validate defaults', () => {
const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(false);
});

test('should validate if on-prem is turned on', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(true);
});

test('should not validate if ems turned off', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
includeElasticMapsService: false,
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(false);
expect(emsSettings.isOnPrem()).toBe(false);
});

test('should work if ems is turned off, but on-prem is turned on', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
includeElasticMapsService: false,
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.isEMSEnabled()).toBe(true);
expect(emsSettings.isOnPrem()).toBe(true);
});

describe('when license is turned off', () => {
test('should not be enabled', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
() => false
);
expect(emsSettings.isEMSEnabled()).toBe(false);
expect(emsSettings.isOnPrem()).toBe(true);
});
});
});

describe('emsUrl setting', () => {
describe('when emsUrl is not set', () => {
test('should respect defaults', () => {
const emsSettings = new EMSSettings(mockConfig, IS_ENTERPRISE_PLUS);
expect(emsSettings.getEMSFileApiUrl()).toBe(DEFAULT_EMS_FILE_API_URL);
expect(emsSettings.getEMSTileApiUrl()).toBe(DEFAULT_EMS_TILE_API_URL);
expect(emsSettings.getEMSFontLibraryUrl()).toBe(DEFAULT_EMS_FONT_LIBRARY_URL);
expect(emsSettings.getEMSLandingPageUrl()).toBe(DEFAULT_EMS_LANDING_PAGE_URL);
});
test('should apply overrides', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsFileApiUrl: 'https://file.foobar',
emsTileApiUrl: 'https://tile.foobar',
emsFontLibraryUrl: 'https://tile.foobar/font',
emsLandingPageUrl: 'https://maps.foobar/v7.666',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar');
expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://tile.foobar/font');
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar/v7.666');
});
});

describe('when emsUrl is set', () => {
test('should override defaults', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

describe('internal settings overrides (the below behavior is not publically supported, but aids internal debugging use-cases)', () => {
test(`should override internal emsFileApiUrl`, () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsFileApiUrl: 'https://file.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://file.foobar');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test(`should override internal emsTileApiUrl`, () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsTileApiUrl: 'https://tile.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://tile.foobar');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test('should override internal emsFontLibraryUrl', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsFontLibraryUrl: 'https://maps.foobar/fonts',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe('https://maps.foobar/fonts');
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://localhost:8080/maps');
});

test('should override internal emsLandingPageUrl', () => {
const emsSettings = new EMSSettings(
{
...mockConfig,
...{
emsUrl: 'https://localhost:8080',
emsLandingPageUrl: 'https://maps.foobar',
},
},
IS_ENTERPRISE_PLUS
);
expect(emsSettings.getEMSFileApiUrl()).toBe('https://localhost:8080/file');
expect(emsSettings.getEMSTileApiUrl()).toBe('https://localhost:8080/tile');
expect(emsSettings.getEMSFontLibraryUrl()).toBe(
'https://localhost:8080/tile/fonts/{fontstack}/{range}.pbf'
);
expect(emsSettings.getEMSLandingPageUrl()).toBe('https://maps.foobar');
});
});
});
});
});
Loading

0 comments on commit e909cee

Please sign in to comment.