-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: circuit status now contains a rolling window (#34)
* feat: circuit status now contains a rolling window The rolling stats window is configurable in both total time sampled, and how many snapshots, or buckets, within that time frame. The new options that can be applied to a circuit breaker are `rollingCountTimeout` and `rollingCountBuckets`, which default to 10000 and 10, respectively. So by default, the window is a statistical view over the last 10 seconds, consisting of 10 one second snapshots. The current circuit breaker status api has not been modified directly, however the expected results are different. For example, you can still do this: ```js console.log(`Failure count: ${circuit.status.failures}`); ``` But that count will consist only of the number of failures within the current snapshot. To obtain stats for the entire window, use the `window` property. ```js const stats = circuit.status.window; ``` This will give you an array containing the statistical sampling for the entire window. So, given the defaults noted above, by default this will be a ten element array, with each element containing an object with sample data that looks something like this: ```js { failures: 11, fallbacks: 9, successes: 3491, rejects: 2, fires: 3493, timeouts: 0, start: 1488999002013 } ``` * feat: add status listeners Users can add a listener to a circuit's status object, which gets called with the most recent status each time a new snapshot is created. Allows users to maintain cumulative stats if they want to. * chore: move increment function out of Status ctor * bug: circuit should emit 'fire' even on cache hit. * (feat) add isCircuitBreakerOpen property to stats * chore: remove some redundant code
- Loading branch information
Showing
3 changed files
with
205 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters