-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Management advanced settings telemetry (#54369)
* management telemetry * Use getUserProvided
- Loading branch information
Liza Katz
authored
Jan 13, 2020
1 parent
2d62ff2
commit ebd2c21
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/legacy/core_plugins/telemetry/server/collectors/management/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
63 changes: 63 additions & 0 deletions
63
...acy/core_plugins/telemetry/server/collectors/management/telemetry_management_collector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters