From f58b611271d8e42c850461f873dbbad9a69a21be Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Fri, 8 Nov 2019 16:34:02 -0700 Subject: [PATCH] [Maps] add settings to maps telemetry --- .../server/maps_telemetry/maps_telemetry.js | 11 +- .../maps_telemetry/maps_telemetry.test.js | 100 ++++++++++-------- 2 files changed, 61 insertions(+), 50 deletions(-) diff --git a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js index bd8dacb53f534..0d318c41a7fd1 100644 --- a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js +++ b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.js @@ -32,7 +32,7 @@ function getUniqueLayerCounts(layerCountsList, mapsCount) { }, {}); } -export function buildMapsTelemetry(savedObjects) { +export function buildMapsTelemetry(savedObjects, settings) { const layerLists = savedObjects .map(savedMapObject => JSON.parse(savedMapObject.attributes.layerListJSON)); @@ -57,7 +57,8 @@ export function buildMapsTelemetry(savedObjects) { const dataSourcesCountSum = _.sum(dataSourcesCount); const layersCountSum = _.sum(layersCount); - const mapsTelem = { + return { + settings, // Total count of maps mapsTotalCount: mapsCount, // Time of capture @@ -85,7 +86,6 @@ export function buildMapsTelemetry(savedObjects) { } } }; - return mapsTelem; } async function getSavedObjects(savedObjectsClient) { @@ -98,7 +98,10 @@ async function getSavedObjects(savedObjectsClient) { export async function getMapsTelemetry(server, callCluster) { const savedObjectsClient = getSavedObjectsClient(server, callCluster); const savedObjects = await getSavedObjects(savedObjectsClient); - const mapsTelemetry = buildMapsTelemetry(savedObjects); + const settings = { + showMapVisualizationTypes: server.config().get('xpack.maps.showMapVisualizationTypes') + }; + const mapsTelemetry = buildMapsTelemetry(savedObjects, settings); return await savedObjectsClient.create('maps-telemetry', mapsTelemetry, { diff --git a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.test.js b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.test.js index d2f7b47577005..4f2b983a54028 100644 --- a/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.test.js +++ b/x-pack/legacy/plugins/maps/server/maps_telemetry/maps_telemetry.test.js @@ -10,79 +10,87 @@ import { buildMapsTelemetry } from './maps_telemetry'; describe('buildMapsTelemetry', () => { + const settings = { showMapVisualizationTypes: false }; + test('returns zeroed telemetry data when there are no saved objects', async () => { const gisMaps = []; - const result = buildMapsTelemetry(gisMaps); + const result = buildMapsTelemetry(gisMaps, settings); expect(result).toMatchObject({ - 'attributesPerMap': { - 'dataSourcesCount': { - 'avg': 0, - 'max': 0, - 'min': 0 + attributesPerMap: { + dataSourcesCount: { + avg: 0, + max: 0, + min: 0 }, - 'emsVectorLayersCount': {}, - 'layerTypesCount': {}, - 'layersCount': { - 'avg': 0, - 'max': 0, - 'min': 0 + emsVectorLayersCount: {}, + layerTypesCount: {}, + layersCount: { + avg: 0, + max: 0, + min: 0 } }, - 'mapsTotalCount': 0 + mapsTotalCount: 0, + settings: { + showMapVisualizationTypes: false + } }); }); test('returns expected telemetry data from saved objects', async () => { const gisMaps = savedObjectsPayload.saved_objects; - const result = buildMapsTelemetry(gisMaps); + const result = buildMapsTelemetry(gisMaps, settings); expect(result).toMatchObject({ - 'attributesPerMap': { - 'dataSourcesCount': { - 'avg': 2.6666666666666665, - 'max': 3, - 'min': 2 + attributesPerMap: { + dataSourcesCount: { + avg: 2.6666666666666665, + max: 3, + min: 2 }, - 'emsVectorLayersCount': { - 'canada_provinces': { - 'avg': 0.3333333333333333, - 'max': 1, - 'min': 1 + emsVectorLayersCount: { + canada_provinces: { + avg: 0.3333333333333333, + max: 1, + min: 1 }, - 'france_departments': { - 'avg': 0.3333333333333333, - 'max': 1, - 'min': 1 + france_departments: { + avg: 0.3333333333333333, + max: 1, + min: 1 }, - 'italy_provinces': { - 'avg': 0.3333333333333333, - 'max': 1, - 'min': 1 + italy_provinces: { + avg: 0.3333333333333333, + max: 1, + min: 1 } }, - 'layerTypesCount': { - 'TILE': { - 'avg': 1, - 'max': 1, - 'min': 1 + layerTypesCount: { + TILE: { + avg: 1, + max: 1, + min: 1 }, - 'VECTOR': { - 'avg': 1.6666666666666667, - 'max': 2, - 'min': 1 + VECTOR: { + avg: 1.6666666666666667, + max: 2, + min: 1 } }, - 'layersCount': { - 'avg': 2.6666666666666665, - 'max': 3, - 'min': 2 + layersCount: { + avg: 2.6666666666666665, + max: 3, + min: 2 } }, - 'mapsTotalCount': 3 + mapsTotalCount: 3, + settings: { + showMapVisualizationTypes: false + } }); }); });