Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
49 changes: 42 additions & 7 deletions docs/chaos/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,54 @@
// Finally, configure chaos strategies if you want to inject chaos.
// These should come after the regular resilience strategies.
// 2% of invocations will be injected with chaos
const double InjectionRate = 0.02;
// 2% of all requests will be injected with chaos fault.
const double faultInjectionRate = 0.02;
// For the remaining 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency.
// Latency injection does not return early.
const double latencyInjectionRate = 0.50;
// For the remaining 98% of total requests, 10% of them will be injected with outcome. Then 9.8% of total request will be injected with chaos outcome.
const double outcomeInjectionRate = 0.10;
// For the remaining 88.2% of total requests, 1% of them will be injected with behavior. Then 0.882% of total request will be injected with chaos behavior.
const double behaviorInjectionRate = 0.01;

builder
.AddChaosLatency(InjectionRate, TimeSpan.FromMinutes(1)) // Inject a chaos latency to executions
.AddChaosFault(InjectionRate, () => new InvalidOperationException("Injected by chaos strategy!")) // Inject a chaos fault to executions
.AddChaosOutcome(InjectionRate, () => new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)) // Inject a chaos outcome to executions
.AddChaosBehavior(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions
.AddChaosFault(faultInjectionRate, () => new InvalidOperationException("Injected by chaos strategy!")) // Inject a chaos fault to executions
.AddChaosLatency(latencyInjectionRate, TimeSpan.FromMinutes(1)) // Inject a chaos latency to executions
.AddChaosOutcome(outcomeInjectionRate, () => new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)) // Inject a chaos outcome to executions
.AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions
```
<!-- endSnippet -->

> [!NOTE]
> It is usual to place the chaos strategy as the last strategy in the resilience pipeline. By placing the chaos strategies as last, they subvert the usual outbound call at the last minute, substituting their fault or adding extra latency, etc. The existing resilience strategies - further out in the `ResiliencePipeline` - still apply, so you can test how the Polly resilience strategies you have configured handle the chaos/faults injected by Simmy.
> It is usual to place the chaos strategy as the last strategy in the resilience pipeline.
> By placing the chaos strategies as last, they subvert the usual outbound call at the last minute, substituting their fault or adding extra latency, etc.
> The existing resilience strategies - further out in the `ResiliencePipeline` - still apply, so you can test how the Polly resilience strategies you have configured handle the chaos/faults injected by Simmy.

Check failure on line 55 in docs/chaos/index.md

View workflow job for this annotation

GitHub Actions / build-docs

Blank line inside blockquote

docs/chaos/index.md:55 MD028/no-blanks-blockquote Blank line inside blockquote https://github.com/DavidAnson/markdownlint/blob/v0.37.4/doc/md028.md
> [!NOTE]
> The `AddChaosFault` `AddChaosLatency` `AddChaosOutcome` `AddChaosBehavior` will take effect sequentially if you combine them together.
> In the above example, we use **fault first then latency strategy**, it can save fault waiting time. If you put `AddChaosLatency` before `AddChaosFault`, you will get different behavior.
```mermaid
sequenceDiagram
autonumber
actor C as Caller
participant F as Fault
participant L as Latency
participant O as Outcome
participant B as Behavior
actor E as Callee
C->>F: Calls AddChaosFault
F->>C: 2% requests return
F->>L: Calls AddChaosLatency [98% requests left]
L->>L: 49% requests with latency
L->>O: Calls AddChaosOutcome [98% requests left]
O->>C: 9.8% reqeuests return
O->>B: Calls AddChaosBehavior [88.2% requests left]
B->>B: 0.882% requests with behavior
B->>E: Outgoing requests
E->>C: returns real result
```

## Major differences

Expand Down
19 changes: 13 additions & 6 deletions src/Snippets/Docs/Chaos.Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@
// Finally, configure chaos strategies if you want to inject chaos.
// These should come after the regular resilience strategies.

// 2% of invocations will be injected with chaos
const double InjectionRate = 0.02;
// 2% of all requests will be injected with chaos fault.
const double faultInjectionRate = 0.02;

Check failure on line 32 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: faultInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 32 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: faultInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)
// For the remaining 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency.
// Latency injection does not return early.
const double latencyInjectionRate = 0.50;

Check failure on line 35 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: latencyInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 35 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: latencyInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 35 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / macos-latest

Naming rule violation: These words must begin with upper case characters: latencyInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 35 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Naming rule violation: These words must begin with upper case characters: latencyInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)
// For the remaining 98% of total requests, 10% of them will be injected with outcome. Then 9.8% of total request will be injected with chaos outcome.
const double outcomeInjectionRate = 0.10;

Check failure on line 37 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: outcomeInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 37 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: outcomeInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 37 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / macos-latest

Naming rule violation: These words must begin with upper case characters: outcomeInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 37 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Naming rule violation: These words must begin with upper case characters: outcomeInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)
// For the remaining 88.2% of total requests, 1% of them will be injected with behavior. Then 0.882% of total request will be injected with chaos behavior.
const double behaviorInjectionRate = 0.01;

Check failure on line 39 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: behaviorInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 39 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Naming rule violation: These words must begin with upper case characters: behaviorInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 39 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / macos-latest

Naming rule violation: These words must begin with upper case characters: behaviorInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

Check failure on line 39 in src/Snippets/Docs/Chaos.Index.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Naming rule violation: These words must begin with upper case characters: behaviorInjectionRate (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1006)

builder
.AddChaosLatency(InjectionRate, TimeSpan.FromMinutes(1)) // Inject a chaos latency to executions
.AddChaosFault(InjectionRate, () => new InvalidOperationException("Injected by chaos strategy!")) // Inject a chaos fault to executions
.AddChaosOutcome(InjectionRate, () => new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)) // Inject a chaos outcome to executions
.AddChaosBehavior(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions
.AddChaosFault(faultInjectionRate, () => new InvalidOperationException("Injected by chaos strategy!")) // Inject a chaos fault to executions
.AddChaosLatency(latencyInjectionRate, TimeSpan.FromMinutes(1)) // Inject a chaos latency to executions
.AddChaosOutcome(outcomeInjectionRate, () => new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)) // Inject a chaos outcome to executions
.AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions

#endregion
}
Expand Down
Loading