Skip to content

Commit

Permalink
feat: allow multiple circuits to aggregate stats (#140)
Browse files Browse the repository at this point in the history
If a user creates multiple circuits in the same process, they should aggregate
their stats in the Hystrix stream.

Fixes: #125
Ref: #124

Now that we are piping all event data for all circuits through a single 
`TransformStream`, a LOT of events are being listened for. I've bumped
the limit to 100.
  • Loading branch information
lance authored Mar 18, 2018
1 parent 4e702f1 commit ba71840
Show file tree
Hide file tree
Showing 15 changed files with 620 additions and 167 deletions.
8 changes: 6 additions & 2 deletions examples/hystrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ This example shows how to access the Hystrix Metrics and create an SSE stream th

Similiar to the jQuery example, a simple service is exposed at the route `http://localhost:3000`. As the service receives requests, it gets slower and slower. Once it takes more than 1 second to respond, the service just returns a `423 (Locked)` error. There is also a SSE stream available at `http://localhost:3000/hystrix.stream`

To see the Hystrix Metrics in action, you will need to run the Hystrix Dashboard. There are instructions on how to do that here: https://github.com/Netflix/Hystrix/tree/master/hystrix-dashboard
To see the Hystrix Metrics in action, you will need to run the Hystrix Dashboard. There is a standalone Hystrix Dashboard that you can run for the purposes of this example at https://github.com/kennedyoliveira/standalone-hystrix-dashboard. The easiest way is to just download the fat jar and run it in its own terminal window.

Once the dashboard is running, navigate to `http://localhost:7979/hystrix-dashboard` (this assumes you are running it from the git repo), and add our servers hystrix stream.
```sh
java -jar standalone-hystrix-dashboard-1.5.6-all.jar
```

Once the dashboard is running, navigate to `http://localhost:7979/hystrix-dashboard`, and add the hystrix stream at `http://localhost:3000/hystrix.stream`.

Now make a few requests to `http://localhost:3000` and you should see movement on the dashboard

Expand Down
16 changes: 4 additions & 12 deletions examples/hystrix/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let delay = baseline;
function flakeFunction () {
return new Promise((resolve, reject) => {
if (delay > 1000) {
return reject('Flakey Service is Flakey');
return reject(new Error('Flakey Service is Flakey'));
}

setTimeout(() => {
Expand Down Expand Up @@ -48,21 +48,13 @@ function fallback () {
const circuit = circuitBreaker(flakeFunction, circuitBreakerOptions);
circuit.fallback(fallback);

const hystrixStats = circuit.hystrixStats;

// setup our SSE endpoint
app.use('/hystrix.stream', (request, response) => {
response.writeHead(200, {'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive'});
response.write('retry: 10000\n');
response.write('event: connecttime\n');

hystrixStats.getHystrixStream().pipe(response);
});
app.use('/hystrix.stream', require('./hystrix-stream')(circuitBreaker));

app.use('/', (request, response) => {
circuit.fire().then((result) => {
circuit.fire().then(result => {
response.send(result);
}).catch((err) => {
}).catch(err => {
response.send(err);
});
});
Expand Down
15 changes: 15 additions & 0 deletions examples/hystrix/hystrix-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

function hystrixStream (circuitBreaker) {
return (request, response) => {
response.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive'});
response.write('retry: 10000\n');
response.write('event: connecttime\n');

circuitBreaker.stats.pipe(response);
};
}

module.exports = hystrixStream;
Loading

0 comments on commit ba71840

Please sign in to comment.