diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js index 0b69370b8e4c1e..3c5065a782c951 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js @@ -19,6 +19,18 @@ class MockCollectorSet { async bulkFetch() { return this.mockCollectors.map(({ fetch }) => fetch()); } + bulkFormat(data) { + return data.reduce((accum, collectedData) => { + if (collectedData) { + const collector = this.mockCollectors[0]; + const formatter = collector.formatForBulkUpload || (result => ([ + { type: collector.type, payload: result } + ])); + accum.push(formatter(collectedData.result)); + } + return accum; + }, []); + } } describe('BulkUploader', () => { diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js index 5b22da47748cda..31fe51e5163ef4 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { get, set, flatten, uniq } from 'lodash'; +import { get, set, flatten, uniq, compact } from 'lodash'; import { callClusterFactory } from '../../../xpack_main'; import { LOGGING_TAG, @@ -149,7 +149,9 @@ export class BulkUploader { * Non-legacy transformation is done in CollectorSet.toApiStats */ static toBulkUploadFormat(uploadData, collectorSet) { - return flatten(BulkUploader.deepMergeUploadData(uploadData, collectorSet)); + if (compact(uploadData).length > 0) { + return flatten(BulkUploader.deepMergeUploadData(uploadData, collectorSet)); + } } static checkPayloadTypesUnique(payload) {