Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: circuit status now contains a rolling window #34

Merged
merged 6 commits into from
Mar 30, 2017
Merged

Conversation

lance
Copy link
Member

@lance lance commented Mar 8, 2017

This is an ongoing PR, do not merge yet

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:

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.

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:

{
  failures: 11,
  fallbacks: 9,
  successes: 3491,
  rejects: 2,
  fires: 3493,
  timeouts: 0,
  start: 1488999002013
}

@lance lance self-assigned this Mar 8, 2017
@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage decreased (-0.8%) to 96.04% when pulling 40fd56d on rolling-stats into 8fb9561 on master.

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage decreased (-0.6%) to 96.154% when pulling 00c4b84 on rolling-stats into 8fb9561 on master.

lib/status.js Outdated
}

const stats = () => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache hits/misses will be part of stats [right?]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge from master before pushing my changes. There will be conflicts in this file, but I will deal with them.

Copy link
Member

@lholmquist lholmquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far 👍

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 96.537% when pulling 1bc3365 on rolling-stats into 770950d on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 96.537% when pulling 1bc3365 on rolling-stats into 770950d on master.

@coveralls
Copy link

coveralls commented Mar 21, 2017

Coverage Status

Coverage increased (+1.3%) to 98.429% when pulling ea970be on rolling-stats into 770950d on master.

@coveralls
Copy link

coveralls commented Mar 27, 2017

Coverage Status

Coverage increased (+1.3%) to 98.421% when pulling 972b830 on rolling-stats into 770950d on master.

lance and others added 6 commits March 30, 2017 09:18
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
}
```
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.
@coveralls
Copy link

coveralls commented Mar 30, 2017

Coverage Status

Coverage decreased (-0.9%) to 98.421% when pulling 1434c0f on rolling-stats into 3657436 on master.

@lance
Copy link
Member Author

lance commented Mar 30, 2017

Merging this as is for the time being and adding #37 #38 and #39 as new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants