From aee03862364dc05f530c0b4cb070b95935987eb2 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 13:30:06 +0800 Subject: [PATCH 01/17] Fix chaos doc example issue and enrich notes on index.md --- docs/chaos/index.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index d114f23f0e4..9e25246e435 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -30,13 +30,17 @@ builder // 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 total requests will be injected with chaos fault. +const double faultInjectionRate = 0.02; +// For the other 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency. +const double latencyInjectionRate = 0.50; +// For the other 49% of total requests, 10% of them will be injected with outcome. Then 4.9% of total request will be injected with chaos outcome. +const double outcomeInjectionRate = 0.10; 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 + .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(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions ``` @@ -44,6 +48,9 @@ builder > [!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. +> [!NOTE] +> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` will take effect sequentially if you combine them together. In the above example, we use `fault first then latency stragtegy`, it can save fault waiting time. If you put `AddChaosLatency` before `AddChaosFault`, you will get different behavior. + ## Major differences This section highlights the major differences compared to the [`Polly.Contrib.Simmy`](https://github.com/Polly-Contrib/Simmy) library: From 8cadca380290ec4ddacce7900242c0c4e54bd092 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 05:46:25 +0000 Subject: [PATCH 02/17] Fix Snippets --- src/Snippets/Docs/Chaos.Index.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Snippets/Docs/Chaos.Index.cs b/src/Snippets/Docs/Chaos.Index.cs index 0d02db88fa3..f0126261e6f 100644 --- a/src/Snippets/Docs/Chaos.Index.cs +++ b/src/Snippets/Docs/Chaos.Index.cs @@ -28,13 +28,17 @@ public static void Usage() // 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 total requests will be injected with chaos fault. + const double faultInjectionRate = 0.02; + // For the other 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency. + const double latencyInjectionRate = 0.50; + // For the other 49% of total requests, 10% of them will be injected with outcome. Then 4.9% of total request will be injected with chaos outcome. + const double outcomeInjectionRate = 0.10; 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 + .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(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions #endregion From b4dbda3f9e9c7d0761868df0e2f252365d9e4058 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 16:45:24 +0800 Subject: [PATCH 03/17] Update chaos injection rates and comments --- docs/chaos/index.md | 7 +++++-- src/Snippets/Docs/Chaos.Index.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 9e25246e435..6cde8aca250 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -33,15 +33,18 @@ builder // 2% of total requests will be injected with chaos fault. const double faultInjectionRate = 0.02; // For the other 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 other 49% of total requests, 10% of them will be injected with outcome. Then 4.9% of total request will be injected with chaos outcome. +// For the other 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 other 89.2% of total requests, 1% of them will be injected with behavior. Then 0.892% of total request will be injected with chaos behavior. +const double behaviorInjectionRate = 0.01; builder .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(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions + .AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions ``` diff --git a/src/Snippets/Docs/Chaos.Index.cs b/src/Snippets/Docs/Chaos.Index.cs index f0126261e6f..b604a45f467 100644 --- a/src/Snippets/Docs/Chaos.Index.cs +++ b/src/Snippets/Docs/Chaos.Index.cs @@ -31,15 +31,18 @@ public static void Usage() // 2% of total requests will be injected with chaos fault. const double faultInjectionRate = 0.02; // For the other 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 other 49% of total requests, 10% of them will be injected with outcome. Then 4.9% of total request will be injected with chaos outcome. + // For the other 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 other 89.2% of total requests, 1% of them will be injected with behavior. Then 0.892% of total request will be injected with chaos behavior. + const double behaviorInjectionRate = 0.01; builder .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(0.001, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions + .AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions #endregion } From 77afbd5d0bcacde7073598466832c616275ba8cb Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 16:45:52 +0800 Subject: [PATCH 04/17] Fix typo and formatting in chaos strategy note --- docs/chaos/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 6cde8aca250..1ae18cda416 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -52,7 +52,7 @@ builder > 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. > [!NOTE] -> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` will take effect sequentially if you combine them together. In the above example, we use `fault first then latency stragtegy`, it can save fault waiting time. If you put `AddChaosLatency` before `AddChaosFault`, you will get different behavior. +> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. ## Major differences From e25f060259fc1b506447621709fd0868ddd382c1 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:12:35 +0800 Subject: [PATCH 05/17] Update behavior injection rate and add diagram --- docs/chaos/index.md | 24 +++++++++++++++++++++++- src/Snippets/Docs/Chaos.Index.cs | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 1ae18cda416..81eb5c799bc 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -37,7 +37,7 @@ const double faultInjectionRate = 0.02; const double latencyInjectionRate = 0.50; // For the other 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 other 89.2% of total requests, 1% of them will be injected with behavior. Then 0.892% of total request will be injected with chaos behavior. +// For the other 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 @@ -54,6 +54,28 @@ builder > [!NOTE] > The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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 This section highlights the major differences compared to the [`Polly.Contrib.Simmy`](https://github.com/Polly-Contrib/Simmy) library: diff --git a/src/Snippets/Docs/Chaos.Index.cs b/src/Snippets/Docs/Chaos.Index.cs index b604a45f467..88111ca60dd 100644 --- a/src/Snippets/Docs/Chaos.Index.cs +++ b/src/Snippets/Docs/Chaos.Index.cs @@ -35,7 +35,7 @@ public static void Usage() const double latencyInjectionRate = 0.50; // For the other 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 other 89.2% of total requests, 1% of them will be injected with behavior. Then 0.892% of total request will be injected with chaos behavior. + // For the other 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 From dff729d414aac4f36d92666eb18a1dcb7609e61a Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:24:45 +0800 Subject: [PATCH 06/17] Update chaos injection comments for clarity --- docs/chaos/index.md | 12 +++++++----- src/Snippets/Docs/Chaos.Index.cs | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 81eb5c799bc..689e2a33330 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -30,14 +30,14 @@ builder // Finally, configure chaos strategies if you want to inject chaos. // These should come after the regular resilience strategies. -// 2% of total requests will be injected with chaos fault. +// 2% of all requests will be injected with chaos fault. const double faultInjectionRate = 0.02; -// For the other 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency. +// 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 other 98% of total requests, 10% of them will be injected with outcome. Then 9.8% of total request will be injected with chaos outcome. +// 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 other 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. +// 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 @@ -52,7 +52,9 @@ builder > 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. > [!NOTE] -> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. +> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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 diff --git a/src/Snippets/Docs/Chaos.Index.cs b/src/Snippets/Docs/Chaos.Index.cs index 88111ca60dd..110d36fe98c 100644 --- a/src/Snippets/Docs/Chaos.Index.cs +++ b/src/Snippets/Docs/Chaos.Index.cs @@ -28,14 +28,14 @@ public static void Usage() // Finally, configure chaos strategies if you want to inject chaos. // These should come after the regular resilience strategies. - // 2% of total requests will be injected with chaos fault. + // 2% of all requests will be injected with chaos fault. const double faultInjectionRate = 0.02; - // For the other 98% of total requests, 50% of them will be injected with latency. Then 49% of total request will be injected with chaos latency. + // 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 other 98% of total requests, 10% of them will be injected with outcome. Then 9.8% of total request will be injected with chaos outcome. + // 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 other 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. + // 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 From a201d4af42f01835309bb4262e8b4f254e723cb9 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:29:37 +0800 Subject: [PATCH 07/17] Add note on chaos strategy order. --- docs/chaos/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 689e2a33330..5309c0cf3e0 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -53,7 +53,9 @@ builder > [!NOTE] > The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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 From 725ced2fbda9d8d6ea146a4a7bd701c6688bf328 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:32:22 +0800 Subject: [PATCH 08/17] Update chaos strategy notes in documentation --- docs/chaos/index.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 5309c0cf3e0..4c16962d6c0 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -51,12 +51,9 @@ builder > [!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. -> [!NOTE] -> The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. +- The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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 From 52c3134483fa9478914c5565138377d2e290fcac Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:33:50 +0800 Subject: [PATCH 09/17] Update docs/chaos/index.md Co-authored-by: Martin Costello --- docs/chaos/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 4c16962d6c0..8324c53fdbf 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -49,7 +49,9 @@ builder > [!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. - The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. From 92f69d8d9ad8a52444c362a47ba1fcd0b7d07d57 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:37:44 +0800 Subject: [PATCH 10/17] Fix note formatting in chaos strategy documentation --- docs/chaos/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 8324c53fdbf..2fa54932fcd 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -49,9 +49,9 @@ builder > [!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. - The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. From bc568076b11bc678fccdc191ed42de1d2a680eaf Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:41:29 +0800 Subject: [PATCH 11/17] Remove note formatting in chaos documentation --- docs/chaos/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 2fa54932fcd..463e8a6e690 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -48,7 +48,6 @@ builder ``` -> [!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. From e5ac3f81f2f8d8043d5b8c68844b39e3cf715ba1 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:45:29 +0800 Subject: [PATCH 12/17] Fix formatting in chaos strategy documentation --- docs/chaos/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 463e8a6e690..adbe999fba2 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -52,9 +52,8 @@ builder - 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. -- The `AddChaosFault`, `AddChaosLatency`, `AddChaosOutcome` 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. +- The `AddChaos*` 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 From 245ca26a397172bc463d0a9e4c48c1aacc5edf75 Mon Sep 17 00:00:00 2001 From: caigen Date: Fri, 7 Feb 2025 17:49:34 +0800 Subject: [PATCH 13/17] Update chaos strategy documentation with notes --- docs/chaos/index.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index adbe999fba2..af5d5d466e3 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -47,13 +47,14 @@ builder .AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions ``` +> [!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. - -- The `AddChaos*` 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. +> [!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 From a9e5e10b87cb76be96e4feb19a7ecc40a966a36d Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 7 Feb 2025 09:54:58 +0000 Subject: [PATCH 14/17] Fix spacing Make markdownlint happy. --- docs/chaos/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index af5d5d466e3..1837e8b15bd 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -47,6 +47,7 @@ builder .AddChaosBehavior(behaviorInjectionRate, cancellationToken => RestartRedisAsync(cancellationToken)); // Inject a chaos behavior to executions ``` + > [!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. From a99c2cd6e434b18dba4938c22034c19ee9e7e077 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 7 Feb 2025 09:58:29 +0000 Subject: [PATCH 15/17] Fix lint warning Markdownlint doesn't like sequential notes. --- docs/chaos/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 1837e8b15bd..b950cf3cd28 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -52,8 +52,7 @@ builder > 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. - -> [!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. From 64ddacc5403b07b9d66f2c10f8254ae1e4e43b7f Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 7 Feb 2025 10:06:14 +0000 Subject: [PATCH 16/17] Apply suggestions from code review Fix casing. --- docs/chaos/index.md | 16 ++++++++-------- src/Snippets/Docs/Chaos.Index.cs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index b950cf3cd28..b9716ee7df9 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -31,20 +31,20 @@ builder // These should come after the regular resilience strategies. // 2% of all requests will be injected with chaos fault. -const double faultInjectionRate = 0.02; +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; +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; +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; +const double BehaviorInjectionRate = 0.01; builder - .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 + .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 ``` diff --git a/src/Snippets/Docs/Chaos.Index.cs b/src/Snippets/Docs/Chaos.Index.cs index 110d36fe98c..0489bfa5f5b 100644 --- a/src/Snippets/Docs/Chaos.Index.cs +++ b/src/Snippets/Docs/Chaos.Index.cs @@ -29,20 +29,20 @@ public static void Usage() // These should come after the regular resilience strategies. // 2% of all requests will be injected with chaos fault. - const double faultInjectionRate = 0.02; + 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; + 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; + 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; + const double BehaviorInjectionRate = 0.01; builder - .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 + .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 } From 35dca076a48b0cd4f090292ad3f9be9bc5a6c949 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Fri, 7 Feb 2025 11:29:50 +0000 Subject: [PATCH 17/17] Remove mermaid diagram --- docs/chaos/index.md | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/docs/chaos/index.md b/docs/chaos/index.md index b9716ee7df9..bf77043f40b 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -56,28 +56,6 @@ builder > 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 This section highlights the major differences compared to the [`Polly.Contrib.Simmy`](https://github.com/Polly-Contrib/Simmy) library: