Skip to content

Commit c3c1a2b

Browse files
[Maps] [Telemetry] Count indices with geo-fields (#51221)
1 parent 05f765a commit c3c1a2b

File tree

5 files changed

+205
-158
lines changed

5 files changed

+205
-158
lines changed

x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import _ from 'lodash';
8-
import { EMS_FILE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
8+
import { EMS_FILE, ES_GEO_FIELD_TYPE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
99

1010
function getSavedObjectsClient(server, callCluster) {
1111
const { SavedObjectsClient, getSavedObjectsRepository } = server.savedObjects;
@@ -32,8 +32,16 @@ function getUniqueLayerCounts(layerCountsList, mapsCount) {
3232
}, {});
3333
}
3434

35-
export function buildMapsTelemetry(savedObjects, settings) {
36-
const layerLists = savedObjects
35+
function getIndexPatternsWithGeoFieldCount(indexPatterns) {
36+
const fieldLists = indexPatterns.map(indexPattern => JSON.parse(indexPattern.attributes.fields));
37+
const fieldListsWithGeoFields = fieldLists.filter(fields => {
38+
return fields.some(field => (field.type === ES_GEO_FIELD_TYPE.GEO_POINT || field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE));
39+
});
40+
return fieldListsWithGeoFields.length;
41+
}
42+
43+
export function buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings }) {
44+
const layerLists = mapSavedObjects
3745
.map(savedMapObject =>
3846
JSON.parse(savedMapObject.attributes.layerListJSON));
3947
const mapsCount = layerLists.length;
@@ -57,8 +65,11 @@ export function buildMapsTelemetry(savedObjects, settings) {
5765

5866
const dataSourcesCountSum = _.sum(dataSourcesCount);
5967
const layersCountSum = _.sum(layersCount);
68+
69+
const indexPatternsWithGeoFieldCount = getIndexPatternsWithGeoFieldCount(indexPatternSavedObjects);
6070
return {
6171
settings,
72+
indexPatternsWithGeoFieldCount,
6273
// Total count of maps
6374
mapsTotalCount: mapsCount,
6475
// Time of capture
@@ -88,24 +99,23 @@ export function buildMapsTelemetry(savedObjects, settings) {
8899
};
89100
}
90101

91-
async function getSavedObjects(savedObjectsClient) {
92-
const gisMapsSavedObject = await savedObjectsClient.find({
93-
type: MAP_SAVED_OBJECT_TYPE
94-
});
95-
return _.get(gisMapsSavedObject, 'saved_objects');
102+
async function getMapSavedObjects(savedObjectsClient) {
103+
const mapsSavedObjects = await savedObjectsClient.find({ type: MAP_SAVED_OBJECT_TYPE });
104+
return _.get(mapsSavedObjects, 'saved_objects', []);
105+
}
106+
107+
async function getIndexPatternSavedObjects(savedObjectsClient) {
108+
const indexPatternSavedObjects = await savedObjectsClient.find({ type: 'index-pattern' });
109+
return _.get(indexPatternSavedObjects, 'saved_objects', []);
96110
}
97111

98112
export async function getMapsTelemetry(server, callCluster) {
99113
const savedObjectsClient = getSavedObjectsClient(server, callCluster);
100-
const savedObjects = await getSavedObjects(savedObjectsClient);
114+
const mapSavedObjects = await getMapSavedObjects(savedObjectsClient);
115+
const indexPatternSavedObjects = await getIndexPatternSavedObjects(savedObjectsClient);
101116
const settings = {
102117
showMapVisualizationTypes: server.config().get('xpack.maps.showMapVisualizationTypes')
103118
};
104-
const mapsTelemetry = buildMapsTelemetry(savedObjects, settings);
105-
106-
return await savedObjectsClient.create('maps-telemetry',
107-
mapsTelemetry, {
108-
id: 'maps-telemetry',
109-
overwrite: true,
110-
});
119+
const mapsTelemetry = buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });
120+
return await savedObjectsClient.create('maps-telemetry', mapsTelemetry, { id: 'maps-telemetry', overwrite: true });
111121
}

x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import * as savedObjectsPayload from
8-
'./test_resources/sample_saved_objects.json';
7+
import mapSavedObjects from './test_resources/sample_map_saved_objects.json';
8+
import indexPatternSavedObjects from './test_resources/sample_index_pattern_saved_objects';
99
import { buildMapsTelemetry } from './maps_telemetry';
1010

1111
describe('buildMapsTelemetry', () => {
@@ -15,10 +15,10 @@ describe('buildMapsTelemetry', () => {
1515
test('returns zeroed telemetry data when there are no saved objects',
1616
async () => {
1717

18-
const gisMaps = [];
19-
const result = buildMapsTelemetry(gisMaps, settings);
18+
const result = buildMapsTelemetry({ mapSavedObjects: [], indexPatternSavedObjects: [], settings });
2019

2120
expect(result).toMatchObject({
21+
indexPatternsWithGeoFieldCount: 0,
2222
attributesPerMap: {
2323
dataSourcesCount: {
2424
avg: 0,
@@ -42,10 +42,10 @@ describe('buildMapsTelemetry', () => {
4242

4343
test('returns expected telemetry data from saved objects', async () => {
4444

45-
const gisMaps = savedObjectsPayload.saved_objects;
46-
const result = buildMapsTelemetry(gisMaps, settings);
45+
const result = buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });
4746

4847
expect(result).toMatchObject({
48+
indexPatternsWithGeoFieldCount: 2,
4949
attributesPerMap: {
5050
dataSourcesCount: {
5151
avg: 2.6666666666666665,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
{
3+
"attributes": {
4+
"fields": "[{\"name\":\"geometry\",\"type\":\"geo_shape\",\"esTypes\":[\"geo_shape\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false}]",
5+
"timeFieldName": "ORIG_DATE",
6+
"title": "indexpattern-with-geoshape"
7+
},
8+
"id": "4a7f6010-0aed-11ea-9dd2-95afd7ad44d4",
9+
"migrationVersion": {
10+
"index-pattern": "7.6.0"
11+
},
12+
"references": [],
13+
"type": "index-pattern",
14+
"updated_at": "2019-11-19T16:54:46.405Z",
15+
"version": "Wzg0LDFd"
16+
},
17+
{
18+
"attributes": {
19+
"fields": "[{\"name\":\"geometry\",\"type\":\"geo_point\",\"esTypes\":[\"geo_point\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]",
20+
"title": "indexpattern-with-geopoint"
21+
},
22+
"id": "55d572f0-0b07-11ea-9dd2-95afd7ad44d4",
23+
"migrationVersion": {
24+
"index-pattern": "7.6.0"
25+
},
26+
"references": [],
27+
"type": "index-pattern",
28+
"updated_at": "2019-11-19T20:05:37.607Z",
29+
"version": "WzExMSwxXQ=="
30+
},
31+
{
32+
"attributes": {
33+
"fields": "[{\"name\":\"assessment_date\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"name\":\"date_exterior_condition\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"name\":\"recording_date\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true},{\"name\":\"sale_date\",\"type\":\"date\",\"esTypes\":[\"date\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]",
34+
"title": "indexpattern-without-geo"
35+
},
36+
"id": "55d572f0-0b07-11ea-9dd2-95afd7ad44d4",
37+
"migrationVersion": {
38+
"index-pattern": "7.6.0"
39+
},
40+
"references": [],
41+
"type": "index-pattern",
42+
"updated_at": "2019-11-19T20:05:37.607Z",
43+
"version": "WzExMSwxXQ=="
44+
}
45+
]
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
[
2+
{
3+
"type": "gis-map",
4+
"id": "37b08d60-25b0-11e9-9858-0f3a1e60d007",
5+
"attributes": {
6+
"title": "Italy Map",
7+
"description": "",
8+
"mapStateJSON": "{\"zoom\":4.82,\"center\":{\"lon\":11.41545,\"lat\":42.0865},\"timeFilters\":{\"from\":\"now-15w\",\"to\":\"now\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"language\":\"lucene\",\"query\":\"\"}}",
9+
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"italy_provinces\"},\"id\":\"0oye8\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#0c1f70\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"},{\"sourceDescriptor\":{\"type\":\"ES_GEO_GRID\",\"id\":\"053fe296-f5ae-4cb0-9e73-a5752cb9ba74\",\"indexPatternId\":\"d3d7af60-4c81-11e8-b3d7-01146121b73d\",\"geoField\":\"DestLocation\",\"requestType\":\"point\",\"resolution\":\"COARSE\"},\"id\":\"1gx22\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"color\":\"Greens\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"DYNAMIC\",\"options\":{\"field\":{\"label\":\"Count\",\"name\":\"doc_count\",\"origin\":\"source\"},\"minSize\":4,\"maxSize\":32}}}},\"type\":\"VECTOR\"}]",
10+
"uiStateJSON": "{}",
11+
"bounds": {
12+
"type": "polygon",
13+
"coordinates": [
14+
[
15+
[
16+
-5.29778,
17+
51.54155
18+
],
19+
[
20+
-5.29778,
21+
30.98066
22+
],
23+
[
24+
28.12868,
25+
30.98066
26+
],
27+
[
28+
28.12868,
29+
51.54155
30+
],
31+
[
32+
-5.29778,
33+
51.54155
34+
]
35+
]
36+
]
37+
}
38+
},
39+
"references": [
40+
],
41+
"updated_at": "2019-01-31T23:30:39.030Z",
42+
"version": 1
43+
},
44+
{
45+
"type": "gis-map",
46+
"id": "5c061dc0-25af-11e9-9858-0f3a1e60d007",
47+
"attributes": {
48+
"title": "France Map",
49+
"description": "",
50+
"mapStateJSON": "{\"zoom\":3.43,\"center\":{\"lon\":-16.30411,\"lat\":42.88411},\"timeFilters\":{\"from\":\"now-15w\",\"to\":\"now\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"query\":\"\",\"language\":\"lucene\"}}",
51+
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"france_departments\"},\"id\":\"65xbw\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.25,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#19c1e6\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"},{\"sourceDescriptor\":{\"id\":\"240125db-e612-4001-b853-50107e55d984\",\"type\":\"ES_SEARCH\",\"indexPatternId\":\"ff959d40-b880-11e8-a6d9-e546fe2bba5f\",\"geoField\":\"geoip.location\",\"limit\":2048,\"filterByMapBounds\":true,\"tooltipProperties\":[]},\"id\":\"mdae9\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#1ce619\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"}]",
52+
"uiStateJSON": "{}",
53+
"bounds": {
54+
"type": "polygon",
55+
"coordinates": [
56+
[
57+
[
58+
-59.97005,
59+
63.9123
60+
],
61+
[
62+
-59.97005,
63+
11.25616
64+
],
65+
[
66+
27.36184,
67+
11.25616
68+
],
69+
[
70+
27.36184,
71+
63.9123
72+
],
73+
[
74+
-59.97005,
75+
63.9123
76+
]
77+
]
78+
]
79+
}
80+
},
81+
"references": [
82+
],
83+
"updated_at": "2019-01-31T23:24:30.492Z",
84+
"version": 1
85+
},
86+
{
87+
"type": "gis-map",
88+
"id": "b853d5f0-25ae-11e9-9858-0f3a1e60d007",
89+
"attributes": {
90+
"title": "Canada Map",
91+
"description": "",
92+
"mapStateJSON": "{\"zoom\":2.12,\"center\":{\"lon\":-88.67592,\"lat\":34.23257},\"timeFilters\":{\"from\":\"now-15m\",\"to\":\"now\",\"mode\":\"quick\"},\"refreshConfig\":{\"isPaused\":false,\"interval\":0},\"query\":{\"query\":\"\",\"language\":\"lucene\"}}",
93+
"layerListJSON": "[{\"sourceDescriptor\":{\"type\":\"EMS_TMS\",\"id\":\"road_map\"},\"id\":\"csq5v\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.65,\"visible\":true,\"style\":{\"type\":\"TILE\",\"properties\":{}},\"type\":\"TILE\"},{\"sourceDescriptor\":{\"type\":\"EMS_FILE\",\"id\":\"canada_provinces\"},\"id\":\"kt086\",\"label\":null,\"minZoom\":0,\"maxZoom\":24,\"alpha\":0.75,\"visible\":true,\"style\":{\"type\":\"VECTOR\",\"properties\":{\"fillColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#60895e\"}},\"lineColor\":{\"type\":\"STATIC\",\"options\":{\"color\":\"#FFFFFF\"}},\"lineWidth\":{\"type\":\"STATIC\",\"options\":{\"size\":1}},\"iconSize\":{\"type\":\"STATIC\",\"options\":{\"size\":10}}}},\"type\":\"VECTOR\"}]",
94+
"uiStateJSON": "{}",
95+
"bounds": {
96+
"type": "polygon",
97+
"coordinates": [
98+
[
99+
[
100+
163.37506,
101+
77.35215
102+
],
103+
[
104+
163.37506,
105+
-46.80667
106+
],
107+
[
108+
19.2731,
109+
-46.80667
110+
],
111+
[
112+
19.2731,
113+
77.35215
114+
],
115+
[
116+
163.37506,
117+
77.35215
118+
]
119+
]
120+
]
121+
}
122+
},
123+
"references": [
124+
],
125+
"updated_at": "2019-01-31T23:19:55.855Z",
126+
"version": 1
127+
}
128+
]

0 commit comments

Comments
 (0)