mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Maps] Move layer stats collector logic to common (#135754)
This commit is contained in:
parent
6d3b05255b
commit
cd1e67cd2c
10 changed files with 478 additions and 288 deletions
15
x-pack/plugins/maps/common/telemetry/index.ts
Normal file
15
x-pack/plugins/maps/common/telemetry/index.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
export { LayerStatsCollector } from './layer_stats_collector';
|
||||
export type {
|
||||
EMS_BASEMAP_KEYS,
|
||||
JOIN_KEYS,
|
||||
LAYER_KEYS,
|
||||
RESOLUTION_KEYS,
|
||||
SCALING_KEYS,
|
||||
} from './types';
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
// @ts-ignore
|
||||
import mapSavedObjects from './test_resources/sample_map_saved_objects.json';
|
||||
import { LayerStatsCollector } from './layer_stats_collector';
|
||||
import { MapSavedObjectAttributes } from '../map_saved_object_type';
|
||||
|
||||
const expecteds = [
|
||||
{
|
||||
layerCount: 3,
|
||||
basemapCounts: { roadmap: 1 },
|
||||
joinCounts: {},
|
||||
layerCounts: { ems_basemap: 1, ems_region: 1, es_agg_clusters: 1 },
|
||||
resolutionCounts: { coarse: 1 },
|
||||
scalingCounts: {},
|
||||
emsFileCounts: { italy_provinces: 1 },
|
||||
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 2 },
|
||||
sourceCount: 3,
|
||||
},
|
||||
{
|
||||
layerCount: 3,
|
||||
basemapCounts: { roadmap: 1 },
|
||||
joinCounts: { term: 1 },
|
||||
layerCounts: { ems_basemap: 1, ems_region: 1, es_docs: 1 },
|
||||
resolutionCounts: {},
|
||||
scalingCounts: { limit: 1 },
|
||||
emsFileCounts: { france_departments: 1 },
|
||||
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 2 },
|
||||
sourceCount: 3,
|
||||
},
|
||||
{
|
||||
layerCount: 2,
|
||||
basemapCounts: { roadmap: 1 },
|
||||
joinCounts: {},
|
||||
layerCounts: { ems_basemap: 1, ems_region: 1 },
|
||||
resolutionCounts: {},
|
||||
scalingCounts: {},
|
||||
emsFileCounts: { canada_provinces: 1 },
|
||||
layerTypeCounts: { TILE: 1, GEOJSON_VECTOR: 1 },
|
||||
sourceCount: 2,
|
||||
},
|
||||
{
|
||||
layerCount: 1,
|
||||
basemapCounts: {},
|
||||
joinCounts: {},
|
||||
layerCounts: { es_agg_clusters: 1 },
|
||||
resolutionCounts: { coarse: 1 },
|
||||
scalingCounts: {},
|
||||
emsFileCounts: {},
|
||||
layerTypeCounts: { GEOJSON_VECTOR: 1 },
|
||||
sourceCount: 1,
|
||||
},
|
||||
{
|
||||
layerCount: 1,
|
||||
basemapCounts: {},
|
||||
joinCounts: {},
|
||||
layerCounts: { es_agg_heatmap: 1 },
|
||||
resolutionCounts: { coarse: 1 },
|
||||
scalingCounts: {},
|
||||
emsFileCounts: {},
|
||||
layerTypeCounts: { HEATMAP: 1 },
|
||||
sourceCount: 1,
|
||||
},
|
||||
];
|
||||
|
||||
const testsToRun = mapSavedObjects.map(
|
||||
(savedObject: { attributes: MapSavedObjectAttributes }, index: number) => {
|
||||
const { attributes } = savedObject;
|
||||
return [attributes, expecteds[index]] as const;
|
||||
}
|
||||
);
|
||||
|
||||
describe.each(testsToRun)('LayerStatsCollector %#', (attributes, expected) => {
|
||||
const statsCollector = new LayerStatsCollector(attributes);
|
||||
test('getLayerCount', () => {
|
||||
expect(statsCollector.getLayerCount()).toBe(expected.layerCount);
|
||||
});
|
||||
|
||||
test('getBasemapCounts', () => {
|
||||
expect(statsCollector.getBasemapCounts()).toEqual(expected.basemapCounts);
|
||||
});
|
||||
|
||||
test('getJoinCounts', () => {
|
||||
expect(statsCollector.getJoinCounts()).toEqual(expected.joinCounts);
|
||||
});
|
||||
|
||||
test('getLayerCounts', () => {
|
||||
expect(statsCollector.getLayerCounts()).toEqual(expected.layerCounts);
|
||||
});
|
||||
|
||||
test('getResolutionCounts', () => {
|
||||
expect(statsCollector.getResolutionCounts()).toEqual(expected.resolutionCounts);
|
||||
});
|
||||
|
||||
test('getScalingCounts', () => {
|
||||
expect(statsCollector.getScalingCounts()).toEqual(expected.scalingCounts);
|
||||
});
|
||||
|
||||
test('getEmsFileCounts', () => {
|
||||
expect(statsCollector.getEmsFileCounts()).toEqual(expected.emsFileCounts);
|
||||
});
|
||||
|
||||
test('getSourceCount', () => {
|
||||
expect(statsCollector.getSourceCount()).toEqual(expected.sourceCount);
|
||||
});
|
||||
});
|
276
x-pack/plugins/maps/common/telemetry/layer_stats_collector.ts
Normal file
276
x-pack/plugins/maps/common/telemetry/layer_stats_collector.ts
Normal file
|
@ -0,0 +1,276 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
DEFAULT_EMS_DARKMAP_ID,
|
||||
DEFAULT_EMS_ROADMAP_DESATURATED_ID,
|
||||
DEFAULT_EMS_ROADMAP_ID,
|
||||
} from '@kbn/maps-ems-plugin/common';
|
||||
import { GRID_RESOLUTION, LAYER_TYPE, RENDER_AS, SCALING_TYPES, SOURCE_TYPES } from '../constants';
|
||||
import {
|
||||
EMSTMSSourceDescriptor,
|
||||
EMSFileSourceDescriptor,
|
||||
ESGeoGridSourceDescriptor,
|
||||
ESSearchSourceDescriptor,
|
||||
LayerDescriptor,
|
||||
VectorLayerDescriptor,
|
||||
} from '../descriptor_types';
|
||||
import { MapSavedObjectAttributes } from '../map_saved_object_type';
|
||||
import { EMS_BASEMAP_KEYS, JOIN_KEYS, LAYER_KEYS, RESOLUTION_KEYS, SCALING_KEYS } from './types';
|
||||
|
||||
export class LayerStatsCollector {
|
||||
private _layerCount = 0;
|
||||
|
||||
private _basemapCounts: { [key in EMS_BASEMAP_KEYS]?: number } = {};
|
||||
private _joinCounts: { [key in JOIN_KEYS]?: number } = {};
|
||||
private _layerCounts: { [key in LAYER_KEYS]?: number } = {};
|
||||
private _resolutionCounts: { [key in RESOLUTION_KEYS]?: number } = {};
|
||||
private _scalingCounts: { [key in SCALING_KEYS]?: number } = {};
|
||||
private _emsFileCounts: { [key: string]: number } = {};
|
||||
private _layerTypeCounts: { [key: string]: number } = {};
|
||||
private _sourceIds: Set<string> = new Set();
|
||||
|
||||
constructor(attributes: MapSavedObjectAttributes) {
|
||||
if (!attributes || !attributes.layerListJSON) {
|
||||
return;
|
||||
}
|
||||
|
||||
let layerList: LayerDescriptor[] = [];
|
||||
try {
|
||||
layerList = JSON.parse(attributes.layerListJSON);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._layerCount = layerList.length;
|
||||
layerList.forEach((layerDescriptor) => {
|
||||
this._updateCounts(getBasemapKey(layerDescriptor), this._basemapCounts);
|
||||
this._updateCounts(getJoinKey(layerDescriptor), this._joinCounts);
|
||||
this._updateCounts(getLayerKey(layerDescriptor), this._layerCounts);
|
||||
this._updateCounts(getResolutionKey(layerDescriptor), this._resolutionCounts);
|
||||
this._updateCounts(getScalingKey(layerDescriptor), this._scalingCounts);
|
||||
this._updateCounts(getEmsFileId(layerDescriptor), this._emsFileCounts);
|
||||
if (layerDescriptor.type) {
|
||||
this._updateCounts(layerDescriptor.type, this._layerTypeCounts);
|
||||
}
|
||||
if (layerDescriptor.sourceDescriptor?.id) {
|
||||
this._sourceIds.add(layerDescriptor.sourceDescriptor.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getLayerCount() {
|
||||
return this._layerCount;
|
||||
}
|
||||
|
||||
getBasemapCounts() {
|
||||
return this._basemapCounts;
|
||||
}
|
||||
|
||||
getJoinCounts() {
|
||||
return this._joinCounts;
|
||||
}
|
||||
|
||||
getLayerCounts() {
|
||||
return this._layerCounts;
|
||||
}
|
||||
|
||||
getResolutionCounts() {
|
||||
return this._resolutionCounts;
|
||||
}
|
||||
|
||||
getScalingCounts() {
|
||||
return this._scalingCounts;
|
||||
}
|
||||
|
||||
getEmsFileCounts() {
|
||||
return this._emsFileCounts;
|
||||
}
|
||||
|
||||
getLayerTypeCounts() {
|
||||
return this._layerTypeCounts;
|
||||
}
|
||||
|
||||
getSourceCount() {
|
||||
return this._sourceIds.size;
|
||||
}
|
||||
|
||||
_updateCounts(key: string | null, counts: { [key: string]: number }) {
|
||||
if (key) {
|
||||
if (key in counts) {
|
||||
counts[key] += 1;
|
||||
} else {
|
||||
counts[key] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getEmsFileId(layerDescriptor: LayerDescriptor): string | null {
|
||||
return layerDescriptor.sourceDescriptor !== null &&
|
||||
layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_FILE &&
|
||||
'id' in layerDescriptor.sourceDescriptor
|
||||
? (layerDescriptor.sourceDescriptor as EMSFileSourceDescriptor).id
|
||||
: null;
|
||||
}
|
||||
|
||||
function getBasemapKey(layerDescriptor: LayerDescriptor): EMS_BASEMAP_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.EMS_TMS
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as EMSTMSSourceDescriptor;
|
||||
|
||||
if (descriptor.isAutoSelect) {
|
||||
return EMS_BASEMAP_KEYS.AUTO;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_ROADMAP_ID) {
|
||||
return EMS_BASEMAP_KEYS.ROADMAP;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_ROADMAP_DESATURATED_ID) {
|
||||
return EMS_BASEMAP_KEYS.ROADMAP_DESATURATED;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_DARKMAP_ID) {
|
||||
return EMS_BASEMAP_KEYS.DARK;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getJoinKey(layerDescriptor: LayerDescriptor): JOIN_KEYS | null {
|
||||
return layerDescriptor.type === LAYER_TYPE.GEOJSON_VECTOR &&
|
||||
(layerDescriptor as VectorLayerDescriptor)?.joins?.length
|
||||
? JOIN_KEYS.TERM
|
||||
: null;
|
||||
}
|
||||
|
||||
function getLayerKey(layerDescriptor: LayerDescriptor): LAYER_KEYS | null {
|
||||
if (!layerDescriptor.sourceDescriptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (layerDescriptor.type === LAYER_TYPE.HEATMAP) {
|
||||
return LAYER_KEYS.ES_AGG_HEATMAP;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_FILE) {
|
||||
return LAYER_KEYS.EMS_REGION;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_TMS) {
|
||||
return LAYER_KEYS.EMS_BASEMAP;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.KIBANA_TILEMAP) {
|
||||
return LAYER_KEYS.KBN_TMS_RASTER;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_XYZ) {
|
||||
return LAYER_KEYS.UX_TMS_RASTER;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.WMS) {
|
||||
return LAYER_KEYS.UX_WMS;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.MVT_SINGLE_LAYER) {
|
||||
return LAYER_KEYS.UX_TMS_MVT;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_GEO_LINE) {
|
||||
return LAYER_KEYS.ES_TRACKS;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_PEW_PEW) {
|
||||
return LAYER_KEYS.ES_POINT_TO_POINT;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_SEARCH) {
|
||||
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor;
|
||||
|
||||
if (sourceDescriptor.scalingType === SCALING_TYPES.TOP_HITS) {
|
||||
return LAYER_KEYS.ES_TOP_HITS;
|
||||
} else {
|
||||
return LAYER_KEYS.ES_DOCS;
|
||||
}
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_GEO_GRID) {
|
||||
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor;
|
||||
if (sourceDescriptor.requestType === RENDER_AS.POINT) {
|
||||
return LAYER_KEYS.ES_AGG_CLUSTERS;
|
||||
} else if (sourceDescriptor.requestType === RENDER_AS.GRID) {
|
||||
return LAYER_KEYS.ES_AGG_GRIDS;
|
||||
} else if (sourceDescriptor.requestType === RENDER_AS.HEX) {
|
||||
return LAYER_KEYS.ES_AGG_HEXAGONS;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getResolutionKey(layerDescriptor: LayerDescriptor): RESOLUTION_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.ES_GEO_GRID ||
|
||||
!(layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor).resolution
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor;
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.COARSE) {
|
||||
return RESOLUTION_KEYS.COARSE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.FINE) {
|
||||
return RESOLUTION_KEYS.FINE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.MOST_FINE) {
|
||||
return RESOLUTION_KEYS.MOST_FINE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.SUPER_FINE) {
|
||||
return RESOLUTION_KEYS.SUPER_FINE;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getScalingKey(layerDescriptor: LayerDescriptor): SCALING_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.ES_SEARCH ||
|
||||
!(layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor).scalingType
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor;
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.CLUSTERS) {
|
||||
return SCALING_KEYS.CLUSTERS;
|
||||
}
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.MVT) {
|
||||
return SCALING_KEYS.MVT;
|
||||
}
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.LIMIT) {
|
||||
return SCALING_KEYS.LIMIT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
47
x-pack/plugins/maps/common/telemetry/types.ts
Normal file
47
x-pack/plugins/maps/common/telemetry/types.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
export enum EMS_BASEMAP_KEYS {
|
||||
ROADMAP_DESATURATED = 'roadmap_desaturated',
|
||||
ROADMAP = 'roadmap',
|
||||
AUTO = 'auto',
|
||||
DARK = 'dark',
|
||||
}
|
||||
|
||||
export enum JOIN_KEYS {
|
||||
TERM = 'term',
|
||||
}
|
||||
|
||||
export enum LAYER_KEYS {
|
||||
ES_DOCS = 'es_docs',
|
||||
ES_TOP_HITS = 'es_top_hits',
|
||||
ES_TRACKS = 'es_tracks',
|
||||
ES_POINT_TO_POINT = 'es_point_to_point',
|
||||
ES_AGG_CLUSTERS = 'es_agg_clusters',
|
||||
ES_AGG_GRIDS = 'es_agg_grids',
|
||||
ES_AGG_HEXAGONS = 'es_agg_hexagons',
|
||||
ES_AGG_HEATMAP = 'es_agg_heatmap',
|
||||
EMS_REGION = 'ems_region',
|
||||
EMS_BASEMAP = 'ems_basemap',
|
||||
KBN_TMS_RASTER = 'kbn_tms_raster',
|
||||
UX_TMS_RASTER = 'ux_tms_raster', // configured in the UX layer wizard of Maps
|
||||
UX_TMS_MVT = 'ux_tms_mvt', // configured in the UX layer wizard of Maps
|
||||
UX_WMS = 'ux_wms', // configured in the UX layer wizard of Maps
|
||||
}
|
||||
|
||||
export enum RESOLUTION_KEYS {
|
||||
COARSE = 'coarse',
|
||||
FINE = 'fine',
|
||||
MOST_FINE = 'most_fine',
|
||||
SUPER_FINE = 'super_fine',
|
||||
}
|
||||
|
||||
export enum SCALING_KEYS {
|
||||
LIMIT = 'limit',
|
||||
MVT = 'mvt',
|
||||
CLUSTERS = 'clusters',
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { ISavedObjectsRepository } from '@kbn/core/server';
|
||||
// @ts-ignore
|
||||
import mapSavedObjects from './test_resources/sample_map_saved_objects.json';
|
||||
import mapSavedObjects from '../../common/telemetry/test_resources/sample_map_saved_objects.json';
|
||||
import { findMaps } from './find_maps';
|
||||
|
||||
function getMockSavedObjectsClient(perPage: number) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { asyncForEach } from '@kbn/std';
|
||||
// @ts-ignore
|
||||
import mapSavedObjects from '../test_resources/sample_map_saved_objects.json';
|
||||
import mapSavedObjects from '../../../common/telemetry/test_resources/sample_map_saved_objects.json';
|
||||
import { DataViewsService } from '@kbn/data-views-plugin/common';
|
||||
import { IndexPatternStatsCollector } from './index_pattern_stats_collector';
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
// @ts-ignore
|
||||
import mapSavedObjects from '../test_resources/sample_map_saved_objects.json';
|
||||
import mapSavedObjects from '../../../common/telemetry/test_resources/sample_map_saved_objects.json';
|
||||
import { MapStatsCollector } from './map_stats_collector';
|
||||
|
||||
test('returns zeroed telemetry data when there are no saved objects', () => {
|
||||
|
|
|
@ -5,37 +5,17 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
DEFAULT_EMS_DARKMAP_ID,
|
||||
DEFAULT_EMS_ROADMAP_DESATURATED_ID,
|
||||
DEFAULT_EMS_ROADMAP_ID,
|
||||
} from '@kbn/maps-ems-plugin/common';
|
||||
import {
|
||||
GRID_RESOLUTION,
|
||||
LAYER_TYPE,
|
||||
RENDER_AS,
|
||||
SCALING_TYPES,
|
||||
SOURCE_TYPES,
|
||||
} from '../../../common/constants';
|
||||
import {
|
||||
EMSTMSSourceDescriptor,
|
||||
EMSFileSourceDescriptor,
|
||||
ESGeoGridSourceDescriptor,
|
||||
ESSearchSourceDescriptor,
|
||||
LayerDescriptor,
|
||||
VectorLayerDescriptor,
|
||||
} from '../../../common/descriptor_types';
|
||||
import { MapSavedObjectAttributes } from '../../../common/map_saved_object_type';
|
||||
import {
|
||||
ClusterCountStats,
|
||||
EMS_BASEMAP_KEYS,
|
||||
JOIN_KEYS,
|
||||
LAYER_KEYS,
|
||||
MapStats,
|
||||
RESOLUTION_KEYS,
|
||||
SCALING_KEYS,
|
||||
} from './types';
|
||||
} from '../../../common/telemetry/types';
|
||||
import { LayerStatsCollector } from '../../../common/telemetry/layer_stats_collector';
|
||||
|
||||
import { ClusterCountStats, MapStats } from './types';
|
||||
|
||||
/*
|
||||
* Use MapStatsCollector instance to track map saved object stats.
|
||||
|
@ -57,20 +37,13 @@ export class MapStatsCollector {
|
|||
private _sourceCountStats: ClusterCountStats | undefined;
|
||||
|
||||
push(attributes: MapSavedObjectAttributes) {
|
||||
if (!attributes || !attributes.layerListJSON) {
|
||||
return;
|
||||
}
|
||||
const layerStatsCollector = new LayerStatsCollector(attributes);
|
||||
|
||||
let layerList: LayerDescriptor[] = [];
|
||||
try {
|
||||
layerList = JSON.parse(attributes.layerListJSON);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if (!layerStatsCollector) return;
|
||||
|
||||
this._mapCount++;
|
||||
|
||||
const layerCount = layerList.length;
|
||||
const layerCount = layerStatsCollector.getLayerCount();
|
||||
if (this._layerCountStats) {
|
||||
const layerCountTotal = this._layerCountStats.total + layerCount;
|
||||
this._layerCountStats = {
|
||||
|
@ -88,16 +61,7 @@ export class MapStatsCollector {
|
|||
};
|
||||
}
|
||||
|
||||
const sourceIdList = layerList
|
||||
.map((layer: LayerDescriptor) => {
|
||||
return layer.sourceDescriptor && 'id' in layer.sourceDescriptor
|
||||
? layer.sourceDescriptor.id
|
||||
: null;
|
||||
})
|
||||
.filter((id: string | null | undefined) => {
|
||||
return id;
|
||||
});
|
||||
const sourceCount = _.uniq(sourceIdList).length;
|
||||
const sourceCount = layerStatsCollector.getSourceCount();
|
||||
if (this._sourceCountStats) {
|
||||
const sourceCountTotal = this._sourceCountStats.total + sourceCount;
|
||||
this._sourceCountStats = {
|
||||
|
@ -115,31 +79,16 @@ export class MapStatsCollector {
|
|||
};
|
||||
}
|
||||
|
||||
const basemapCounts: { [key in EMS_BASEMAP_KEYS]?: number } = {};
|
||||
const joinCounts: { [key in JOIN_KEYS]?: number } = {};
|
||||
const layerCounts: { [key in LAYER_KEYS]?: number } = {};
|
||||
const resolutionCounts: { [key in RESOLUTION_KEYS]?: number } = {};
|
||||
const scalingCounts: { [key in SCALING_KEYS]?: number } = {};
|
||||
const emsFileCounts: { [key: string]: number } = {};
|
||||
const layerTypeCounts: { [key: string]: number } = {};
|
||||
layerList.forEach((layerDescriptor) => {
|
||||
this._updateCounts(getBasemapKey(layerDescriptor), basemapCounts);
|
||||
this._updateCounts(getJoinKey(layerDescriptor), joinCounts);
|
||||
this._updateCounts(getLayerKey(layerDescriptor), layerCounts);
|
||||
this._updateCounts(getResolutionKey(layerDescriptor), resolutionCounts);
|
||||
this._updateCounts(getScalingKey(layerDescriptor), scalingCounts);
|
||||
this._updateCounts(getEmsFileId(layerDescriptor), emsFileCounts);
|
||||
if (layerDescriptor.type) {
|
||||
this._updateCounts(layerDescriptor.type, layerTypeCounts);
|
||||
}
|
||||
});
|
||||
this._updateClusterStats(this._basemapClusterStats, basemapCounts);
|
||||
this._updateClusterStats(this._joinClusterStats, joinCounts);
|
||||
this._updateClusterStats(this._layerClusterStats, layerCounts);
|
||||
this._updateClusterStats(this._resolutionClusterStats, resolutionCounts);
|
||||
this._updateClusterStats(this._scalingClusterStats, scalingCounts);
|
||||
this._updateClusterStats(this._emsFileClusterStats, emsFileCounts);
|
||||
this._updateClusterStats(this._layerTypeClusterStats, layerTypeCounts);
|
||||
this._updateClusterStats(this._basemapClusterStats, layerStatsCollector.getBasemapCounts());
|
||||
this._updateClusterStats(this._joinClusterStats, layerStatsCollector.getJoinCounts());
|
||||
this._updateClusterStats(this._layerClusterStats, layerStatsCollector.getLayerCounts());
|
||||
this._updateClusterStats(
|
||||
this._resolutionClusterStats,
|
||||
layerStatsCollector.getResolutionCounts()
|
||||
);
|
||||
this._updateClusterStats(this._scalingClusterStats, layerStatsCollector.getScalingCounts());
|
||||
this._updateClusterStats(this._emsFileClusterStats, layerStatsCollector.getEmsFileCounts());
|
||||
this._updateClusterStats(this._layerTypeClusterStats, layerStatsCollector.getLayerTypeCounts());
|
||||
}
|
||||
|
||||
getStats(): MapStats {
|
||||
|
@ -198,16 +147,6 @@ export class MapStatsCollector {
|
|||
}
|
||||
}
|
||||
|
||||
_updateCounts(key: string | null, counts: { [key: string]: number }) {
|
||||
if (key) {
|
||||
if (key in counts) {
|
||||
counts[key] += 1;
|
||||
} else {
|
||||
counts[key] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stats in attributesPerMap do not include 'total' key. Use this method to remove 'total' key from ClusterCountStats
|
||||
_excludeTotalFromKeyedStats(clusterStats: { [key: string]: ClusterCountStats }): {
|
||||
[key: string]: Omit<ClusterCountStats, 'total'>;
|
||||
|
@ -232,168 +171,3 @@ export class MapStatsCollector {
|
|||
return modifiedStats;
|
||||
}
|
||||
}
|
||||
|
||||
function getEmsFileId(layerDescriptor: LayerDescriptor): string | null {
|
||||
return layerDescriptor.sourceDescriptor !== null &&
|
||||
layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_FILE &&
|
||||
'id' in layerDescriptor.sourceDescriptor
|
||||
? (layerDescriptor.sourceDescriptor as EMSFileSourceDescriptor).id
|
||||
: null;
|
||||
}
|
||||
|
||||
function getBasemapKey(layerDescriptor: LayerDescriptor): EMS_BASEMAP_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.EMS_TMS
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as EMSTMSSourceDescriptor;
|
||||
|
||||
if (descriptor.isAutoSelect) {
|
||||
return EMS_BASEMAP_KEYS.AUTO;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_ROADMAP_ID) {
|
||||
return EMS_BASEMAP_KEYS.ROADMAP;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_ROADMAP_DESATURATED_ID) {
|
||||
return EMS_BASEMAP_KEYS.ROADMAP_DESATURATED;
|
||||
}
|
||||
|
||||
if (descriptor.id === DEFAULT_EMS_DARKMAP_ID) {
|
||||
return EMS_BASEMAP_KEYS.DARK;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getJoinKey(layerDescriptor: LayerDescriptor): JOIN_KEYS | null {
|
||||
return layerDescriptor.type === LAYER_TYPE.GEOJSON_VECTOR &&
|
||||
(layerDescriptor as VectorLayerDescriptor)?.joins?.length
|
||||
? JOIN_KEYS.TERM
|
||||
: null;
|
||||
}
|
||||
|
||||
function getLayerKey(layerDescriptor: LayerDescriptor): LAYER_KEYS | null {
|
||||
if (!layerDescriptor.sourceDescriptor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (layerDescriptor.type === LAYER_TYPE.HEATMAP) {
|
||||
return LAYER_KEYS.ES_AGG_HEATMAP;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_FILE) {
|
||||
return LAYER_KEYS.EMS_REGION;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_TMS) {
|
||||
return LAYER_KEYS.EMS_BASEMAP;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.KIBANA_TILEMAP) {
|
||||
return LAYER_KEYS.KBN_TMS_RASTER;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.EMS_XYZ) {
|
||||
return LAYER_KEYS.UX_TMS_RASTER;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.WMS) {
|
||||
return LAYER_KEYS.UX_WMS;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.MVT_SINGLE_LAYER) {
|
||||
return LAYER_KEYS.UX_TMS_MVT;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_GEO_LINE) {
|
||||
return LAYER_KEYS.ES_TRACKS;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_PEW_PEW) {
|
||||
return LAYER_KEYS.ES_POINT_TO_POINT;
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_SEARCH) {
|
||||
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor;
|
||||
|
||||
if (sourceDescriptor.scalingType === SCALING_TYPES.TOP_HITS) {
|
||||
return LAYER_KEYS.ES_TOP_HITS;
|
||||
} else {
|
||||
return LAYER_KEYS.ES_DOCS;
|
||||
}
|
||||
}
|
||||
|
||||
if (layerDescriptor.sourceDescriptor.type === SOURCE_TYPES.ES_GEO_GRID) {
|
||||
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor;
|
||||
if (sourceDescriptor.requestType === RENDER_AS.POINT) {
|
||||
return LAYER_KEYS.ES_AGG_CLUSTERS;
|
||||
} else if (sourceDescriptor.requestType === RENDER_AS.GRID) {
|
||||
return LAYER_KEYS.ES_AGG_GRIDS;
|
||||
} else if (sourceDescriptor.requestType === RENDER_AS.HEX) {
|
||||
return LAYER_KEYS.ES_AGG_HEXAGONS;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getResolutionKey(layerDescriptor: LayerDescriptor): RESOLUTION_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.ES_GEO_GRID ||
|
||||
!(layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor).resolution
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as ESGeoGridSourceDescriptor;
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.COARSE) {
|
||||
return RESOLUTION_KEYS.COARSE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.FINE) {
|
||||
return RESOLUTION_KEYS.FINE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.MOST_FINE) {
|
||||
return RESOLUTION_KEYS.MOST_FINE;
|
||||
}
|
||||
|
||||
if (descriptor.resolution === GRID_RESOLUTION.SUPER_FINE) {
|
||||
return RESOLUTION_KEYS.SUPER_FINE;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getScalingKey(layerDescriptor: LayerDescriptor): SCALING_KEYS | null {
|
||||
if (
|
||||
!layerDescriptor.sourceDescriptor ||
|
||||
layerDescriptor.sourceDescriptor.type !== SOURCE_TYPES.ES_SEARCH ||
|
||||
!(layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor).scalingType
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const descriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor;
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.CLUSTERS) {
|
||||
return SCALING_KEYS.CLUSTERS;
|
||||
}
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.MVT) {
|
||||
return SCALING_KEYS.MVT;
|
||||
}
|
||||
|
||||
if (descriptor.scalingType === SCALING_TYPES.LIMIT) {
|
||||
return SCALING_KEYS.LIMIT;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type {
|
||||
LAYER_KEYS,
|
||||
SCALING_KEYS,
|
||||
JOIN_KEYS,
|
||||
EMS_BASEMAP_KEYS,
|
||||
RESOLUTION_KEYS,
|
||||
} from '../../../common/telemetry/types';
|
||||
|
||||
export interface ClusterCountStats {
|
||||
min: number;
|
||||
max: number;
|
||||
|
@ -12,47 +20,6 @@ export interface ClusterCountStats {
|
|||
avg: number;
|
||||
}
|
||||
|
||||
export enum EMS_BASEMAP_KEYS {
|
||||
ROADMAP_DESATURATED = 'roadmap_desaturated',
|
||||
ROADMAP = 'roadmap',
|
||||
AUTO = 'auto',
|
||||
DARK = 'dark',
|
||||
}
|
||||
|
||||
export enum JOIN_KEYS {
|
||||
TERM = 'term',
|
||||
}
|
||||
|
||||
export enum LAYER_KEYS {
|
||||
ES_DOCS = 'es_docs',
|
||||
ES_TOP_HITS = 'es_top_hits',
|
||||
ES_TRACKS = 'es_tracks',
|
||||
ES_POINT_TO_POINT = 'es_point_to_point',
|
||||
ES_AGG_CLUSTERS = 'es_agg_clusters',
|
||||
ES_AGG_GRIDS = 'es_agg_grids',
|
||||
ES_AGG_HEXAGONS = 'es_agg_hexagons',
|
||||
ES_AGG_HEATMAP = 'es_agg_heatmap',
|
||||
EMS_REGION = 'ems_region',
|
||||
EMS_BASEMAP = 'ems_basemap',
|
||||
KBN_TMS_RASTER = 'kbn_tms_raster',
|
||||
UX_TMS_RASTER = 'ux_tms_raster', // configured in the UX layer wizard of Maps
|
||||
UX_TMS_MVT = 'ux_tms_mvt', // configured in the UX layer wizard of Maps
|
||||
UX_WMS = 'ux_wms', // configured in the UX layer wizard of Maps
|
||||
}
|
||||
|
||||
export enum RESOLUTION_KEYS {
|
||||
COARSE = 'coarse',
|
||||
FINE = 'fine',
|
||||
MOST_FINE = 'most_fine',
|
||||
SUPER_FINE = 'super_fine',
|
||||
}
|
||||
|
||||
export enum SCALING_KEYS {
|
||||
LIMIT = 'limit',
|
||||
MVT = 'mvt',
|
||||
CLUSTERS = 'clusters',
|
||||
}
|
||||
|
||||
export interface MapStats {
|
||||
mapsTotalCount: number;
|
||||
timeCaptured: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue