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

[Docs] Add diagram to action generator hedging #1713

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions docs/strategies/circuit-breaker.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ sequenceDiagram

C->>P: Calls ExecuteAsync
P->>CB: Calls ExecuteCore
CB->>CB: Rejects request
CB-->>CB: Rejects request
CB->>P: Throws <br/>BrokenCircuitException
P->>C: Propagates exception
deactivate CB
Expand All @@ -203,6 +203,8 @@ Let's suppose we have a circuit breaker strategy with the following configuratio

#### Complex: happy path sequence diagram

The circuit will break and later it will transition into `HalfOpen` state. The probe will succeed so, the circuit breaker will go back to normal (`Closed`) state.
peter-csala marked this conversation as resolved.
Show resolved Hide resolved

```mermaid
sequenceDiagram
autonumber
Expand Down Expand Up @@ -230,7 +232,7 @@ sequenceDiagram

C->>P: Calls ExecuteAsync
P->>CB: Calls ExecuteCore
CB->>CB: Rejects request
CB-->>CB: Rejects request
CB->>P: Throws <br/>BrokenCircuitException
P->>C: Propagates exception

Expand All @@ -247,6 +249,8 @@ sequenceDiagram

#### Complex: unhappy path sequence diagram

The circuit will break and later it will transition into `HalfOpen` state. The probe will fail so, the circuit breaker will become broken again (`Open` state).
peter-csala marked this conversation as resolved.
Show resolved Hide resolved

```mermaid
sequenceDiagram
autonumber
Expand Down Expand Up @@ -274,7 +278,7 @@ sequenceDiagram

C->>P: Calls ExecuteAsync
P->>CB: Calls ExecuteCore
CB->>CB: Rejects request
CB-->>CB: Rejects request
CB->>P: Throws <br/>BrokenCircuitException
P->>C: Propagates exception

Expand Down
4 changes: 3 additions & 1 deletion docs/strategies/fallback.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ sequenceDiagram
P->>F: Calls ExecuteCore
F->>+D: Invokes
D->>-F: Fails
F->>F: Falls back to<br/>substitute result
activate F
F-->>F: Falls back to<br/>substitute result
deactivate F
peter-csala marked this conversation as resolved.
Show resolved Hide resolved
F->>P: Returns <br/>substituted result
P->>C: Returns <br/>substituted result
```
Expand Down
53 changes: 45 additions & 8 deletions docs/strategies/hedging.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ sequenceDiagram

#### Parallel: unhappy path sequence diagram

The hedging strategy triggers because the `Delay` is set to zero. It succeeds because one of the requests succeeds.
The hedging strategy triggers because the `Delay` is set to zero. It fails because all requests fail.

```mermaid
sequenceDiagram
Expand Down Expand Up @@ -323,7 +323,7 @@ new ResiliencePipelineBuilder<HttpResponseMessage>()
{
0 => TimeSpan.FromSeconds(1),
1 => TimeSpan.FromSeconds(2),
_ => System.Threading.Timeout.InfiniteTimeSpan
_ => TimeSpan.FromSeconds(-1)
peter-csala marked this conversation as resolved.
Show resolved Hide resolved
};

return new ValueTask<TimeSpan>(delay);
Expand All @@ -339,7 +339,7 @@ With this configuration, the hedging strategy:

#### Dynamic: happy path sequence diagram

The hedging strategy triggers and switches between modes due to the usage of `DelayGenerator`. It succeeds because the last request succeeds.
The hedging strategy triggers and switches between modes due to our `DelayGenerator`. It succeeds because the last request succeeds.

```mermaid
sequenceDiagram
Expand Down Expand Up @@ -373,13 +373,13 @@ sequenceDiagram
Note over H: Fallback mode

H->>DG: Gets delay
DG->>H: Infinite
DG->>H: -1 second
H->>+HUC: Invokes (R3)
HUC-->>HUC: Processes R3
HUC->>-H: Fails (R3)

H->>DG: Gets delay
DG->>H: Infinite
DG->>H: -1 second
H->>+HUC: Invokes (R4)
HUC-->>HUC: Processes R4
HUC->>-H: Returns result (R4)
Expand All @@ -391,7 +391,7 @@ sequenceDiagram

#### Dynamic: unhappy path sequence diagram

The hedging strategy triggers and switches between modes due to the usage of `DelayGenerator`. It fails because all requests fail.
The hedging strategy triggers and switches between modes due our `DelayGenerator`. It fails because all requests fail.

```mermaid
sequenceDiagram
Expand Down Expand Up @@ -425,13 +425,13 @@ sequenceDiagram
Note over H: Fallback mode

H->>DG: Gets delay
DG->>H: Infinite
DG->>H: -1 second
H->>+HUC: Invokes (R3)
HUC-->>HUC: Processes R3
HUC->>-H: Fails (R3)

H -> DG: Gets delay
DG->>H: Infinite
DG->>H: -1 second
H->>+HUC: Invokes (R4)
HUC-->>HUC: Processes R4
HUC->>-H: Fails (R4)
Expand Down Expand Up @@ -486,6 +486,43 @@ new ResiliencePipelineBuilder<HttpResponseMessage>()
```
<!-- endSnippet -->

### Action generator: sequence diagram

```mermaid
sequenceDiagram
autonumber
actor C as Caller
participant P as Pipeline
participant H as Hedging
participant AG as ActionGenerator
participant UC as UserCallback
participant HUC as HedgedUserCallback

C->>P: Calls ExecuteAsync
P->>H: Calls ExecuteCore

activate H
H->>+UC: Invokes (R1)
UC-->>UC: Processes R1
UC->>-H: Fails (R1)
H->>+AG: Invokes
AG->>-H: Returns factory
H-->>H: Invokes factory

H->>+HUC: Invokes (R2)
HUC-->>HUC: Processes R2
HUC->>-H: Fails (R2)

H-->>H: Invokes factory
H->>+HUC: Invokes (R3)
HUC-->>HUC: Processes R3
HUC->>-H: Returns result (R3)
deactivate H

H->>P: Returns result (R3)
P->>C: Returns result (R3)
```

### Parameterized callbacks and action generator

When you have control over the callbacks that the resilience pipeline receives, you can parameterize them. This flexibility allows for reusing the callbacks within an action generator.
Expand Down
10 changes: 6 additions & 4 deletions docs/strategies/rate-limiter.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Let's suppose we have a rate limiter strategy with `PermitLimit` : `1` and `Wind

```mermaid
sequenceDiagram
autonumber
actor C as Caller
participant P as Pipeline
participant RL as RateLimiter
Expand Down Expand Up @@ -112,6 +113,7 @@ sequenceDiagram

```mermaid
sequenceDiagram
autonumber
actor C as Caller
participant P as Pipeline
participant RL as RateLimiter
Expand All @@ -127,7 +129,7 @@ sequenceDiagram
Note over C: Few seconds later...
C->>P: Calls ExecuteAsync
P->>RL: Calls ExecuteCore
RL->>RL: Rejects request
RL-->>RL: Rejects request
RL->>P: Throws <br/>RateLimiterRejectedException
P->>C: Propagates exception
Note over RL,D: Window end
Expand Down Expand Up @@ -156,7 +158,7 @@ sequenceDiagram
P->>CL: Calls ExecuteCore
CL->>+D: Invokes (C1)
P->>CL: Calls ExecuteCore
CL->>CL: Queues request
CL-->>CL: Queues request

D->>-CL: Returns result (C1)
CL->>P: Returns result (C1)
Expand Down Expand Up @@ -189,9 +191,9 @@ sequenceDiagram
P->>CL: Calls ExecuteCore
CL->>+D: Invokes (C1)
P->>CL: Calls ExecuteCore
CL->>CL: Queues request (C2)
CL-->>CL: Queues request (C2)
P->>CL: Calls ExecuteCore
CL->>CL: Rejects request (C3)
CL-->>CL: Rejects request (C3)
CL->>P: Throws <br/>RateLimiterRejectedException
P->>C3: Propagates exception

Expand Down
6 changes: 3 additions & 3 deletions docs/strategies/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ sequenceDiagram
Note over R,D: Initial attempt
R->>+D: Invokes
D->>-R: Fails
R->>R: Sleeps
R-->>R: Sleeps
Note over R,D: 1st retry attempt
R->>+D: Invokes
D->>-R: Returns result
Expand All @@ -144,11 +144,11 @@ sequenceDiagram
Note over R,D: Initial attempt
R->>+D: Invokes
D->>-R: Fails
R->>R: Sleeps
R-->>R: Sleeps
Note over R,D: 1st retry attempt
R->>+D: Invokes
D->>-R: Fails
R->>R: Sleeps
R-->>R: Sleeps
Note over R,D: 2nd retry attempt
R->>+D: Invokes
D->>-R: Fails
Expand Down
6 changes: 3 additions & 3 deletions docs/strategies/timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ sequenceDiagram
C->>P: Calls ExecuteAsync
P->>T: Calls ExecuteCore
T->>+D: Invokes
D->>D: Performs <br/>long-running <br/>operation
D-->>D: Performs <br/>long-running <br/>operation
D->>-T: Returns result
T->>P: Returns result
P->>C: Returns result
Expand All @@ -112,8 +112,8 @@ sequenceDiagram
T->>+D: Invokes
activate T
activate D
D->>D: Performs <br/>long-running <br/>operation
T->T: Times out
D-->>D: Performs <br/>long-running <br/>operation
T-->>T: Times out
deactivate T
T->>D: Propagates cancellation
deactivate D
Expand Down
2 changes: 1 addition & 1 deletion src/Snippets/Docs/Hedging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void DynamicMode()
{
0 => TimeSpan.FromSeconds(1),
1 => TimeSpan.FromSeconds(2),
_ => System.Threading.Timeout.InfiniteTimeSpan
_ => TimeSpan.FromSeconds(-1)
};

return new ValueTask<TimeSpan>(delay);
Expand Down