Skip to content

Commit

Permalink
[Maps] [Telemetry] Count indices with geo-fields (#51221)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Nov 21, 2019
1 parent 7f9f164 commit 0ad9dd9
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 158 deletions.
42 changes: 26 additions & 16 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import _ from 'lodash';
import { EMS_FILE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants';
import { EMS_FILE, ES_GEO_FIELD_TYPE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants';

function getSavedObjectsClient(server, callCluster) {
const { SavedObjectsClient, getSavedObjectsRepository } = server.savedObjects;
Expand All @@ -32,8 +32,16 @@ function getUniqueLayerCounts(layerCountsList, mapsCount) {
}, {});
}

export function buildMapsTelemetry(savedObjects, settings) {
const layerLists = savedObjects
function getIndexPatternsWithGeoFieldCount(indexPatterns) {
const fieldLists = indexPatterns.map(indexPattern => JSON.parse(indexPattern.attributes.fields));
const fieldListsWithGeoFields = fieldLists.filter(fields => {
return fields.some(field => (field.type === ES_GEO_FIELD_TYPE.GEO_POINT || field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE));
});
return fieldListsWithGeoFields.length;
}

export function buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings }) {
const layerLists = mapSavedObjects
.map(savedMapObject =>
JSON.parse(savedMapObject.attributes.layerListJSON));
const mapsCount = layerLists.length;
Expand All @@ -57,8 +65,11 @@ export function buildMapsTelemetry(savedObjects, settings) {

const dataSourcesCountSum = _.sum(dataSourcesCount);
const layersCountSum = _.sum(layersCount);

const indexPatternsWithGeoFieldCount = getIndexPatternsWithGeoFieldCount(indexPatternSavedObjects);
return {
settings,
indexPatternsWithGeoFieldCount,
// Total count of maps
mapsTotalCount: mapsCount,
// Time of capture
Expand Down Expand Up @@ -88,24 +99,23 @@ export function buildMapsTelemetry(savedObjects, settings) {
};
}

async function getSavedObjects(savedObjectsClient) {
const gisMapsSavedObject = await savedObjectsClient.find({
type: MAP_SAVED_OBJECT_TYPE
});
return _.get(gisMapsSavedObject, 'saved_objects');
async function getMapSavedObjects(savedObjectsClient) {
const mapsSavedObjects = await savedObjectsClient.find({ type: MAP_SAVED_OBJECT_TYPE });
return _.get(mapsSavedObjects, 'saved_objects', []);
}

async function getIndexPatternSavedObjects(savedObjectsClient) {
const indexPatternSavedObjects = await savedObjectsClient.find({ type: 'index-pattern' });
return _.get(indexPatternSavedObjects, 'saved_objects', []);
}

export async function getMapsTelemetry(server, callCluster) {
const savedObjectsClient = getSavedObjectsClient(server, callCluster);
const savedObjects = await getSavedObjects(savedObjectsClient);
const mapSavedObjects = await getMapSavedObjects(savedObjectsClient);
const indexPatternSavedObjects = await getIndexPatternSavedObjects(savedObjectsClient);
const settings = {
showMapVisualizationTypes: server.config().get('xpack.maps.showMapVisualizationTypes')
};
const mapsTelemetry = buildMapsTelemetry(savedObjects, settings);

return await savedObjectsClient.create('maps-telemetry',
mapsTelemetry, {
id: 'maps-telemetry',
overwrite: true,
});
const mapsTelemetry = buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });
return await savedObjectsClient.create('maps-telemetry', mapsTelemetry, { id: 'maps-telemetry', overwrite: true });
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as savedObjectsPayload from
'./test_resources/sample_saved_objects.json';
import mapSavedObjects from './test_resources/sample_map_saved_objects.json';
import indexPatternSavedObjects from './test_resources/sample_index_pattern_saved_objects';
import { buildMapsTelemetry } from './maps_telemetry';

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

const gisMaps = [];
const result = buildMapsTelemetry(gisMaps, settings);
const result = buildMapsTelemetry({ mapSavedObjects: [], indexPatternSavedObjects: [], settings });

expect(result).toMatchObject({
indexPatternsWithGeoFieldCount: 0,
attributesPerMap: {
dataSourcesCount: {
avg: 0,
Expand All @@ -42,10 +42,10 @@ describe('buildMapsTelemetry', () => {

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

const gisMaps = savedObjectsPayload.saved_objects;
const result = buildMapsTelemetry(gisMaps, settings);
const result = buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });

expect(result).toMatchObject({
indexPatternsWithGeoFieldCount: 2,
attributesPerMap: {
dataSourcesCount: {
avg: 2.6666666666666665,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"attributes": {
"fields": "[{\"name\":\"geometry\",\"type\":\"geo_shape\",\"esTypes\":[\"geo_shape\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":false,\"readFromDocValues\":false}]",
"timeFieldName": "ORIG_DATE",
"title": "indexpattern-with-geoshape"
},
"id": "4a7f6010-0aed-11ea-9dd2-95afd7ad44d4",
"migrationVersion": {
"index-pattern": "7.6.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2019-11-19T16:54:46.405Z",
"version": "Wzg0LDFd"
},
{
"attributes": {
"fields": "[{\"name\":\"geometry\",\"type\":\"geo_point\",\"esTypes\":[\"geo_point\"],\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]",
"title": "indexpattern-with-geopoint"
},
"id": "55d572f0-0b07-11ea-9dd2-95afd7ad44d4",
"migrationVersion": {
"index-pattern": "7.6.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2019-11-19T20:05:37.607Z",
"version": "WzExMSwxXQ=="
},
{
"attributes": {
"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}]",
"title": "indexpattern-without-geo"
},
"id": "55d572f0-0b07-11ea-9dd2-95afd7ad44d4",
"migrationVersion": {
"index-pattern": "7.6.0"
},
"references": [],
"type": "index-pattern",
"updated_at": "2019-11-19T20:05:37.607Z",
"version": "WzExMSwxXQ=="
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
[
{
"type": "gis-map",
"id": "37b08d60-25b0-11e9-9858-0f3a1e60d007",
"attributes": {
"title": "Italy Map",
"description": "",
"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\":\"\"}}",
"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\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
-5.29778,
51.54155
],
[
-5.29778,
30.98066
],
[
28.12868,
30.98066
],
[
28.12868,
51.54155
],
[
-5.29778,
51.54155
]
]
]
}
},
"references": [
],
"updated_at": "2019-01-31T23:30:39.030Z",
"version": 1
},
{
"type": "gis-map",
"id": "5c061dc0-25af-11e9-9858-0f3a1e60d007",
"attributes": {
"title": "France Map",
"description": "",
"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\"}}",
"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\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
-59.97005,
63.9123
],
[
-59.97005,
11.25616
],
[
27.36184,
11.25616
],
[
27.36184,
63.9123
],
[
-59.97005,
63.9123
]
]
]
}
},
"references": [
],
"updated_at": "2019-01-31T23:24:30.492Z",
"version": 1
},
{
"type": "gis-map",
"id": "b853d5f0-25ae-11e9-9858-0f3a1e60d007",
"attributes": {
"title": "Canada Map",
"description": "",
"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\"}}",
"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\"}]",
"uiStateJSON": "{}",
"bounds": {
"type": "polygon",
"coordinates": [
[
[
163.37506,
77.35215
],
[
163.37506,
-46.80667
],
[
19.2731,
-46.80667
],
[
19.2731,
77.35215
],
[
163.37506,
77.35215
]
]
]
}
},
"references": [
],
"updated_at": "2019-01-31T23:19:55.855Z",
"version": 1
}
]
Loading

0 comments on commit 0ad9dd9

Please sign in to comment.