connor4312 / cockatiel

🐦 A resilience and transient-fault-handling library that allows developers to express policies such as Backoff, Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback. Inspired by .NET Polly.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Q: Is there an easy way to track all signals with simple event handler?

trenttobler opened this issue · comments

Love the power and flexibility of this library.

I'm wondering if there is an easy way to track the various signals for metrics / counts / errors, etc. the policies use and generate for the on_____(..) methods across each of the policy types.

Specifically, I was using opossum for circuit breaker, and was looking to remove some custom logic for retry, bulkhead, etc, by replacing that use with cockatiel. However, the event tracking appears to wiring up a function for each listener / event name, E.G, onTimeout, onReset, onSuccess, onHalfOpen, etc. It seems one must know and attach to every listener, and continue to maintain those signals as the library features evolve.

In contrast, the metrics that I had added in opossum was just this (ref: https://nodejs.org/api/events.html#emittereventnames):

for(const key of breaker.eventNames()) {
  breaker.on(key, () => incrementApiMetric(key));
}

NOTE: incrementApiMetric would send stats to DataDog, NewRelic, or other metrics collection library.

I tried looking through the source but nothing jumped out as being as trivial / easy at capturing existing and future event signals. Any suggestions or is this something that could be added as the features evolve? Will it require just unrolling the loop and adding one metric callback per each on____() method?

I've requested similar in issue #20 , you can use onStateChange for monitoring.

Yep, onStateChange is the way to go. Let me know if you need anything beyond that.