66 * Side Public License, v 1.
77 */
88
9- // import { parse } from 'hjson';
9+ import { parse } from 'hjson' ;
1010
1111import type {
1212 SavedObjectsClientContract ,
@@ -16,7 +16,7 @@ import type { SavedVisState } from '../../../../visualizations/common';
1616import type { VegaSavedObjectAttributes , VisTypeVegaPluginSetupDependencies } from '../types' ;
1717
1818type UsageCollectorDependencies = Pick < VisTypeVegaPluginSetupDependencies , 'home' > ;
19- // type VegaType = 'vega' | 'vega-lite';
19+ type VegaType = 'vega' | 'vega-lite' ;
2020
2121export interface VegaUsage {
2222 vega_lib_specs_total : number ;
@@ -28,8 +28,8 @@ function isVegaType(attributes: any): attributes is VegaSavedObjectAttributes {
2828 return attributes && attributes . type === 'vega' && attributes . params ?. spec ;
2929}
3030
31- // const checkVegaSchemaType = (schemaURL: string, type: VegaType) =>
32- // schemaURL.includes(`//vega.github.io/schema/${type}/`);
31+ const checkVegaSchemaType = ( schemaURL : string , type : VegaType ) =>
32+ schemaURL . includes ( `//vega.github.io/schema/${ type } /` ) ;
3333
3434const getDefaultVegaVisualizations = ( home : UsageCollectorDependencies [ 'home' ] ) => {
3535 const titles : string [ ] = [ ] ;
@@ -58,7 +58,7 @@ export const getStats = async (
5858 soClient : SavedObjectsClientContract ,
5959 { home } : UsageCollectorDependencies
6060) : Promise < VegaUsage | undefined > => {
61- const shouldPublishTelemetry = false ;
61+ let shouldPublishTelemetry = false ;
6262
6363 const vegaUsage = {
6464 vega_lib_specs_total : 0 ,
@@ -76,27 +76,27 @@ export const getStats = async (
7676 namespaces : [ '*' ] ,
7777 } ) ;
7878
79- // const doTelemetry = ({ params }: SavedVisState) => {
80- // try {
81- // const spec = parse(params.spec, { legacyRoot: false });
82-
83- // if (spec) {
84- // shouldPublishTelemetry = true;
85-
86- // if (checkVegaSchemaType(spec.$schema, 'vega')) {
87- // vegaUsage.vega_lib_specs_total++;
88- // }
89- // if (checkVegaSchemaType(spec.$schema, 'vega-lite')) {
90- // vegaUsage.vega_lite_lib_specs_total++;
91- // }
92- // if (spec.config?.kibana?.type === 'map') {
93- // vegaUsage.vega_use_map_total++;
94- // }
95- // }
96- // } catch (e) {
97- // // Let it go, the data is invalid and we'll don't need to handle it
98- // }
99- // };
79+ const doTelemetry = ( { params } : SavedVisState ) => {
80+ try {
81+ const spec = parse ( params . spec , { legacyRoot : false } ) ;
82+
83+ if ( spec ) {
84+ shouldPublishTelemetry = true ;
85+
86+ if ( checkVegaSchemaType ( spec . $schema , 'vega' ) ) {
87+ vegaUsage . vega_lib_specs_total ++ ;
88+ }
89+ if ( checkVegaSchemaType ( spec . $schema , 'vega-lite' ) ) {
90+ vegaUsage . vega_lite_lib_specs_total ++ ;
91+ }
92+ if ( spec . config ?. kibana ?. type === 'map' ) {
93+ vegaUsage . vega_use_map_total ++ ;
94+ }
95+ }
96+ } catch ( e ) {
97+ // Let it go, the data is invalid and we'll don't need to handle it
98+ }
99+ } ;
100100
101101 for await ( const response of finder . find ( ) ) {
102102 ( response . saved_objects || [ ] ) . forEach ( ( { attributes } : SavedObjectsFindResult < any > ) => {
@@ -105,7 +105,7 @@ export const getStats = async (
105105 const visState : SavedVisState = JSON . parse ( attributes . visState ) ;
106106
107107 if ( isVegaType ( visState ) && ! excludedFromStatsVisualizations . includes ( visState . title ) ) {
108- // doTelemetry(visState);
108+ doTelemetry ( visState ) ;
109109 }
110110 } catch {
111111 // nothing to be here, "so" not valid
0 commit comments