Skip to content

Commit

Permalink
Telemetry for preconfigured alert history config enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Apr 13, 2021
1 parent dc652f5 commit e6965bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
if (usageCollection) {
registerActionsUsageCollector(
usageCollection,
this.actionsConfig,
core.getStartServices().then(([_, { taskManager }]) => taskManager)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MakeSchemaFrom, UsageCollectionSetup } from 'src/plugins/usage_collecti
import { get } from 'lodash';
import { TaskManagerStartContract } from '../../../task_manager/server';
import { ActionsUsage } from './types';
import { ActionsConfig } from '../config';

const byTypeSchema: MakeSchemaFrom<ActionsUsage>['count_by_type'] = {
// TODO: Find out an automated way to populate the keys or reformat these into an array (and change the Remote Telemetry indexer accordingly)
Expand All @@ -28,6 +29,7 @@ const byTypeSchema: MakeSchemaFrom<ActionsUsage>['count_by_type'] = {

export function createActionsUsageCollector(
usageCollection: UsageCollectionSetup,
config: ActionsConfig,
taskManager: Promise<TaskManagerStartContract>
) {
return usageCollection.makeUsageCollector<ActionsUsage>({
Expand All @@ -37,6 +39,7 @@ export function createActionsUsageCollector(
return true;
},
schema: {
alert_history_connector_enabled: { type: 'boolean' },
count_total: { type: 'long' },
count_active_total: { type: 'long' },
count_active_alert_history_connectors: { type: 'long' },
Expand All @@ -51,9 +54,11 @@ export function createActionsUsageCollector(

return {
...state,
alert_history_connector_enabled: config.preconfiguredAlertHistoryEsIndex,
};
} catch (err) {
return {
alert_history_connector_enabled: false,
count_total: 0,
count_active_total: 0,
count_active_alert_history_connectors: 0,
Expand Down Expand Up @@ -86,8 +91,9 @@ async function getLatestTaskState(taskManager: TaskManagerStartContract) {

export function registerActionsUsageCollector(
usageCollection: UsageCollectionSetup,
config: ActionsConfig,
taskManager: Promise<TaskManagerStartContract>
) {
const collector = createActionsUsageCollector(usageCollection, taskManager);
const collector = createActionsUsageCollector(usageCollection, config, taskManager);
usageCollection.registerCollector(collector);
}
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/usage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

export interface ActionsUsage {
alert_history_connector_enabled: boolean;
count_total: number;
count_active_total: number;
count_active_alert_history_connectors: number;
Expand Down

0 comments on commit e6965bb

Please sign in to comment.