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

Increment level only for methods/classes/packages listed in WatchedCustomServices (instead of every watched method/class/package) #452

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chaos-monkey-docs/src/main/asciidoc/changes.adoc
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[[changes]]
== Changes in {project-version}
== Changes in 3.1.1

Built with Spring Boot {spring-boot-version}
Built with Spring Boot 3.2.3

=== Bug Fixes
// - https://github.com/codecentric/chaos-monkey-spring-boot/pull/xxx[#xxx] Added example entry. Please don't remove.

=== Improvements
// - https://github.com/codecentric/chaos-monkey-spring-boot/pull/xxx[#xxx] Added example entry. Please don't remove.
- Increment level count exclusively for methods, classes or packages listed in WatchedCustomServices

=== New Features
// - https://github.com/codecentric/chaos-monkey-spring-boot/pull/xxx[#xxx] Added example entry. Please don't remove.
Expand All @@ -16,5 +17,6 @@ Built with Spring Boot {spring-boot-version}
This release was only possible because of these great humans ❤️:

// - https://github.com/octocat[@octocat]
- https://github.com/eshaanganesh2[@eshaanganesh2]

Thank you for your support!
6 changes: 6 additions & 0 deletions chaos-monkey-docs/src/main/asciidoc/faq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,11 @@ To prevent these classes from being proxied, you can either:
- mark them as final
- don't mark them as spring `@Component` (or `@Service`, `@Controller`, ...). Instead, register them as `@Bean` inside a configuration.

=== My classes (or methods or packages) do not get assaulted after setting the WatchedCustomServices property

- Ensure that the associated watcher property for the class/method/package is set to true
- Ensure that the fully qualified path of the class/method/package is set accurately




Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,25 +67,31 @@ public ChaosMonkeyRequestScope(ChaosMonkeySettings chaosMonkeySettings, List<Cha
}

public void callChaosMonkey(ChaosTarget type, String simpleName) {
if (isEnabled(type, simpleName) && isTrouble()) {

AssaultProperties assaultProps = chaosMonkeySettings.getAssaultProperties();
if (isEnabled(type, simpleName) && checkWhetherWatchedCustomServiceToAttack()) {
if (assaultProps.getWatchedCustomServices().stream().anyMatch(simpleName::startsWith) && isTrouble()) {
// only all listed custom methods will be attacked
if (metricEventPublisher != null) {
metricEventPublisher.publishMetricEvent(MetricType.APPLICATION_REQ_COUNT, "type", "total");
}
chooseAndRunAttack();
}
} else if (isEnabled(type, simpleName) && isTrouble()) {
if (metricEventPublisher != null) {
metricEventPublisher.publishMetricEvent(MetricType.APPLICATION_REQ_COUNT, "type", "total");
}
chooseAndRunAttack();
}
}

// Custom watched services can be defined at runtime, if there are any, only
// these will be attacked!
AssaultProperties assaultProps = chaosMonkeySettings.getAssaultProperties();
if (assaultProps.isWatchedCustomServicesActive()) {
if (assaultProps.getWatchedCustomServices().stream().anyMatch(simpleName::startsWith)) {
// only all listed custom methods will be attacked
chooseAndRunAttack();
}
} else {
// default attack if no custom watched service is defined
chooseAndRunAttack();
}
private boolean checkWhetherWatchedCustomServiceToAttack() {
// Custom watched services can be defined at runtime, if there are any, only
// these will be attacked!
AssaultProperties assaultProps = chaosMonkeySettings.getAssaultProperties();
if (assaultProps.isWatchedCustomServicesActive()) {
return true;
}
return false;
}

private void chooseAndRunAttack() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -81,6 +81,21 @@ void givenChaosMonkeyExecutionIsDisabledExpectNoInteractions() {
verify(exceptionAssault, never()).attack();
}

@Test
void chaosMonkeyIsNotCalledWhenServiceNotWatched() {
String customService = "CustomService";

given(chaosMonkeyProperties.isEnabled()).willReturn(true);
given(chaosMonkeySettings.getAssaultProperties()).willReturn(assaultProperties);
given(assaultProperties.getWatchedCustomServices()).willReturn(Collections.singletonList(customService));
given(chaosMonkeySettings.getAssaultProperties().isWatchedCustomServicesActive()).willReturn(true);

chaosMonkeyRequestScope.callChaosMonkey(null, "notInListService");

verify(latencyAssault, never()).attack();
verify(exceptionAssault, never()).attack();
}

@Nested
class GivenChaosMonekyExecutionIsEnabled {

Expand Down Expand Up @@ -196,19 +211,6 @@ void givenAssaultLevelTooHighExpectNoLogging() {
verify(exceptionAssault, never()).attack();
}

@Test
void chaosMonkeyIsNotCalledWhenServiceNotWatched() {
String customService = "CustomService";

given(assaultProperties.getWatchedCustomServices()).willReturn(Collections.singletonList(customService));
given(chaosMonkeySettings.getAssaultProperties().isWatchedCustomServicesActive()).willReturn(true);

chaosMonkeyRequestScope.callChaosMonkey(null, "notInListService");

verify(latencyAssault, never()).attack();
verify(exceptionAssault, never()).attack();
}

@Test
void chaosMonkeyIsCalledWhenServiceIsWatched() {
String customService = "CustomService";
Expand Down