-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Maps] Enh/gis telemetry #29346
Merged
Merged
[Maps] Enh/gis telemetry #29346
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
4e3c22c
Add basic framework for maps telemetry gathering
kindsun 3330518
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun 1e67ebc
Update mappings to cover required maps usage metrics
kindsun 06a122a
Update telemetry to harvest from saved maps
kindsun aef2b52
Consolidate. Clean up
kindsun baaf22d
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun 475580b
Harvest telemetry daily at midnight using task manager. Retrieve task…
kindsun bb4e105
Organize, clean up
kindsun 6d0f932
Reorg
kindsun 7579bcd
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun b0e2152
Add usage collector tests. Add test utils
kindsun 9c01a21
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun 929907e
Add maps telemetry tests to verify values. Multiple structure changes…
kindsun f6c63d1
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun e15e00e
Review feedback
kindsun cf97d4a
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun 0859ca4
More review feedback
kindsun fdd66bf
Add capture date/time to telemetry
kindsun d9ab073
Change date to 'type: date'
kindsun 9a8fc37
Review feedback
kindsun 20742b8
Merge remote-tracking branch 'upstream/master' into enh/gisTelemetry
kindsun 7a1aab4
Fix merge issue
kindsun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 { initTelemetryCollection } from './maps_usage_collector'; |
108 changes: 108 additions & 0 deletions
108
x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.js
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,108 @@ | ||
/* | ||
* 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 _ from 'lodash'; | ||
import { EMS_FILE } from '../../common/constants'; | ||
|
||
function getSavedObjectsClient(server, callCluster) { | ||
const { SavedObjectsClient, getSavedObjectsRepository } = server.savedObjects; | ||
const internalRepository = getSavedObjectsRepository(callCluster); | ||
return new SavedObjectsClient(internalRepository); | ||
} | ||
|
||
function getUniqueLayerCounts(layerCountsList, mapsCount) { | ||
const uniqueLayerTypes = _.uniq(_.flatten( | ||
layerCountsList.map(lTypes => Object.keys(lTypes)))); | ||
|
||
return uniqueLayerTypes.reduce((accu, type) => { | ||
const typeCounts = layerCountsList.reduce((accu, tCounts) => { | ||
tCounts[type] && accu.push(tCounts[type]); | ||
return accu; | ||
}, []); | ||
const typeCountsSum = _.sum(typeCounts); | ||
accu[type] = { | ||
min: typeCounts.length ? _.min(typeCounts) : 0, | ||
max: typeCounts.length ? _.max(typeCounts) : 0, | ||
avg: typeCountsSum ? typeCountsSum / mapsCount : 0 | ||
}; | ||
return accu; | ||
}, {}); | ||
} | ||
|
||
export function buildMapsTelemetry(savedObjects) { | ||
const layerLists = savedObjects | ||
.map(savedMapObject => | ||
JSON.parse(savedMapObject.attributes.layerListJSON)); | ||
const mapsCount = layerLists.length; | ||
|
||
const dataSourcesCount = layerLists.map(lList => { | ||
const sourceIdList = lList.map(layer => layer.sourceDescriptor.id); | ||
return _.uniq(sourceIdList).length; | ||
}); | ||
|
||
const layersCount = layerLists.map(lList => lList.length); | ||
const layerTypesCount = layerLists.map(lList => _.countBy(lList, 'type')); | ||
|
||
// Count of EMS Vector layers used | ||
const emsLayersCount = layerLists.map(lList => _(lList) | ||
.countBy(layer => { | ||
const isEmsFile = _.get(layer, 'sourceDescriptor.type') === EMS_FILE; | ||
return isEmsFile && _.get(layer, 'sourceDescriptor.id'); | ||
}) | ||
.pick((val, key) => key !== 'false') | ||
.value()); | ||
|
||
const dataSourcesCountSum = _.sum(dataSourcesCount); | ||
const layersCountSum = _.sum(layersCount); | ||
const mapsTelem = { | ||
// Total count of maps | ||
mapsTotalCount: mapsCount, | ||
// Time of capture | ||
timeCaptured: new Date(), | ||
attributesPerMap: { | ||
// Count of data sources per map | ||
dataSourcesCount: { | ||
min: dataSourcesCount.length ? _.min(dataSourcesCount) : 0, | ||
max: dataSourcesCount.length ? _.max(dataSourcesCount) : 0, | ||
avg: dataSourcesCountSum ? layersCountSum / mapsCount : 0 | ||
}, | ||
// Total count of layers per map | ||
layersCount: { | ||
min: layersCount.length ? _.min(layersCount) : 0, | ||
max: layersCount.length ? _.max(layersCount) : 0, | ||
avg: layersCountSum ? layersCountSum / mapsCount : 0 | ||
}, | ||
// Count of layers by type | ||
layerTypesCount: { | ||
...getUniqueLayerCounts(layerTypesCount, mapsCount) | ||
}, | ||
// Count of layer by EMS region | ||
emsVectorLayersCount: { | ||
...getUniqueLayerCounts(emsLayersCount, mapsCount) | ||
} | ||
} | ||
}; | ||
return mapsTelem; | ||
} | ||
|
||
async function getSavedObjects(savedObjectsClient) { | ||
const gisMapsSavedObject = await savedObjectsClient.find({ | ||
type: 'map' | ||
}); | ||
return _.get(gisMapsSavedObject, 'saved_objects'); | ||
} | ||
|
||
export async function getMapsTelemetry(server, callCluster) { | ||
const savedObjectsClient = getSavedObjectsClient(server, callCluster); | ||
const savedObjects = await getSavedObjects(savedObjectsClient); | ||
const mapsTelemetry = buildMapsTelemetry(savedObjects); | ||
|
||
return await savedObjectsClient.create('maps-telemetry', | ||
mapsTelemetry, { | ||
id: 'maps-telemetry', | ||
overwrite: true, | ||
}); | ||
} |
88 changes: 88 additions & 0 deletions
88
x-pack/plugins/maps/server/maps_telemetry/maps_telemetry.test.js
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,88 @@ | ||
/* | ||
* 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 * as savedObjectsPayload from | ||
'./test_resources/sample_saved_objects.json'; | ||
import { buildMapsTelemetry } from './maps_telemetry'; | ||
|
||
describe('buildMapsTelemetry', () => { | ||
|
||
test('returns zeroed telemetry data when there are no saved objects', | ||
async () => { | ||
|
||
const gisMaps = []; | ||
const result = buildMapsTelemetry(gisMaps); | ||
|
||
expect(result).toMatchObject({ | ||
"attributesPerMap": { | ||
"dataSourcesCount": { | ||
"avg": 0, | ||
"max": 0, | ||
"min": 0 | ||
}, | ||
"emsVectorLayersCount": {}, | ||
"layerTypesCount": {}, | ||
"layersCount": { | ||
"avg": 0, | ||
"max": 0, | ||
"min": 0 | ||
} | ||
}, | ||
"mapsTotalCount": 0 | ||
}); | ||
}); | ||
|
||
test('returns expected telemetry data from saved objects', async () => { | ||
|
||
const gisMaps = savedObjectsPayload.saved_objects; | ||
const result = buildMapsTelemetry(gisMaps); | ||
|
||
expect(result).toMatchObject({ | ||
"attributesPerMap": { | ||
"dataSourcesCount": { | ||
"avg": 2.6666666666666665, | ||
"max": 3, | ||
"min": 2 | ||
}, | ||
"emsVectorLayersCount": { | ||
"canada_provinces": { | ||
"avg": 0.3333333333333333, | ||
"max": 1, | ||
"min": 1 | ||
}, | ||
"france_departments": { | ||
"avg": 0.3333333333333333, | ||
"max": 1, | ||
"min": 1 | ||
}, | ||
"italy_provinces": { | ||
"avg": 0.3333333333333333, | ||
"max": 1, | ||
"min": 1 | ||
} | ||
}, | ||
"layerTypesCount": { | ||
"TILE": { | ||
"avg": 1, | ||
"max": 1, | ||
"min": 1 | ||
}, | ||
"VECTOR": { | ||
"avg": 1.6666666666666667, | ||
"max": 2, | ||
"min": 1 | ||
} | ||
}, | ||
"layersCount": { | ||
"avg": 2.6666666666666665, | ||
"max": 3, | ||
"min": 2 | ||
} | ||
}, | ||
"mapsTotalCount": 3 | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, just to let you know, if someone needed to disable task manager, they would also have to disable the Maps plugin.
You could avoid that by putting the task stuff in
x-pack/plugins/oss_telemetry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some offline conversation and some code digging, I've decided to leave this as is for now with the understanding that we may need to rethink this dependency in the future. There shouldn't be a timing issue as the plugin spec requires dependencies be both enabled and initialized (
kibana/src/plugin_discovery/plugin_spec/plugin_spec.js
Line 35 in 94d99d6
xpack.task_manager.enabled
which is obtained from the server config at init time, trying to get this info at the point of require feels hacky. This might be a bigger issue of how to elegantly handle conditional requires in a broader way moving forward and could likely be tackled in the plugin spec.