mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Usage Collection] [schema] maps
(#78952)
This commit is contained in:
parent
21353403b8
commit
bad59f4fb4
5 changed files with 180 additions and 33 deletions
|
@ -4,7 +4,6 @@
|
|||
"exclude": [
|
||||
"plugins/actions/server/usage/actions_usage_collector.ts",
|
||||
"plugins/alerts/server/usage/alerts_usage_collector.ts",
|
||||
"plugins/apm/server/lib/apm_telemetry/index.ts",
|
||||
"plugins/maps/server/maps_telemetry/collectors/register.ts"
|
||||
"plugins/apm/server/lib/apm_telemetry/index.ts"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
|
||||
import { getMapsTelemetry } from '../maps_telemetry';
|
||||
import { getMapsTelemetry, MapsUsage } from '../maps_telemetry';
|
||||
import { MapsConfigType } from '../../../config';
|
||||
|
||||
export function registerMapsUsageCollector(
|
||||
|
@ -16,10 +16,40 @@ export function registerMapsUsageCollector(
|
|||
return;
|
||||
}
|
||||
|
||||
const mapsUsageCollector = usageCollection.makeUsageCollector({
|
||||
const mapsUsageCollector = usageCollection.makeUsageCollector<MapsUsage>({
|
||||
type: 'maps',
|
||||
isReady: () => true,
|
||||
fetch: async () => await getMapsTelemetry(config),
|
||||
schema: {
|
||||
settings: {
|
||||
showMapVisualizationTypes: { type: 'boolean' },
|
||||
},
|
||||
indexPatternsWithGeoFieldCount: { type: 'long' },
|
||||
indexPatternsWithGeoPointFieldCount: { type: 'long' },
|
||||
indexPatternsWithGeoShapeFieldCount: { type: 'long' },
|
||||
geoShapeAggLayersCount: { type: 'long' },
|
||||
mapsTotalCount: { type: 'long' },
|
||||
timeCaptured: { type: 'date' },
|
||||
attributesPerMap: {
|
||||
dataSourcesCount: {
|
||||
min: { type: 'long' },
|
||||
max: { type: 'long' },
|
||||
avg: { type: 'float' },
|
||||
},
|
||||
layersCount: {
|
||||
min: { type: 'long' },
|
||||
max: { type: 'long' },
|
||||
avg: { type: 'float' },
|
||||
},
|
||||
// TODO: Find out all the possible values for DYNAMIC_KEY or reformat into an array
|
||||
layerTypesCount: {
|
||||
DYNAMIC_KEY: { min: { type: 'long' }, max: { type: 'long' }, avg: { type: 'float' } },
|
||||
},
|
||||
emsVectorLayersCount: {
|
||||
DYNAMIC_KEY: { min: { type: 'long' }, max: { type: 'long' }, avg: { type: 'float' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
usageCollection.registerCollector(mapsUsageCollector);
|
||||
|
|
|
@ -33,6 +33,7 @@ describe('buildCollectorObj#fetch', () => {
|
|||
type: expect.any(String),
|
||||
isReady: expect.any(Function),
|
||||
fetch: expect.any(Function),
|
||||
schema: expect.any(Object),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,12 +5,7 @@
|
|||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
SavedObject,
|
||||
SavedObjectAttribute,
|
||||
SavedObjectAttributes,
|
||||
SavedObjectsClientContract,
|
||||
} from 'kibana/server';
|
||||
import { ISavedObjectsRepository, SavedObject, SavedObjectsClientContract } from 'kibana/server';
|
||||
import { IFieldType, IndexPatternAttributes } from 'src/plugins/data/public';
|
||||
import {
|
||||
ES_GEO_FIELD_TYPE,
|
||||
|
@ -25,11 +20,14 @@ import {
|
|||
ESSearchSourceDescriptor,
|
||||
LayerDescriptor,
|
||||
} from '../../common/descriptor_types';
|
||||
import { MapSavedObject } from '../../common/map_saved_object_type';
|
||||
// @ts-ignore
|
||||
import { MapSavedObject, MapSavedObjectAttributes } from '../../common/map_saved_object_type';
|
||||
import { getInternalRepository } from '../kibana_server_services';
|
||||
import { MapsConfigType } from '../../config';
|
||||
|
||||
interface Settings {
|
||||
showMapVisualizationTypes: boolean;
|
||||
}
|
||||
|
||||
interface IStats {
|
||||
[key: string]: {
|
||||
min: number;
|
||||
|
@ -42,6 +40,30 @@ interface ILayerTypeCount {
|
|||
[key: string]: number;
|
||||
}
|
||||
|
||||
export interface MapsUsage {
|
||||
settings: Settings;
|
||||
indexPatternsWithGeoFieldCount: number;
|
||||
indexPatternsWithGeoPointFieldCount: number;
|
||||
indexPatternsWithGeoShapeFieldCount: number;
|
||||
geoShapeAggLayersCount: number;
|
||||
mapsTotalCount: number;
|
||||
timeCaptured: string;
|
||||
attributesPerMap: {
|
||||
dataSourcesCount: {
|
||||
min: number;
|
||||
max: number;
|
||||
avg: number;
|
||||
};
|
||||
layersCount: {
|
||||
min: number;
|
||||
max: number;
|
||||
avg: number;
|
||||
};
|
||||
layerTypesCount: IStats;
|
||||
emsVectorLayersCount: IStats;
|
||||
};
|
||||
}
|
||||
|
||||
function getUniqueLayerCounts(layerCountsList: ILayerTypeCount[], mapsCount: number) {
|
||||
const uniqueLayerTypes = _.uniq(_.flatten(layerCountsList.map((lTypes) => Object.keys(lTypes))));
|
||||
|
||||
|
@ -213,8 +235,8 @@ export function buildMapsTelemetry({
|
|||
}: {
|
||||
mapSavedObjects: MapSavedObject[];
|
||||
indexPatternSavedObjects: Array<SavedObject<IndexPatternAttributes>>;
|
||||
settings: SavedObjectAttribute;
|
||||
}): SavedObjectAttributes {
|
||||
settings: Settings;
|
||||
}): MapsUsage {
|
||||
const layerLists: LayerDescriptor[][] = getLayerLists(mapSavedObjects);
|
||||
const mapsCount = layerLists.length;
|
||||
|
||||
|
@ -256,14 +278,14 @@ export function buildMapsTelemetry({
|
|||
attributesPerMap: {
|
||||
// Count of data sources per map
|
||||
dataSourcesCount: {
|
||||
min: dataSourcesCount.length ? _.min(dataSourcesCount) : 0,
|
||||
max: dataSourcesCount.length ? _.max(dataSourcesCount) : 0,
|
||||
min: dataSourcesCount.length ? _.min(dataSourcesCount)! : 0,
|
||||
max: dataSourcesCount.length ? _.max(dataSourcesCount)! : 0,
|
||||
avg: dataSourcesCountSum ? layersCountSum / mapsCount : 0,
|
||||
},
|
||||
// Total count of layers per map
|
||||
layersCount: {
|
||||
min: layersCount.length ? _.min(layersCount) : 0,
|
||||
max: layersCount.length ? _.max(layersCount) : 0,
|
||||
min: layersCount.length ? _.min(layersCount)! : 0,
|
||||
max: layersCount.length ? _.max(layersCount)! : 0,
|
||||
avg: layersCountSum ? layersCountSum / mapsCount : 0,
|
||||
},
|
||||
// Count of layers by type
|
||||
|
@ -277,27 +299,29 @@ export function buildMapsTelemetry({
|
|||
},
|
||||
};
|
||||
}
|
||||
async function getMapSavedObjects(savedObjectsClient: SavedObjectsClientContract) {
|
||||
const mapsSavedObjects = await savedObjectsClient.find({ type: MAP_SAVED_OBJECT_TYPE });
|
||||
return _.get(mapsSavedObjects, 'saved_objects', []);
|
||||
async function getMapSavedObjects(
|
||||
savedObjectsClient: SavedObjectsClientContract | ISavedObjectsRepository
|
||||
) {
|
||||
const mapsSavedObjects = await savedObjectsClient.find<MapSavedObjectAttributes>({
|
||||
type: MAP_SAVED_OBJECT_TYPE,
|
||||
});
|
||||
return mapsSavedObjects.saved_objects;
|
||||
}
|
||||
|
||||
async function getIndexPatternSavedObjects(savedObjectsClient: SavedObjectsClientContract) {
|
||||
const indexPatternSavedObjects = await savedObjectsClient.find({ type: 'index-pattern' });
|
||||
return _.get(indexPatternSavedObjects, 'saved_objects', []);
|
||||
async function getIndexPatternSavedObjects(
|
||||
savedObjectsClient: SavedObjectsClientContract | ISavedObjectsRepository
|
||||
) {
|
||||
const indexPatternSavedObjects = await savedObjectsClient.find<IndexPatternAttributes>({
|
||||
type: 'index-pattern',
|
||||
});
|
||||
return indexPatternSavedObjects.saved_objects;
|
||||
}
|
||||
|
||||
export async function getMapsTelemetry(config: MapsConfigType) {
|
||||
const savedObjectsClient = getInternalRepository();
|
||||
// @ts-ignore
|
||||
const mapSavedObjects: MapSavedObject[] = await getMapSavedObjects(savedObjectsClient);
|
||||
const indexPatternSavedObjects: Array<SavedObject<
|
||||
IndexPatternAttributes
|
||||
>> = (await getIndexPatternSavedObjects(
|
||||
// @ts-ignore
|
||||
savedObjectsClient
|
||||
)) as Array<SavedObject<IndexPatternAttributes>>;
|
||||
const settings: SavedObjectAttribute = {
|
||||
const mapSavedObjects = await getMapSavedObjects(savedObjectsClient);
|
||||
const indexPatternSavedObjects = await getIndexPatternSavedObjects(savedObjectsClient);
|
||||
const settings = {
|
||||
showMapVisualizationTypes: config.showMapVisualizationTypes,
|
||||
};
|
||||
return buildMapsTelemetry({ mapSavedObjects, indexPatternSavedObjects, settings });
|
||||
|
|
|
@ -679,6 +679,99 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"maps": {
|
||||
"properties": {
|
||||
"settings": {
|
||||
"properties": {
|
||||
"showMapVisualizationTypes": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"indexPatternsWithGeoFieldCount": {
|
||||
"type": "long"
|
||||
},
|
||||
"indexPatternsWithGeoPointFieldCount": {
|
||||
"type": "long"
|
||||
},
|
||||
"indexPatternsWithGeoShapeFieldCount": {
|
||||
"type": "long"
|
||||
},
|
||||
"geoShapeAggLayersCount": {
|
||||
"type": "long"
|
||||
},
|
||||
"mapsTotalCount": {
|
||||
"type": "long"
|
||||
},
|
||||
"timeCaptured": {
|
||||
"type": "date"
|
||||
},
|
||||
"attributesPerMap": {
|
||||
"properties": {
|
||||
"dataSourcesCount": {
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "long"
|
||||
},
|
||||
"max": {
|
||||
"type": "long"
|
||||
},
|
||||
"avg": {
|
||||
"type": "float"
|
||||
}
|
||||
}
|
||||
},
|
||||
"layersCount": {
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "long"
|
||||
},
|
||||
"max": {
|
||||
"type": "long"
|
||||
},
|
||||
"avg": {
|
||||
"type": "float"
|
||||
}
|
||||
}
|
||||
},
|
||||
"layerTypesCount": {
|
||||
"properties": {
|
||||
"DYNAMIC_KEY": {
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "long"
|
||||
},
|
||||
"max": {
|
||||
"type": "long"
|
||||
},
|
||||
"avg": {
|
||||
"type": "float"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"emsVectorLayersCount": {
|
||||
"properties": {
|
||||
"DYNAMIC_KEY": {
|
||||
"properties": {
|
||||
"min": {
|
||||
"type": "long"
|
||||
},
|
||||
"max": {
|
||||
"type": "long"
|
||||
},
|
||||
"avg": {
|
||||
"type": "float"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mlTelemetry": {
|
||||
"properties": {
|
||||
"file_data_visualizer": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue