Skip to content

Commit

Permalink
Filter the collectors properly in bulkFetch
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Apr 6, 2020
1 parent cc04a95 commit 3b49f82
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/plugins/usage_collection/server/collector/collector_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,19 @@ export class CollectorSet {
collectionName: string,
collectors: Array<Collector<any, any>> = 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<any, any> });
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({
Expand Down

0 comments on commit 3b49f82

Please sign in to comment.