Skip to content

Commit

Permalink
Retain saved object fields layerTypesCount and emsVectorLayersCount b…
Browse files Browse the repository at this point in the history
…ut set as type object
  • Loading branch information
Aaron Caldwell committed Jun 25, 2020
1 parent e2fbf08 commit f798091
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
31 changes: 31 additions & 0 deletions x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ describe('buildMapsTelemetry', () => {
max: 0,
min: 0,
},
emsVectorLayersCount: {},
layerTypesCount: {},
layersCount: {
avg: 0,
max: 0,
Expand All @@ -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,
Expand Down
58 changes: 57 additions & 1 deletion x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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),
},
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/server/saved_objects/maps_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const mapsTelemetrySavedObjects: SavedObjectsType = {
avg: { type: 'long' },
},
},
layerTypesCount: { type: 'object' },
emsVectorLayersCount: { type: 'object' },
},
},
},
Expand Down

0 comments on commit f798091

Please sign in to comment.