Skip to content

Commit

Permalink
Address various telemetry issues
Browse files Browse the repository at this point in the history
- saved objects: removing indexing per elastic#43673
- add schema and generate json per elastic#64942
- move definitions over to collectors since saved objects is mostly empty at this point, and schema throws an error when it imports an obj instead of being defined inline
- istanbul ignore saved_objects file since it doesn't have anything meaningful to test but was affecting code coverage
  • Loading branch information
cee-chen committed Jul 6, 2020
1 parent aaa978e commit 76970ef
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@ import {
} from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import { AS_TELEMETRY_NAME, ITelemetrySavedObject } from '../../saved_objects/app_search/telemetry';
interface ITelemetry {
ui_viewed: {
setup_guide: number;
engines_overview: number;
};
ui_error: {
cannot_connect: number;
no_as_account: number;
};
ui_clicked: {
create_first_engine_button: number;
header_launch_button: number;
engine_table_link: number;
};
}

export const AS_TELEMETRY_NAME = 'app_search_telemetry';

/**
* Register the telemetry collector
Expand All @@ -22,10 +38,25 @@ export const registerTelemetryUsageCollector = (
usageCollection: UsageCollectionSetup,
savedObjects: SavedObjectsServiceStart
) => {
const telemetryUsageCollector = usageCollection.makeUsageCollector({
const telemetryUsageCollector = usageCollection.makeUsageCollector<ITelemetry>({
type: 'app_search',
fetch: async () => fetchTelemetryMetrics(savedObjects),
isReady: () => true,
schema: {
ui_viewed: {
setup_guide: { type: 'long' },
engines_overview: { type: 'long' },
},
ui_error: {
cannot_connect: { type: 'long' },
no_as_account: { type: 'long' },
},
ui_clicked: {
create_first_engine_button: { type: 'long' },
header_launch_button: { type: 'long' },
engine_table_link: { type: 'long' },
},
},
});
usageCollection.registerCollector(telemetryUsageCollector);
};
Expand All @@ -40,7 +71,7 @@ const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart) =>
savedObjectsRepository
)) as SavedObjectAttributes;

const defaultTelemetrySavedObject: ITelemetrySavedObject = {
const defaultTelemetrySavedObject: ITelemetry = {
ui_viewed: {
setup_guide: 0,
engines_overview: 0,
Expand Down Expand Up @@ -68,7 +99,7 @@ const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart) =>
set(telemetryObj, key, savedObjectAttributes[key]);
});

return telemetryObj as ITelemetrySavedObject;
return telemetryObj as ITelemetry;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,17 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
/* istanbul ignore file */

import { SavedObjectsType } from 'src/core/server';

export const AS_TELEMETRY_NAME = 'app_search_telemetry';

export interface ITelemetrySavedObject {
ui_viewed: {
setup_guide: number;
engines_overview: number;
};
ui_error: {
cannot_connect: number;
no_as_account: number;
};
ui_clicked: {
create_first_engine_button: number;
header_launch_button: number;
engine_table_link: number;
};
}
import { AS_TELEMETRY_NAME } from '../../collectors/app_search/telemetry';

export const appSearchTelemetryType: SavedObjectsType = {
name: AS_TELEMETRY_NAME,
hidden: false,
namespaceType: 'single',
mappings: {
properties: {
ui_viewed: {
properties: {
setup_guide: {
type: 'long',
null_value: 0,
},
engines_overview: {
type: 'long',
null_value: 0,
},
},
},
ui_error: {
properties: {
cannot_connect: {
type: 'long',
null_value: 0,
},
no_as_account: {
type: 'long',
null_value: 0,
},
},
},
ui_clicked: {
properties: {
create_first_engine_button: {
type: 'long',
null_value: 0,
},
header_launch_button: {
type: 'long',
null_value: 0,
},
engine_table_link: {
type: 'long',
null_value: 0,
},
},
},
},
dynamic: false,
properties: {},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,43 @@
}
}
},
"app_search": {
"properties": {
"ui_viewed": {
"properties": {
"setup_guide": {
"type": "long"
},
"engines_overview": {
"type": "long"
}
}
},
"ui_error": {
"properties": {
"cannot_connect": {
"type": "long"
},
"no_as_account": {
"type": "long"
}
}
},
"ui_clicked": {
"properties": {
"create_first_engine_button": {
"type": "long"
},
"header_launch_button": {
"type": "long"
},
"engine_table_link": {
"type": "long"
}
}
}
}
},
"fileUploadTelemetry": {
"properties": {
"filesUploadedTotalCount": {
Expand Down

0 comments on commit 76970ef

Please sign in to comment.