diff --git a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js index 1d911643144dc2..6131ff45c4a0f6 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js +++ b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js @@ -28,6 +28,8 @@ describe('buildMapsTelemetry', () => { max: 0, min: 0, }, + emsVectorLayersCount: {}, + layerTypesCount: {}, layersCount: { avg: 0, max: 0, @@ -54,6 +56,35 @@ describe('buildMapsTelemetry', () => { max: 3, min: 2, }, + emsVectorLayersCount: { + canada_provinces: { + 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, + }, + }, + layerTypesCount: { + TILE: { + avg: 1, + max: 1, + min: 1, + }, + VECTOR: { + avg: 1.6666666666666667, + max: 2, + min: 1, + }, + }, layersCount: { avg: 2.6666666666666665, max: 3, diff --git a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts index e148a66416c7bd..0e29eca2446422 100644 --- a/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts +++ b/x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts @@ -11,13 +11,48 @@ import { SavedObjectAttribute, } from 'kibana/server'; import { IFieldType, IIndexPattern } from 'src/plugins/data/public'; -import { ES_GEO_FIELD_TYPE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; +import { SOURCE_TYPES, ES_GEO_FIELD_TYPE, MAP_SAVED_OBJECT_TYPE } from '../../common/constants'; import { LayerDescriptor } from '../../common/descriptor_types'; import { MapSavedObject } from '../../common/map_saved_object_type'; // @ts-ignore import { getInternalRepository } from '../kibana_server_services'; import { MapsConfigType } from '../../config'; +interface IStats { + [key: string]: { + min: number; + max: number; + avg: number; + }; +} + +interface ILayerTypeCount { + [key: string]: number; +} + +function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) { + const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map((lTypes) => Object.keys(lTypes)))); + + return uniqueLayerTypes.reduce((accu: IStats, type: string) => { + const typeCounts = layerCountsList.reduce( + (tCountsAccu: number[], tCounts: ILayerTypeCount): number[] => { + if (tCounts[type]) { + tCountsAccu.push(tCounts[type]); + } + return tCountsAccu; + }, + [] + ); + const typeCountsSum = _.sum(typeCounts); + accu[type] = { + min: typeCounts.length ? _.min(typeCounts) : 0, + max: typeCounts.length ? _.max(typeCounts) : 0, + avg: typeCountsSum ? typeCountsSum / mapsCount : 0, + }; + return accu; + }, {}); +} + function getIndexPatternsWithGeoFieldCount(indexPatterns: IIndexPattern[]) { const fieldLists = indexPatterns.map((indexPattern) => indexPattern.attributes && indexPattern.attributes.fields @@ -71,6 +106,19 @@ export function buildMapsTelemetry({ }); const layersCount = layerLists.map((lList) => lList.length); + const layerTypesCount = layerLists.map((lList) => _.countBy(lList, 'type')); + + // Count of EMS Vector layers used + const emsLayersCount = layerLists.map((lList) => + _(lList) + .countBy((layer: LayerDescriptor) => { + const isEmsFile = _.get(layer, 'sourceDescriptor.type') === SOURCE_TYPES.EMS_FILE; + return isEmsFile && _.get(layer, 'sourceDescriptor.id'); + }) + .pick((val, key) => key !== 'false') + .value() + ); + const dataSourcesCountSum = _.sum(dataSourcesCount); const layersCountSum = _.sum(layersCount); @@ -101,6 +149,14 @@ export function buildMapsTelemetry({ max: layersCount.length ? _.max(layersCount) : 0, avg: layersCountSum ? layersCountSum / mapsCount : 0, }, + // Count of layers by type + layerTypesCount: { + ...getUniqueLayerCounts(layerTypesCount, mapsCount), + }, + // Count of layer by EMS region + emsVectorLayersCount: { + ...getUniqueLayerCounts(emsLayersCount, mapsCount), + }, }, }; } diff --git a/x-pack/plugins/maps/server/saved_objects/maps_telemetry.ts b/x-pack/plugins/maps/server/saved_objects/maps_telemetry.ts index 8d55c638556462..01a51bc6c6547d 100644 --- a/x-pack/plugins/maps/server/saved_objects/maps_telemetry.ts +++ b/x-pack/plugins/maps/server/saved_objects/maps_telemetry.ts @@ -37,6 +37,8 @@ export const mapsTelemetrySavedObjects: SavedObjectsType = { avg: { type: 'long' }, }, }, + layerTypesCount: { type: 'object' }, + emsVectorLayersCount: { type: 'object' }, }, }, },