From 3b49f827923641af090a9cdf630ded8ce563e8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 6 Apr 2020 19:03:55 +0100 Subject: [PATCH] Filter the collectors properly in bulkFetch --- .../server/collector/collector_set.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/usage_collection/server/collector/collector_set.ts b/src/plugins/usage_collection/server/collector/collector_set.ts index d1dabfa42d413..dbbabfc2ad8f3 100644 --- a/src/plugins/usage_collection/server/collector/collector_set.ts +++ b/src/plugins/usage_collection/server/collector/collector_set.ts @@ -125,11 +125,19 @@ export class CollectorSet { collectionName: string, collectors: Array> = this.collectors ) => { - const filteredCollectors = collectors.filter(collector => { - return !collector.onlyForCollectionName || collector.onlyForCollectionName === collectionName; - }); + const filteredCollectors = collectors.reduce((acc, collector) => { + const { type, onlyForCollectionName } = collector; + // If it's an exclusive collector OR it's not exclusive but it hasn't been assigned before + if (onlyForCollectionName === collectionName || (!onlyForCollectionName && !acc[type])) { + return { + ...acc, + [type]: collector, + }; + } + return acc; + }, {} as { [key: string]: Collector }); const responses = []; - for (const collector of filteredCollectors) { + for (const collector of Object.values(filteredCollectors)) { this.logger.debug(`Fetching data from ${collector.type} collector`); try { responses.push({