Skip to content

Commit 1c97dbc

Browse files
authoredJan 3, 2017
[5.x] Backport: Read map service metadata from external service (#8630)
Due to merge conflicts, manual backport of 929b4de This modifies the way Kibana reads out metadata about the TMS service used in the Tilemap Visualization. - Kibana now uses an external service that exposes a 'manifest'. This contains metadata about one or more available TMS services - Kibana continues to respect the configuration of the kibana.yml file. If a custom TMS service is set here, the manifest will not be consulted - This also adds an API extension point for other plugins to add additional query parameters to the requests to the manifest service and for the individual tile requests to the TMS.
1 parent caba849 commit 1c97dbc

File tree

18 files changed

+460
-71
lines changed

18 files changed

+460
-71
lines changed
 

‎src/core_plugins/kibana/index.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = function (kibana) {
2222
},
2323

2424
uiExports: {
25+
26+
27+
2528
app: {
2629
id: 'kibana',
2730
title: 'Kibana',
@@ -39,10 +42,23 @@ module.exports = function (kibana) {
3942
],
4043

4144
injectVars: function (server, options) {
42-
let config = server.config();
45+
const serverConfig = server.config();
46+
47+
//DEPRECATED SETTINGS
48+
//if the url is set, the old settings must be used.
49+
//keeping this logic for backward compatibilty.
50+
const configuredUrl = server.config().get('tilemap.url');
51+
const isOverridden = typeof configuredUrl === 'string' && configuredUrl !== '';
52+
const tilemapConfig = serverConfig.get('tilemap');
4353
return {
44-
kbnDefaultAppId: config.get('kibana.defaultAppId'),
45-
tilemap: config.get('tilemap')
54+
kbnDefaultAppId: serverConfig.get('kibana.defaultAppId'),
55+
tilemapsConfig: {
56+
deprecated: {
57+
isOverridden: isOverridden,
58+
config: tilemapConfig,
59+
},
60+
manifestServiceUrl: serverConfig.get('tilemap.manifestServiceUrl')
61+
},
4662
};
4763
},
4864
},

‎src/core_plugins/kibana/public/visualize/saved_visualizations/saved_visualizations.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import _ from 'lodash';
2-
import Scanner from 'ui/utils/scanner';
31
import 'plugins/kibana/visualize/saved_visualizations/_saved_vis';
42
import RegistryVisTypesProvider from 'ui/registry/vis_types';
53
import uiModules from 'ui/modules';

‎src/core_plugins/tests_bundle/tests_entry_template.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ window.__KBN__ = {
2828
esShardTimeout: 1500,
2929
esApiVersion: '5.x',
3030
esRequestTimeout: '300000',
31-
tilemap: {
32-
url: 'https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?my_app_name=kibana&my_app_version=1.2.3&elastic_tile_service_tos=agree',
33-
options: {
34-
minZoom: 1,
35-
maxZoom: 10,
36-
attribution: '© [Elastic Tile Service](https://www.elastic.co/elastic_tile_service)'
37-
}
31+
tilemapsConfig: {
32+
deprecated: {
33+
isOverridden: true,
34+
config: {
35+
url: 'https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?my_app_name=kibana&my_app_version=1.2.3&elastic_tile_service_tos=agree',
36+
options: {
37+
minZoom: 1,
38+
maxZoom: 10,
39+
attribution: '© [Elastic Tile Service](https://www.elastic.co/elastic_tile_service)'
40+
}
41+
}
42+
},
43+
manifestServiceUrl: 'https://proxy-tiles.elastic.co/v1/manifest'
3844
}
3945
},
4046
uiSettings: {

‎src/server/config/schema.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ module.exports = () => Joi.object({
131131
status: Joi.object({
132132
allowAnonymous: Joi.boolean().default(false)
133133
}).default(),
134-
135134
tilemap: Joi.object({
136-
url: Joi.string().default(`https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?my_app_name=kibana&my_app_version=${pkg.version}&elastic_tile_service_tos=agree`),
135+
manifestServiceUrl: Joi.string().default('https://proxy-tiles.elastic.co/v1/manifest'),
136+
url: Joi.string(),
137137
options: Joi.object({
138-
attribution: Joi.string().default('© [Elastic Tile Service](https://www.elastic.co/elastic-tile-service)'),
138+
attribution: Joi.string(),
139139
minZoom: Joi.number().min(1, 'Must not be less than 1').default(1),
140140
maxZoom: Joi.number().default(10),
141141
tileSize: Joi.number(),
@@ -146,7 +146,6 @@ module.exports = () => Joi.object({
146146
bounds: Joi.array().items(Joi.array().items(Joi.number()).min(2).required()).min(2)
147147
}).default()
148148
}).default(),
149-
150149
uiSettings: Joi.object({
151150
// this is used to prevent the uiSettings from initializing. Since they
152151
// require the elasticsearch plugin in order to function we need to turn

‎src/ui/public/registry/_registry.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import _ from 'lodash';
22
import IndexedArray from 'ui/indexed_array';
3-
import RegistryVisTypesProvider from 'ui/registry/vis_types';
4-
let notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor');
3+
const notPropsOptNames = IndexedArray.OPT_NAMES.concat('constructor');
54

65
/**
76
* Create a registry, which is just a Private module provider.

‎src/ui/public/vis/vis.js

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import AggTypesIndexProvider from 'ui/agg_types/index';
1313
import RegistryVisTypesProvider from 'ui/registry/vis_types';
1414
import VisAggConfigsProvider from 'ui/vis/agg_configs';
1515
import PersistedStateProvider from 'ui/persisted_state/persisted_state';
16-
import EventsProvider from 'ui/events';
1716

1817
export default function VisFactory(Notifier, Private) {
1918
let aggTypes = Private(AggTypesIndexProvider);

‎src/ui/public/vis_maps/__tests__/tile_maps/map.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ import VislibVisualizationsMapProvider from 'ui/vis_maps/visualizations/_map';
2424
// 'Heatmap'
2525
// ];
2626

27-
describe('TileMap Map Tests', function () {
27+
describe('tilemaptest - TileMap Map Tests', function () {
2828
const $mockMapEl = $('<div>');
2929
let TileMapMap;
30+
let theTileMapSettings;
3031
const leafletStubs = {};
3132
const leafletMocks = {};
3233

34+
3335
beforeEach(ngMock.module('kibana'));
34-
beforeEach(ngMock.inject(function (Private) {
36+
beforeEach(ngMock.inject(function (Private, tilemapSettings) {
3537
// mock parts of leaflet
3638
leafletMocks.tileLayer = { on: sinon.stub() };
3739
leafletMocks.map = { on: sinon.stub() };
@@ -41,13 +43,22 @@ describe('TileMap Map Tests', function () {
4143
leafletStubs.map = sinon.stub(L, 'map', _.constant(leafletMocks.map));
4244

4345
TileMapMap = Private(VislibVisualizationsMapProvider);
46+
47+
theTileMapSettings = tilemapSettings;
48+
4449
}));
4550

51+
async function loadTileMapSettings() {
52+
await theTileMapSettings.loadSettings();
53+
}
54+
4655
describe('instantiation', function () {
4756
let map;
4857
let createStub;
4958

50-
beforeEach(function () {
59+
beforeEach(loadTileMapSettings);
60+
61+
beforeEach(async function () {
5162
createStub = sinon.stub(TileMapMap.prototype, '_createMap', _.noop);
5263
map = new TileMapMap($mockMapEl, geoJsonData, {});
5364
});
@@ -69,6 +80,8 @@ describe('TileMap Map Tests', function () {
6980
let map;
7081
let mapStubs;
7182

83+
beforeEach(loadTileMapSettings);
84+
7285
beforeEach(function () {
7386
mapStubs = {
7487
destroy: sinon.stub(TileMapMap.prototype, 'destroy'),
@@ -112,6 +125,8 @@ describe('TileMap Map Tests', function () {
112125
describe('attachEvents', function () {
113126
let map;
114127

128+
beforeEach(loadTileMapSettings);
129+
115130
beforeEach(function () {
116131
sinon.stub(TileMapMap.prototype, '_createMap', function () {
117132
this._tileLayer = leafletMocks.tileLayer;
@@ -148,12 +163,13 @@ describe('TileMap Map Tests', function () {
148163
let map;
149164
let createStub;
150165

166+
beforeEach(loadTileMapSettings);
167+
151168
beforeEach(function () {
152169
sinon.stub(TileMapMap.prototype, '_createMap');
153170
createStub = sinon.stub(TileMapMap.prototype, '_createMarkers', _.constant({ addLegend: _.noop }));
154171
map = new TileMapMap($mockMapEl, geoJsonData, {});
155172
});
156-
157173
it('should pass the map options to the marker', function () {
158174
map._addMarkers();
159175

@@ -175,6 +191,8 @@ describe('TileMap Map Tests', function () {
175191
describe('getDataRectangles', function () {
176192
let map;
177193

194+
beforeEach(loadTileMapSettings);
195+
178196
beforeEach(function () {
179197
sinon.stub(TileMapMap.prototype, '_createMap');
180198
map = new TileMapMap($mockMapEl, geoJsonData, {});

‎src/ui/public/vis_maps/__tests__/tile_maps/markers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const mockMap = {
3838
getZoom: _.constant(5)
3939
};
4040

41-
describe('Marker Tests', function () {
41+
describe('tilemaptest - Marker Tests', function () {
4242
let mapData;
4343
let markerLayer;
4444

‎src/ui/public/vis_maps/__tests__/tile_maps/tile_map.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ function createTileMap(handler, chartEl, chartData) {
2828
chartEl = chartEl || mockChartEl;
2929
chartData = chartData || geoJsonData;
3030

31-
const tilemap = new TileMap(handler, chartEl, chartData);
32-
return tilemap;
31+
return new TileMap(handler, chartEl, chartData);
3332
}
3433

35-
describe('TileMap Tests', function () {
34+
describe('tilemaptest - TileMap Tests', function () {
3635
let tilemap;
3736

3837
beforeEach(ngMock.module('kibana'));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import expect from 'expect.js';
2+
import ngMock from 'ng_mock';
3+
import url from 'url';
4+
5+
describe('tilemaptest - TileMapSettingsTests-deprecated', function () {
6+
let theTileMapSettings;
7+
let theTilemapsConfig;
8+
9+
beforeEach(ngMock.module('kibana'));
10+
beforeEach(ngMock.inject(function (Private, tilemapSettings, tilemapsConfig) {
11+
theTileMapSettings = tilemapSettings;
12+
theTilemapsConfig = tilemapsConfig;
13+
theTilemapsConfig.deprecated.isOverridden = true;
14+
}));
15+
16+
17+
describe('getting settings', function () {
18+
19+
beforeEach(async function () {
20+
await theTileMapSettings.loadSettings();
21+
});
22+
23+
it('should get url', async function () {
24+
25+
const mapUrl = theTileMapSettings.getUrl();
26+
expect(mapUrl.indexOf('{x}') > -1).to.be.ok();
27+
expect(mapUrl.indexOf('{y}') > -1).to.be.ok();
28+
expect(mapUrl.indexOf('{z}') > -1).to.be.ok();
29+
30+
const urlObject = url.parse(mapUrl, true);
31+
expect(urlObject.host.endsWith('elastic.co')).to.be.ok();
32+
expect(urlObject.query).to.have.property('my_app_name');
33+
expect(urlObject.query).to.have.property('my_app_version');
34+
expect(urlObject.query).to.have.property('elastic_tile_service_tos');
35+
36+
});
37+
38+
it('should get options', async function () {
39+
const options = theTileMapSettings.getOptions();
40+
expect(options).to.have.property('minZoom');
41+
expect(options).to.have.property('maxZoom');
42+
expect(options).to.have.property('attribution');
43+
});
44+
45+
});
46+
47+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import expect from 'expect.js';
2+
import ngMock from 'ng_mock';
3+
import url from 'url';
4+
5+
describe('tilemaptest - TileMapSettingsTests-mocked', function () {
6+
let theTileMapSettings;
7+
let theTilemapsConfig;
8+
let oldGetManifest;
9+
10+
const mockGetManifest = async function () {
11+
const data = JSON.parse(`
12+
{
13+
"version":"0.0.0",
14+
"expiry":"14d",
15+
"services":[
16+
{
17+
"id":"road_map",
18+
"url":"https://proxy-tiles.elastic.co/v1/default/{z}/{x}/{y}.png",
19+
"minZoom":0,
20+
"maxZoom":12,
21+
"attribution":"© [Elastic Tile Service](https://www.elastic.co/elastic-tile-service)",
22+
"query_parameters":{
23+
"elastic_tile_service_tos":"agree",
24+
"my_app_name":"kibana"
25+
}
26+
}
27+
]
28+
}
29+
`);
30+
31+
return {
32+
data: data
33+
};
34+
};
35+
36+
beforeEach(ngMock.module('kibana'));
37+
beforeEach(ngMock.inject(function (Private, tilemapSettings, tilemapsConfig) {
38+
theTileMapSettings = tilemapSettings;
39+
theTilemapsConfig = tilemapsConfig;
40+
41+
//mock the use of a manifest
42+
theTilemapsConfig.deprecated.isOverridden = false;
43+
oldGetManifest = theTileMapSettings._getTileServiceManifest;
44+
theTileMapSettings._getTileServiceManifest = mockGetManifest;
45+
}));
46+
47+
afterEach(function () {
48+
//restore overrides.
49+
theTilemapsConfig.isOverridden = true;
50+
theTileMapSettings._getTileServiceManifest = oldGetManifest;
51+
});
52+
53+
54+
describe('getting settings', function () {
55+
56+
beforeEach(function (done) {
57+
theTileMapSettings.loadSettings().then(function () {
58+
done();
59+
});
60+
});
61+
62+
63+
it('should get url', async function () {
64+
65+
const mapUrl = theTileMapSettings.getUrl();
66+
expect(mapUrl.indexOf('{x}') > -1).to.be.ok();
67+
expect(mapUrl.indexOf('{y}') > -1).to.be.ok();
68+
expect(mapUrl.indexOf('{z}') > -1).to.be.ok();
69+
70+
const urlObject = url.parse(mapUrl, true);
71+
expect(urlObject.host.endsWith('elastic.co')).to.be.ok();
72+
expect(urlObject.query).to.have.property('my_app_name');
73+
expect(urlObject.query).to.have.property('elastic_tile_service_tos');
74+
75+
});
76+
77+
it('should get options', async function () {
78+
const options = theTileMapSettings.getOptions();
79+
expect(options).to.have.property('minZoom');
80+
expect(options).to.have.property('maxZoom');
81+
expect(options).to.have.property('attribution');
82+
});
83+
84+
});
85+
86+
describe('modify', function () {
87+
88+
beforeEach(function (done) {
89+
theTileMapSettings.addQueryParams({ foo: 'bar' });
90+
theTileMapSettings.addQueryParams({ bar: 'stool' });
91+
theTileMapSettings.addQueryParams({ foo: 'tstool' });
92+
theTileMapSettings.loadSettings().then(function () {
93+
done();
94+
});
95+
96+
});
97+
98+
99+
it('addQueryParameters', async function () {
100+
101+
const mapUrl = theTileMapSettings.getUrl();
102+
const urlObject = url.parse(mapUrl, true);
103+
expect(urlObject.query).to.have.property('foo');
104+
expect(urlObject.query).to.have.property('bar');
105+
expect(urlObject.query.foo).to.equal('tstool');
106+
expect(urlObject.query.bar).to.equal('stool');
107+
108+
});
109+
110+
111+
});
112+
113+
});

‎src/ui/public/vis_maps/lib/maps_config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import _ from 'lodash';
55

6-
export default function MapsConfigFactory(Private) {
6+
export default function MapsConfigFactory() {
77

88
const DEFAULT_VIS_CONFIG = {
99
style: {

0 commit comments

Comments
 (0)
Please sign in to comment.