mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	process buckets
This commit is contained in:
		
							parent
							
								
									44f5d5edd4
								
							
						
					
					
						commit
						4778f9a7bd
					
				@ -6,7 +6,7 @@ module.exports = class UnleashClientMetrics {
 | 
				
			|||||||
        this.apps = [];
 | 
					        this.apps = [];
 | 
				
			||||||
        this.clients = {};
 | 
					        this.clients = {};
 | 
				
			||||||
        this.strategies = {};
 | 
					        this.strategies = {};
 | 
				
			||||||
        this.store = {};
 | 
					        this.buckets = {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    toJSON () {
 | 
					    toJSON () {
 | 
				
			||||||
@ -21,7 +21,7 @@ module.exports = class UnleashClientMetrics {
 | 
				
			|||||||
            apps: this.apps,
 | 
					            apps: this.apps,
 | 
				
			||||||
            clients: this.clients,
 | 
					            clients: this.clients,
 | 
				
			||||||
            strategies: this.strategies,
 | 
					            strategies: this.strategies,
 | 
				
			||||||
            store: this.store,
 | 
					            buckets: this.buckets,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,28 +29,25 @@ module.exports = class UnleashClientMetrics {
 | 
				
			|||||||
        this.addApp(data.appName);
 | 
					        this.addApp(data.appName);
 | 
				
			||||||
        this.addClient(data.appName, data.instanceId, data.clientInitTime);
 | 
					        this.addClient(data.appName, data.instanceId, data.clientInitTime);
 | 
				
			||||||
        this.addStrategies(data.appName, data.strategies);
 | 
					        this.addStrategies(data.appName, data.strategies);
 | 
				
			||||||
        this.addStore(data.appName, data.instanceId, data.store);
 | 
					        this.addBucket(data.appName, data.instanceId, data.bucket);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addStore (appName, instanceId, instanceStore) {
 | 
					    addBucket (appName, instanceId, bucket) {
 | 
				
			||||||
        // TODO normalize time client-server-time / NTP?
 | 
					        // TODO normalize time client-server-time / NTP?
 | 
				
			||||||
        const normalizeTimeEntries = (entry) => Object.assign({ appName, instanceId }, entry);
 | 
					 | 
				
			||||||
        let count = 0;
 | 
					        let count = 0;
 | 
				
			||||||
 | 
					        const { start, stop, toggles } = bucket;
 | 
				
			||||||
        Object.keys(instanceStore).forEach((n) => {
 | 
					        Object.keys(toggles).forEach((n) => {
 | 
				
			||||||
            if (n.startsWith('_')) {
 | 
					            if (this.buckets[n]) {
 | 
				
			||||||
                return;
 | 
					                this.buckets[n].yes.push({ start, stop, count: toggles[n].yes });
 | 
				
			||||||
            }
 | 
					                this.buckets[n].no.push({ start, stop, count: toggles[n].no });
 | 
				
			||||||
            if (this.store[n]) {
 | 
					 | 
				
			||||||
                this.store[n].yes = this.store[n].yes.concat(instanceStore[n].yes.map(normalizeTimeEntries));
 | 
					 | 
				
			||||||
                this.store[n].no = this.store[n].no.concat(instanceStore[n].no.map(normalizeTimeEntries));
 | 
					 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                this.store[n] = {
 | 
					                this.buckets[n] = {
 | 
				
			||||||
                    yes: instanceStore[n].yes.map(normalizeTimeEntries),
 | 
					                    yes: [{ start, stop, count: toggles[n].yes }],
 | 
				
			||||||
                    no: instanceStore[n].no.map(normalizeTimeEntries),
 | 
					                    no: [{ start, stop, count: toggles[n].no }],
 | 
				
			||||||
                };
 | 
					                };
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            count += (instanceStore[n].yes.length + instanceStore[n].no.length);
 | 
					
 | 
				
			||||||
 | 
					            count += (toggles[n].yes + toggles[n].no);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        this.addClientCount(instanceId, count);
 | 
					        this.addClientCount(instanceId, count);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user