chaos-monkey-spring-boot icon indicating copy to clipboard operation
chaos-monkey-spring-boot copied to clipboard

Support Spring Data's Repository interface

Open jonatan-ivanov opened this issue 3 years ago • 4 comments

As far as I know (and as it is documented), the repository watcher (chaos.monkey.watcher.repository) only supports the @Repository stereotype. There are use-cases where repositories are created without the user annotating them with the @Repository annotation. E.g.: Spring Data JPA, Spring Data Rest, etc. generates implementation for interfaces that extend org.springframework.data.repository.Repository (or one of it's sub-interface like CrudRepository or PagingAndSortingRepository). These repositories are not watched by the repository watcher.

Expected Behavior

org.springframework.data.repository.Repository instances should be watched if chaos.monkey.watcher.repository is set to true.

Current Behavior

org.springframework.data.repository.Repository instances are not watched if chaos.monkey.watcher.repository is set to true.

Possible Solution

I'm not very familiar with the internals of the projects but loosening the predicate that decides if a bean is watched or not during scanning should solve this (I guess).

Steps to Reproduce

I think this is by-design but here's a reproducer; you need to re-enable chaos-monkey and set chaos.monkey.watcher.repository=true.

Context (Environment)

I would like to inject errors and latency inside of my application close to the DB. I'm using Spring Boot 2.7.0 (latest right now)

jonatan-ivanov avatar May 31 '22 23:05 jonatan-ivanov

I think this is supposed to already work that way, hence the bug label.

F43nd1r avatar Jun 03 '22 09:06 F43nd1r

Update: This does work usually. I have not yet been able to identify why it doesn't work in your project. You could help us by slimming down the project to a minimum viable reproducer.

F43nd1r avatar Jun 03 '22 14:06 F43nd1r

@F43nd1r I slimmed down one of your sample apps and it seems it does not work on my box: https://github.com/jonatan-ivanov/chaos-monkey-spring-boot/tree/spring-data-jpa-demo (the diff is not very nice so I recommend viewing the code, it's small)

A few notes for the demo app:

  • I removed @Repository from the HelloRepository interface, the @Repository stereotype is not for this use-case, it is not needed
  • If you call the http://localhost:8080/hello endpoint (see: HelloController), chaos monkey does work: chaos.monkey.watcher.rest-controller=true
  • If you call the http://localhost:8080/helloes (see: HelloRepository), chaos monkey does nothing: chaos.monkey.watcher.repository=true

Please let me know if you were able to repro the issue with this sample.

jonatan-ivanov avatar Jun 04 '22 00:06 jonatan-ivanov

Your demo works as expected for me. Please note that enabling multiple assaults (exception and latency) means one will be picked at random, so not every request fails.

F43nd1r avatar Jun 10 '22 08:06 F43nd1r

This issue was marked as stale because it has been open and waiting for feedback for 60 days with no activity. If no feedback is provided within 14 days, this will be closed.

github-actions[bot] avatar Oct 19 '22 05:10 github-actions[bot]

@jonatan-ivanov This is probably fixed with #335. It works with the latest snapshot (instructions here.

Would be great if you let usknow if it works in your use case as well :)

WtfJoke avatar Feb 05 '23 23:02 WtfJoke