From 009c0643ef0c3834062bd6f1a60ae31bd0f51d8a Mon Sep 17 00:00:00 2001 From: Chris Roberson Date: Fri, 9 Aug 2019 14:22:30 -0400 Subject: [PATCH] [Monitoring] Use async/await pattern which should address weird bug (#42876) (#43035) * Use async/await pattern which should address weird bug * Fix tests --- .../usage/classes/__tests__/collector_set.js | 2 +- .../server/usage/classes/collector_set.js | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/legacy/server/usage/classes/__tests__/collector_set.js b/src/legacy/server/usage/classes/__tests__/collector_set.js index 6c9b9e87d6a40..5cf18a8a15200 100644 --- a/src/legacy/server/usage/classes/__tests__/collector_set.js +++ b/src/legacy/server/usage/classes/__tests__/collector_set.js @@ -87,7 +87,7 @@ describe('CollectorSet', () => { // Do nothing } // This must return an empty object instead of null/undefined - expect(result).to.eql([{}]); + expect(result).to.eql([]); }); }); diff --git a/src/legacy/server/usage/classes/collector_set.js b/src/legacy/server/usage/classes/collector_set.js index 58367e79baef6..5a86992f0af71 100644 --- a/src/legacy/server/usage/classes/collector_set.js +++ b/src/legacy/server/usage/classes/collector_set.js @@ -18,7 +18,6 @@ */ import { snakeCase } from 'lodash'; -import Promise from 'bluebird'; import { getCollectorLogger } from '../lib'; import { Collector } from './collector'; import { UsageCollector } from './usage_collector'; @@ -114,25 +113,26 @@ export class CollectorSet { * Call a bunch of fetch methods and then do them in bulk * @param {CollectorSet} collectorSet - a set of collectors to fetch. Default to all registered collectors */ - bulkFetch(callCluster, collectorSet = this) { + async bulkFetch(callCluster, collectorSet = this) { if (!(collectorSet instanceof CollectorSet)) { throw new Error(`bulkFetch method given bad collectorSet parameter: ` + typeof collectorSet); } - const fetchPromises = collectorSet.map(collector => { - const collectorType = collector.type; - this._log.debug(`Fetching data from ${collectorType} collector`); - return Promise.props({ - type: collectorType, - result: collector.fetchInternal(callCluster) // use the wrapper for fetch, kicks in error checking - }) - .catch(err => { - this._log.warn(err); - this._log.warn(`Unable to fetch data from ${collectorType} collector`); - return {}; + const responses = []; + await collectorSet.asyncEach(async collector => { + this._log.debug(`Fetching data from ${collector.type} collector`); + try { + responses.push({ + type: collector.type, + result: await collector.fetchInternal(callCluster) }); + } + catch (err) { + this._log.warn(err); + this._log.warn(`Unable to fetch data from ${collector.type} collector`); + } }); - return Promise.all(fetchPromises); + return responses; } /*