ackintosh / ganesha

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

Creating new strategies #114

Open maxbaldanza opened 6 months ago

maxbaldanza commented 6 months ago

Hi,

Great package 🙌

We'd like to create a new strategy that opens the circuit if a request takes too long for example if a request took longer then 5s X times in X seconds. One way to achieve this is to set the timeout in Guzzle/http client which would throw an exception but the problem with this is that we want the request to continue to process rather than throw an exception after a certain timeout. Therefore we we're thinking of creating a new Strategy that would track the time it took to process and either say success/failure based on this time.

The problem we have is how we set the Configuration for this timeout because this gets passed to the service but the configuration for this Strategy will be different to the existing ones. Any plans/thoughts on how to change the configuration for new strategies?

maxbaldanza commented 6 months ago

Happy to help by the way but I suspect the changes needed may be breaking changes so just thought I'd gather feedback first

maxbaldanza commented 6 months ago

@ackintosh would love to get your thoughts on this 😄

TheCelavi commented 2 days ago

@maxbaldanza Sorry to meddle - I was investigating similar idea, but it seams that new strategy is not necessary to have same functionality. Our approach is to wait for request to complete, check the response time and if it is longer than acceptable (per example, 10s and we expected 2 or less) we report that as failure.

Logic behind that is that endpoint is obviously in serious problem and it will probably crash very soon, so we are backing off earlier to give it a breather.

For this, we are using custom guzzle middleware.

Does this have any value to you? Please, share your thoughts - do you have different idea?

Thanks :)