ackintosh / ganesha

:elephant: A Circuit Breaker pattern implementation for PHP applications.
https://ackintosh.github.io/ganesha/
MIT License
585 stars 42 forks source link

Enable users to provide suffix and prefix particles #48

Closed albertojgomez closed 5 years ago

albertojgomez commented 5 years ago

This PR enables users to provide an object that contains the keys to be used when storing circuit breaker information

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-1.3%) to 91.108% when pulling 4db930a98b67de7dcaa21bbbafee7fa5a520c6d0 on albertojgomez:patch/flexible-suffix-prefix into ab33f5ef81f224a2191a6138092bae986e9cf46a on ackintosh:master.

ackintosh commented 5 years ago

Thanks for your PR! I'll have a look on this weekend. 😉

albertojgomez commented 5 years ago

Thanks @ackintosh ! Much appreciated.

ackintosh commented 5 years ago

Question: How could we use our custom StrorageKeys implementation? Typically an instance of Ganesha is built via Ganesha::Builder but I could not find the way that pass a StorageKeys.

ackintosh commented 5 years ago

https://github.com/ackintosh/ganesha/pull/48#issuecomment-526795336

I think it may be good that we can pass an instance of StorageKeysInterface implementation via Builder like below 💡 :

(the sample below is based on https://github.com/ackintosh/ganesha#rate-default )

$ganesha = Ackintosh\Ganesha\Builder::build([
    // The interval in time (seconds) that evaluate the thresholds. 
    'timeWindow'            => 30,
    // The failure rate threshold in percentage that changes CircuitBreaker's state to `OPEN`.
    'failureRateThreshold'  => 50,
    // The minimum number of requests to detect failures.
    // Even if `failureRateThreshold` exceeds the threshold,
    // CircuitBreaker remains in `CLOSED` if `minimumRequests` is below this threshold.
    'minimumRequests'       => 10,
    // The interval (seconds) to change CircuitBreaker's state from `OPEN` to `HALF_OPEN`.
    'intervalToHalfOpen'    => 5,
    // The storage adapter instance to store various statistics to detect failures.
    'adapter'               => new Ackintosh\Ganesha\Storage\Adapter\Memcached($memcached),
+   // If you want customize the keys to be used when storing circuit breaker information,
+   // set an instance of StorageKeysInterface implementation.
+   'storageKeys'           => new YourStorageKeys(),
]);

That is not required for this PR. 😌 So if making the builder parameter(storageKeys) available is hard for you, the enhancement will be day2-requirement.

ackintosh commented 5 years ago

Hi @albertojgomez , I would appriciate it if you could check the comments. 😺

ackintosh commented 5 years ago

I still can't get your reply but have updated the PR because this enhancement is worth providing to users. Thank you for your understanding. ✨