This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from jeffggardner/master
Added the ability to fine-tune the probability on a per-ASG basis.
- Loading branch information
Showing
7 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/netflix/simianarmy/tunable/TunableInstanceGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.netflix.simianarmy.tunable; | ||
|
||
import com.netflix.simianarmy.GroupType; | ||
import com.netflix.simianarmy.basic.chaos.BasicInstanceGroup; | ||
|
||
/** | ||
* Allows for individual InstanceGroups to alter the aggressiveness | ||
* of ChaosMonkey. | ||
* | ||
* @author jeffggardner | ||
* | ||
*/ | ||
public class TunableInstanceGroup extends BasicInstanceGroup { | ||
|
||
public TunableInstanceGroup(String name, GroupType type, String region) { | ||
super(name, type, region); | ||
} | ||
|
||
private double aggressionCoefficient = 1.0; | ||
|
||
/** | ||
* @return the aggressionCoefficient | ||
*/ | ||
public final double getAggressionCoefficient() { | ||
return aggressionCoefficient; | ||
} | ||
|
||
/** | ||
* @param aggressionCoefficient the aggressionCoefficient to set | ||
*/ | ||
public final void setAggressionCoefficient(double aggressionCoefficient) { | ||
this.aggressionCoefficient = aggressionCoefficient; | ||
} | ||
|
||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/netflix/simianarmy/tunable/TunablyAggressiveChaosMonkey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.netflix.simianarmy.tunable; | ||
|
||
import com.netflix.simianarmy.basic.chaos.BasicChaosMonkey; | ||
import com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup; | ||
|
||
/** | ||
* This class modifies the probability by multiplying the configured | ||
* probability by the aggression coefficient tag on the instance group. | ||
* | ||
* @author jeffggardner | ||
*/ | ||
public class TunablyAggressiveChaosMonkey extends BasicChaosMonkey { | ||
|
||
public TunablyAggressiveChaosMonkey(Context ctx) { | ||
super(ctx); | ||
} | ||
|
||
/** | ||
* Gets the tuned probability value, returns 0 if the group is not | ||
* enabled. Calls getEffectiveProbability and modifies that value if | ||
* the instance group is a TunableInstanceGroup. | ||
* | ||
* @param group The instance group | ||
* @return the effective probability value for the instance group | ||
*/ | ||
@Override | ||
protected double getEffectiveProbability(InstanceGroup group) { | ||
|
||
if (!isGroupEnabled(group)) { | ||
return 0; | ||
} | ||
|
||
double probability = getEffectiveProbabilityFromCfg(group); | ||
|
||
// if this instance group is tunable, then factor in the aggression coefficient | ||
if (group instanceof TunableInstanceGroup ) { | ||
TunableInstanceGroup tunable = (TunableInstanceGroup) group; | ||
probability *= tunable.getAggressionCoefficient(); | ||
} | ||
|
||
return probability; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/com/netflix/simianarmy/tunable/TestTunablyAggressiveChaosMonkey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.netflix.simianarmy.tunable; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import com.netflix.simianarmy.GroupType; | ||
import com.netflix.simianarmy.basic.chaos.BasicInstanceGroup; | ||
import com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup; | ||
import com.netflix.simianarmy.chaos.TestChaosMonkeyContext; | ||
|
||
public class TestTunablyAggressiveChaosMonkey { | ||
private enum GroupTypes implements GroupType { | ||
TYPE_A, TYPE_B | ||
}; | ||
|
||
@Test | ||
public void testFullProbability_basic() { | ||
TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("fullProbability.properties"); | ||
|
||
TunablyAggressiveChaosMonkey chaos = new TunablyAggressiveChaosMonkey(ctx); | ||
|
||
InstanceGroup basic = new BasicInstanceGroup("basic", GroupTypes.TYPE_A, "region"); | ||
|
||
double probability = chaos.getEffectiveProbability(basic); | ||
|
||
Assert.assertEquals(probability, 1.0); | ||
} | ||
|
||
@Test | ||
public void testFullProbability_tuned() { | ||
TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("fullProbability.properties"); | ||
|
||
TunablyAggressiveChaosMonkey chaos = new TunablyAggressiveChaosMonkey(ctx); | ||
|
||
TunableInstanceGroup tuned = new TunableInstanceGroup("basic", GroupTypes.TYPE_A, "region"); | ||
tuned.setAggressionCoefficient(0.5); | ||
|
||
double probability = chaos.getEffectiveProbability(tuned); | ||
|
||
Assert.assertEquals(probability, 0.5); | ||
} | ||
} |