Skip to content

Commit

Permalink
Management advanced settings telemetry (elastic#54369)
Browse files Browse the repository at this point in the history
* management telemetry

* Use getUserProvided
  • Loading branch information
Liza Katz authored and jkelastic committed Jan 17, 2020
1 parent 34609ff commit 32513ce
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/legacy/core_plugins/telemetry/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ export const UI_METRIC_USAGE_TYPE = 'ui_metric';
* Link to Advanced Settings.
*/
export const PATH_TO_ADVANCED_SETTINGS = 'kibana#/management/kibana/settings';

/**
* The type name used within the Monitoring index to publish management stats.
* @type {string}
*/
export const KIBANA_MANAGEMENT_STATS_TYPE = 'management';
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export { registerTelemetryUsageCollector } from './usage';
export { registerUiMetricUsageCollector } from './ui_metric';
export { registerLocalizationUsageCollector } from './localization';
export { registerTelemetryPluginUsageCollector } from './telemetry_plugin';
export { registerManagementUsageCollector } from './management';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { registerManagementUsageCollector } from './telemetry_management_collector';
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Server } from 'hapi';
import { size } from 'lodash';
import { KIBANA_MANAGEMENT_STATS_TYPE } from '../../../common/constants';
import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server';
import { SavedObjectsClient } from '../../../../../../core/server';

export type UsageStats = Record<string, any>;

export async function getTranslationCount(loader: any, locale: string): Promise<number> {
const translations = await loader.getTranslationsByLocale(locale);
return size(translations.messages);
}

export function createCollectorFetch(server: Server) {
return async function fetchUsageStats(): Promise<UsageStats> {
const internalRepo = server.newPlatform.setup.core.savedObjects.createInternalRepository();
const uiSettingsClient = server.newPlatform.start.core.uiSettings.asScopedToClient(
new SavedObjectsClient(internalRepo)
);

const user = await uiSettingsClient.getUserProvided();
const modifiedEntries = Object.keys(user)
.filter((key: string) => key !== 'buildNum')
.reduce((obj: any, key: string) => {
obj[key] = user[key].userValue;
return obj;
}, {});

return modifiedEntries;
};
}

export function registerManagementUsageCollector(
usageCollection: UsageCollectionSetup,
server: any
) {
const collector = usageCollection.makeUsageCollector({
type: KIBANA_MANAGEMENT_STATS_TYPE,
isReady: () => true,
fetch: createCollectorFetch(server),
});

usageCollection.registerCollector(collector);
}
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/telemetry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
registerTelemetryUsageCollector,
registerLocalizationUsageCollector,
registerTelemetryPluginUsageCollector,
registerManagementUsageCollector,
} from './collectors';

export interface PluginsSetup {
Expand All @@ -50,5 +51,6 @@ export class TelemetryPlugin {
registerLocalizationUsageCollector(usageCollection, server);
registerTelemetryUsageCollector(usageCollection, server);
registerUiMetricUsageCollector(usageCollection, server);
registerManagementUsageCollector(usageCollection, server);
}
}

0 comments on commit 32513ce

Please sign in to comment.