How to inject Exception Assault using CM4SB (chaos monkey for spring boot) in Spring Data JPA Repository?

162 views
Skip to first unread message

Pratik Chauhan

unread,
Mar 22, 2025, 3:55:13 AMMar 22
to Chaos Community
0

I want to inject java.sql.SQLException Exception Assault using CM4SB library in target spring boot application for org.springframework.data.repository.CrudRepository.findById method.

Need help with working Assault-watcher configuration.

I tried multiple way but could not get any working solution.

I referred - https://codecentric.github.io/chaos-monkey-spring-boot/latest/#_properties for assault-watcher configuration.

Appreciate your helps !! Thanks !!

aniiket bhute

unread,
Mar 22, 2025, 2:12:01 PMMar 22
to Chaos Community
Hi Pratik,

Have you tried below approach ?

Enable Chaos Monkey in application.properties

Configure Chaos Monkey to target repository methods like findById().

chaos.monkey.enabled=true
chaos.monkey.assaults.exceptions-active=true
chaos.monkey.assaults.exception-class=java.sql.SQLException
chaos.monkey.assaults.exception-message=Database connection failed
chaos.monkey.watcher.repository=true

Inject Chaos into CrudRepository.findById()

Ensure you have a Spring Data repository:

@Service

public class UserService {

    @Autowired
    private UserRepository userRepository;

    public User getUserById(Long id) {
        return userRepository.findById(id)
                .orElseThrow(() -> new RuntimeException("User not found"));
    }
}

Run your application and test calling the endpoint. If CM4SB is enabled, some requests will fail with SQLException as configured.


Enable Chaos Monkey Actuator Endpoint

If you need dynamic control, enable Spring Boot Actuator and Chaos Monkey:

management.endpoints.web.exposure.include=chaosmonkey
management.endpoint.chaosmonkey.enabled=true

Then, toggle assaults dynamically via:

curl -X POST http://localhost:8080/actuator/chaosmonkey/assaults/exception


Make sure chaos.monkey.watcher.repository=true is enabled.


cheers


Pratik Chauhan

unread,
Mar 23, 2025, 1:52:50 AMMar 23
to Chaos Community
Hi Aniiket,

Thank you for taking interest and providing inputs.

I tried the assault-watcher configuration which you suggested. But, it's not injecting assault at the Repository method.
If you have a working example, please share with me if it's feasible.

Thanks !!

Pratik Chauhan

unread,
Mar 24, 2025, 12:39:46 PMMar 24
to Chaos Community
This issue is happening with v3.2.0. Its working fine with v2.2.0

Refer - https://github.com/codecentric/chaos-monkey-spring-boot/issues/554 for complete details.
Reply all
Reply to author
Forward
0 new messages