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

Feature Proposal - Add callback to be run when chaos is injected #65

Open
iCodeSometime opened this issue Dec 28, 2021 · 1 comment
Open
Labels
feature up-for-grabs Good for newcomers

Comments

@iCodeSometime
Copy link

iCodeSometime commented Dec 28, 2021

It would be nice to be able to run code when chaos is injected (by any of the simmy injection policies).

Example use-case:

var  chaosExceptionPolicy = MonkeyPolicy
    .InjectExceptionAsync(with => with
        .Fault(new TimeoutException())
        .InjectionRate(0.2)
        .Enabled()
        .OnInject((context, exception, cancellation) => logger.LogInformation("Injecting Chaos"));

Alternative:
Using InjectBehavior rather than InjectException, and throwing the exception myself would also work without changes in Simmy.

@vany0114 vany0114 added feature up-for-grabs Good for newcomers labels Dec 29, 2021
@vany0114
Copy link
Member

vany0114 commented Dec 29, 2021

Hey @iCodeSometime that's a great idea (and a nice workaround too by using the InjectBehavior monkey). If you want to contribute, a PR is more than welcome!

If so, here's a rough idea about the implementation: you would need to update the engines (async, sync) and call the delegate after the chaos is injected (behavior, exception or, result). In the case of the exception monkey, you should call the delegate right before throwing the exception (obviously)

You'll also need to update the InjectOptionsBase (both async and sync implementations) and its extensions so that you can expose the OnInject method.

iCodeSometime added a commit to iCodeSometime/Simmy that referenced this issue Jan 20, 2022
iCodeSometime added a commit to iCodeSometime/Simmy that referenced this issue Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature up-for-grabs Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants