-
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.
[lens] Basic usage telemetry for total visualizations, and by type
- Loading branch information
1 parent
b9bbde6
commit 93b7af4
Showing
6 changed files
with
124 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; | ||
import { CoreSetup, SavedObjectsLegacyService } from 'src/core/server'; | ||
import { getVisualizationCounts } from './visualization_counts'; | ||
|
||
export function getSavedObjectsClient( | ||
savedObjects: SavedObjectsLegacyService, | ||
callAsInternalUser: unknown | ||
) { | ||
const { SavedObjectsClient, getSavedObjectsRepository } = savedObjects; | ||
const internalRepository = getSavedObjectsRepository(callAsInternalUser); | ||
return new SavedObjectsClient(internalRepository); | ||
} | ||
|
||
export function registerLensUsageCollector( | ||
core: CoreSetup, | ||
plugins: { | ||
savedObjects: SavedObjectsLegacyService; | ||
usage: { | ||
collectorSet: { | ||
makeUsageCollector: (options: unknown) => unknown; | ||
register: (options: unknown) => unknown; | ||
}; | ||
}; | ||
} | ||
) { | ||
const lensUsageCollector = plugins.usage.collectorSet.makeUsageCollector({ | ||
type: 'lens', | ||
fetch: async (callCluster: CallCluster) => { | ||
const savedObjectsClient = getSavedObjectsClient(plugins.savedObjects, callCluster); | ||
try { | ||
return getVisualizationCounts(savedObjectsClient); | ||
} catch (err) { | ||
return { | ||
lens: { | ||
total: 0, | ||
visualization_types: {}, | ||
}, | ||
}; | ||
} | ||
}, | ||
isReady: () => true, | ||
}); | ||
plugins.usage.collectorSet.register(lensUsageCollector); | ||
} |
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './collectors'; |
35 changes: 35 additions & 0 deletions
35
x-pack/legacy/plugins/lens/server/usage/visualization_counts.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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SavedObjectsClient } from 'src/core/server'; | ||
|
||
export async function getVisualizationCounts(savedObjectsClient: SavedObjectsClient) { | ||
const lensSavedObjects = await savedObjectsClient.find({ | ||
type: 'lens', | ||
}); | ||
|
||
const byType: Record<string, number> = {}; | ||
|
||
lensSavedObjects.saved_objects.forEach(({ attributes }) => { | ||
let type; | ||
if (attributes.visualizationType === 'lnsXY') { | ||
type = attributes.state.visualization.preferredSeriesType; | ||
} else { | ||
type = attributes.visualizationType; | ||
} | ||
|
||
if (byType[type]) { | ||
byType[type] += 1; | ||
} else { | ||
byType[type] = 1; | ||
} | ||
}); | ||
|
||
return { | ||
total: lensSavedObjects.total, | ||
visualization_types: byType, | ||
}; | ||
} |