diff --git a/docs/advanced/telemetry.md b/docs/advanced/telemetry.md index 18b7da1ab13..a4a46aadc35 100644 --- a/docs/advanced/telemetry.md +++ b/docs/advanced/telemetry.md @@ -1,6 +1,6 @@ # Telemetry -Starting with version 8, Polly provides telemetry for all built-in resilience strategies. +Starting with version 8, Polly provides telemetry for all built-in standard and chaos resilience strategies. ## Usage @@ -140,14 +140,18 @@ Tags: The `event.name` tag is reported by individual resilience strategies. The built-in strategies report the following events: -- `OnRetry` -- `OnFallback` -- `OnHedging` -- `OnTimeout` -- `OnCircuitClosed` -- `OnCircuitOpened` -- `OnCircuitHalfOpened` -- `OnRateLimiterRejected` +- [`OnRetry`](../strategies/retry.md#telemetry) +- [`OnFallback`](../strategies/fallback.md#telemetry) +- [`OnHedging`](../strategies/hedging.md#telemetry) +- [`OnTimeout`](../strategies/timeout.md#telemetry) +- [`OnCircuitClosed`](../strategies/circuit-breaker.md#telemetry) +- [`OnCircuitOpened`](../strategies/circuit-breaker.md#telemetry) +- [`OnCircuitHalfOpened`](../strategies/circuit-breaker.md#telemetry) +- [`OnRateLimiterRejected`](../strategies/rate-limiter.md#telemetry) +- [`Chaos.OnFault`](../chaos/fault.md#telemetry) +- [`Chaos.OnOutcome`](../chaos/outcome.md#telemetry) +- [`Chaos.OnLatency`](../chaos/latency.md#telemetry) +- [`Chaos.OnBehavior`](../chaos/behavior.md#telemetry) ### Instrument: `resilience.polly.strategy.attempt.duration` diff --git a/docs/chaos/behavior.md b/docs/chaos/behavior.md index 3b16ec0a367..70596013679 100644 --- a/docs/chaos/behavior.md +++ b/docs/chaos/behavior.md @@ -2,13 +2,15 @@ ## About -- **Options**: [`ChaosBehaviorStrategyOptions`](xref:Polly.Simmy.Behavior.ChaosBehaviorStrategyOptions) -- **Extensions**: `AddChaosBehavior` -- **Strategy Type**: Proactive +- **Option(s)**: + - [`ChaosBehaviorStrategyOptions`](xref:Polly.Simmy.Behavior.ChaosBehaviorStrategyOptions) +- **Extension(s)**: + - `AddChaosBehavior` +- **Exception(s)**: - --- -The behavior chaos strategy is designed to inject custom behaviors into system operations right before such an operation is invoked. This strategy is flexible, allowing users to define specific behaviors such as altering the input, simulating resource exhaustion, putting the system in a given state before the actual operation is called, or other operational variations to simulate real-world scenarios. +The behavior **proactive** chaos strategy is designed to inject custom behaviors into system operations right before such an operation is invoked. This strategy is flexible, allowing users to define specific behaviors such as altering the input, simulating resource exhaustion, putting the system in a given state before the actual operation is called, or other operational variations to simulate real-world scenarios. ## Usage @@ -66,10 +68,35 @@ var pipeline = new ResiliencePipelineBuilder() ## Defaults -| Property | Default Value | Description | -|----------------------|---------------|------------------------------------------------| -| `OnBehaviorInjected` | `null` | Action executed when the behavior is injected. | -| `BehaviorGenerator` | `null` | Custom behavior to be injected. | +| Property | Default Value | Description | +|----------------------|---------------|------------------------------------------------------------------------------------------------------------------------------| +| `BehaviorGenerator` | `null` | This required delegate allows you to inject custom behavior by utilizing information that is only available at runtime. | +| `OnBehaviorInjected` | `null` | If provided then it will be invoked after the behavior injection occurred. | + +## Telemetry + +The behavior chaos strategy reports the following telemetry events: + +| Event Name | Event Severity | When? | +|--------------------|----------------|------------------------------------------------------------------| +| `Chaos.OnBehavior` | `Information` | Just before the strategy calls the `OnBehaviorInjected` delegate | + +Here are some sample events: + +```none +Resilience event occurred. EventName: 'Chaos.OnBehavior', Source: '(null)/(null)/Chaos.Behavior', Operation Key: '', Result: '' + +Resilience event occurred. EventName: 'Chaos.OnBehavior', Source: 'MyPipeline/MyPipelineInstance/MyChaosBehaviorStrategy', Operation Key: 'MyBehaviorInjectedOperation', Result: '' +``` + +> [!NOTE] +> Please note that the `Chaos.OnBehavior` telemetry event will be reported **only if** the behavior chaos strategy injects a custom behavior which does not throw exception. +> +> So, if the behavior is either not injected or injected and throws an exception then there will be no telemetry emitted. +> +> Also remember that the `Result` will be **always empty** for the `Chaos.OnBehavior` telemetry event. + +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/chaos/fault.md b/docs/chaos/fault.md index d29dbd9c942..bc47b63ca94 100644 --- a/docs/chaos/fault.md +++ b/docs/chaos/fault.md @@ -2,13 +2,15 @@ ## About -- **Options**: [`ChaosFaultStrategyOptions`](xref:Polly.Simmy.Fault.ChaosFaultStrategyOptions) -- **Extensions**: `AddChaosFault` -- **Strategy Type**: Proactive +- **Option(s)**: + - [`ChaosFaultStrategyOptions`](xref:Polly.Simmy.Fault.ChaosFaultStrategyOptions) +- **Extensions**: + - `AddChaosFault` +- **Exception(s)**: - --- -The fault chaos strategy is designed to introduce faults (exceptions) into the system, simulating real-world scenarios where operations might fail unexpectedly. It is configurable to inject specific types of exceptions or use custom logic to generate faults dynamically. +The fault **proactive** chaos strategy is designed to introduce faults (exceptions) into the system, simulating real-world scenarios where operations might fail unexpectedly. It is configurable to inject specific types of exceptions or use custom logic to generate faults dynamically. ## Usage @@ -87,10 +89,35 @@ var pipeline = new ResiliencePipelineBuilder() ## Defaults -| Property | Default Value | Description | -|-------------------|---------------|------------------------------------------------------| -| `OnFaultInjected` | `null` | Action executed when the fault is injected. | -| `FaultGenerator` | `null` | Generates the fault to inject for a given execution. | +| Property | Default Value | Description | +|-------------------|---------------|------------------------------------------------------------------------------------------------------------------------| +| `FaultGenerator` | `null` | This required delegate allows you to inject exception by utilizing information that is only available at runtime. | +| `OnFaultInjected` | `null` | If provided then it will be invoked after the fault injection occurred. | + +## Telemetry + +The fault chaos strategy reports the following telemetry events: + +| Event Name | Event Severity | When? | +|-----------------|----------------|---------------------------------------------------------------| +| `Chaos.OnFault` | `Information` | Just before the strategy calls the `OnFaultInjected` delegate | + +Here are some sample events: + +```none +Resilience event occurred. EventName: 'Chaos.OnFault', Source: '(null)/(null)/Chaos.Fault', Operation Key: '', Result: '' + +Resilience event occurred. EventName: 'Chaos.OnFault', Source: 'MyPipeline/MyPipelineInstance/MyChaosFaultStrategy', Operation Key: 'MyFaultInjectedOperation', Result: '' +``` + +> [!NOTE] +> Please note that the `Chaos.OnFault` telemetry event will be reported **only if** the fault chaos strategy injects an exception which is wrapped into a `ValueTask`. +> +> So, if the fault is either not injected or injected and throws an exception then there will be no telemetry emitted. +> +> Also remember that the `Result` will be **always empty** for the `Chaos.OnFault` telemetry event. + +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/chaos/index.md b/docs/chaos/index.md index 85e098cd3e0..9112406bf6f 100644 --- a/docs/chaos/index.md +++ b/docs/chaos/index.md @@ -52,10 +52,14 @@ This section highlights the major differences compared to the [`Polly.Contrib.Si - **Unified configuration options**: The `InjectOptionsBase` and `InjectOptionsAsyncBase` are now consolidated into `ChaosStrategyOptions`. This change brings Simmy in line with the Polly v8 API, offering built-in support for options-based configuration and seamless integration of synchronous and asynchronous executions. - **Chaos strategies enabled by default**: Adding a chaos strategy (previously known as monkey policy) now means it's active right away. This is a departure from earlier versions, where the monkey policy had to be explicitly enabled. - **API changes**: The new version of Simmy introduces several API updates. While this list isn't complete, it includes key changes like renaming `Inject` to `AddChaos` and switching from `Result` to `Outcome`. Here are some specific renames: - - `InjectException` is now `AddChaosFault` - - `InjectResult` is now `AddChaosOutcome` - - `InjectBehavior` is now `AddChaosBehavior` - - `InjectLatency` is now `AddChaosLatency` + +| From | To | +|-------------------|--------------------| +| `InjectException` | `AddChaosFault` | +| `InjectResult` | `AddChaosOutcome` | +| `InjectBehavior` | `AddChaosBehavior` | +| `InjectLatency` | `AddChaosLatency` | + - **Sync and async unification**: Before, Simmy had various methods to set policies like `InjectLatency`, `InjectLatencyAsync`, `InjectLatency`, and `InjectLatencyAsync`. With the new version based on Polly v8, these methods have been combined into a single `AddChaosLatency` extension that works for both `ResiliencePipelineBuilder` and `ResiliencePipelineBuilder`. These rules are covering all types of chaos strategies (Outcome, Fault, Latency, and Behavior). ## Motivation @@ -82,12 +86,12 @@ Chaos strategies (formerly known as Monkey strategies) are in essence a [Resilie ### Built-in strategies -| Strategy | Reactive | What does the strategy do? | -|-------------------------|----------|----------------------------------------------------------------------| -| [Fault](fault.md) | No | Injects exceptions in your system. | -| [Outcome](outcome.md) | Yes | Injects fake outcomes (results or exceptions) in your system. | -| [Latency](latency.md) | No | Injects latency into executions before the calls are made. | -| [Behavior](behavior.md) | No | Allows you to inject *any* extra behavior, before a call is placed. | +| Strategy | Type | What does the strategy do? | +|-------------------------|-----------|---------------------------------------------------------------------| +| [Fault](fault.md) | Proactive | Injects exceptions in your system. | +| [Outcome](outcome.md) | Reactive | Injects fake outcomes (results or exceptions) in your system. | +| [Latency](latency.md) | Proactive | Injects latency into executions before the calls are made. | +| [Behavior](behavior.md) | Proactive | Allows you to inject *any* extra behavior, before a call is placed. | ## Common options across strategies @@ -114,12 +118,12 @@ All the strategies' options implement the [`ChaosStrategyOptions`](xref:Polly.Si ## Telemetry -The telemetry of chaos strategies is seamlessly integrated with Polly [telemetry infrastructure](../advanced/telemetry.md). The chaos strategies produce the following events: +The telemetry of chaos strategies is seamlessly integrated with Polly [telemetry infrastructure](../advanced/telemetry.md). The chaos strategies produce the following information events: -- `Chaos.OnFault` -- `Chaos.OnOutcome` -- `Chaos.OnLatency` -- `Chaos.OnBehavior` +- [`Chaos.OnFault`](fault.md#telemetry) +- [`Chaos.OnOutcome`](outcome.md#telemetry) +- [`Chaos.OnLatency`](latency.md#telemetry) +- [`Chaos.OnBehavior`](behavior.md#telemetry) ## Patterns diff --git a/docs/chaos/latency.md b/docs/chaos/latency.md index fc22f7fab57..d732001e889 100644 --- a/docs/chaos/latency.md +++ b/docs/chaos/latency.md @@ -2,13 +2,15 @@ ## About -- **Options**: [`ChaosLatencyStrategyOptions`](xref:Polly.Simmy.Latency.ChaosLatencyStrategyOptions) -- **Extensions**: `AddChaosLatency` -- **Strategy Type**: Proactive +- **Option(s)**: + - [`ChaosLatencyStrategyOptions`](xref:Polly.Simmy.Latency.ChaosLatencyStrategyOptions) +- **Extension(s)**: + - `AddChaosLatency` +- **Exception(s)**: - --- -The latency chaos strategy is designed to introduce controlled delays into system operations, simulating network latency or slow processing times. This strategy helps in assessing and improving the resilience of applications against increased response times. +The latency **proactive** chaos strategy is designed to introduce controlled delays into system operations, simulating network latency or slow processing times. This strategy helps in assessing and improving the resilience of applications against increased response times. ## Usage @@ -90,15 +92,45 @@ var pipeline = new ResiliencePipelineBuilder() ## Defaults -| Property | Default Value | Description | -|---------------------|---------------|--------------------------------------------------------| -| `Latency` | `30 seconds` | A `TimeSpan` indicating the delay to be injected. | -| `LatencyGenerator` | `null` | Generates the latency to inject for a given execution. | -| `OnLatencyInjected` | `null` | Action executed when latency is injected. | +| Property | Default Value | Description | +|---------------------|---------------|----------------------------------------------------------------------------------------------------------------------| +| `Latency` | 30 seconds | Defines a **fixed** delay to be injected. | +| `LatencyGenerator` | `null` | This delegate allows you to **dynamically** inject delay by utilizing information that is only available at runtime. | +| `OnLatencyInjected` | `null` | If provided then it will be invoked after the latency injection occurred. | > [!NOTE] > If both `Latency` and `LatencyGenerator` are specified then `Latency` will be ignored. +--- + +> [!IMPORTANT] +> Please note that if the calculated latency is negative (regardless if it's fixed or dynamic) then it will not be injected. + +## Telemetry + +The latency chaos strategy reports the following telemetry events: + +| Event Name | Event Severity | When? | +|-------------------|----------------|-----------------------------------------------------------------| +| `Chaos.OnLatency` | `Information` | Just before the strategy calls the `OnLatencyInjected` delegate | + +Here are some sample events: + +```none +Resilience event occurred. EventName: 'Chaos.OnLatency', Source: '(null)/(null)/Chaos.Latency', Operation Key: '', Result: '' + +Resilience event occurred. EventName: 'Chaos.OnLatency', Source: 'MyPipeline/MyPipelineInstance/MyLatencyStrategy', Operation Key: 'MyLatencyInjectedOperation', Result: '' +``` + +> [!NOTE] +> Please note that the `Chaos.OnLatency` telemetry event will be reported **only if** the latency chaos strategy injects a positive delay. +> +> So, if the latency is not injected then there will be no telemetry emitted. Also if injected but the latency is negative or the `LatencyGenerator` throws an exception then there will be no telemetry emitted. +> +> Also remember that the `Result` will be **always empty** for the `Chaos.OnLatency` telemetry event. + +For further information please check out the [telemetry page](../advanced/telemetry.md). + ## Diagrams ### Normal 🐵 sequence diagram diff --git a/docs/chaos/outcome.md b/docs/chaos/outcome.md index ed21508877a..410b06ea564 100644 --- a/docs/chaos/outcome.md +++ b/docs/chaos/outcome.md @@ -2,14 +2,15 @@ ## About -- **Options**: +- **Option(s)**: - [`ChaosOutcomeStrategyOptions`](xref:Polly.Simmy.Outcomes.ChaosOutcomeStrategyOptions`1) -- **Extensions**: `AddChaosOutcome` -- **Strategy Type**: Reactive +- **Extension(s)**: + - `AddChaosOutcome` +- **Exception(s)**: - --- -The outcome chaos strategy is designed to inject or substitute fake results into system operations. This allows testing how an application behaves when it receives different types of responses, like successful results, errors, or exceptions. +The outcome **reactive** chaos strategy is designed to inject or substitute fake results into system operations. This allows testing how an application behaves when it receives different types of responses, like successful results, errors, or exceptions. ## Usage @@ -79,10 +80,38 @@ var pipeline = new ResiliencePipelineBuilder() ## Defaults -| Property | Default Value | Description | -|---------------------|---------------|---------------------------------------------------------| -| `OutcomeGenerator` | `null` | Function to generate the outcome for a given execution. | -| `OnOutcomeInjected` | `null` | Action executed when the outcome is injected. | +| Property | Default Value | Description | +|---------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------| +| `OutcomeGenerator` | `null` | This required delegate allows you to inject custom outcome by utilizing information that is only available at runtime. | +| `OnOutcomeInjected` | `null` | If provided then it will be invoked after the outcome injection occurred. | + +> [!NOTE] +> Please note this strategy is a reactive chaos strategy, but it does not have a `ShouldHandle` delegate. + +## Telemetry + +The outcome chaos strategy reports the following telemetry events: + +| Event Name | Event Severity | When? | +|-------------------|----------------|-----------------------------------------------------------------| +| `Chaos.OnOutcome` | `Information` | Just before the strategy calls the `OnOutcomeInjected` delegate | + +Here are some sample events: + +```none +Resilience event occurred. EventName: 'Chaos.OnOutcome', Source: '(null)/(null)/Chaos.Outcome', Operation Key: '', Result: '' + +Resilience event occurred. EventName: 'Chaos.OnOutcome', Source: 'MyPipeline/MyPipelineInstance/MyOutcomeStrategy', Operation Key: 'MyOutcomeInjectedOperation', Result: '' +``` + +> [!NOTE] +> Please note that the `Chaos.OnOutcome` telemetry event will be reported **only if** the outcome chaos strategy injects an outcome object. +> +> So, if the outcome is not injected or injected but the generator delegate throws an exception then there will be no telemetry emitted. +> +> Also remember that the `Result` will be **always empty** for the `Chaos.OnOutcome` telemetry event. + +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/strategies/circuit-breaker.md b/docs/strategies/circuit-breaker.md index fdd85fe78dc..4a2bef29d6d 100644 --- a/docs/strategies/circuit-breaker.md +++ b/docs/strategies/circuit-breaker.md @@ -100,7 +100,7 @@ new ResiliencePipelineBuilder().AddCircuitBreaker(optionsSt | `FailureRatio` | 0.1 | The failure-success ratio that will cause the circuit to break/open. `0.1` means 10% failed of all sampled executions. | | `MinimumThroughput` | 100 | The minimum number of executions that must occur within the specified sampling duration. | | `SamplingDuration` | 30 seconds | The time period over which the failure-success ratio is calculated. | -| `BreakDuration` | 5 seconds | Defines a **static** time period for which the circuit will remain broken/open before attempting to reset. | +| `BreakDuration` | 5 seconds | Defines a **fixed** time period for which the circuit will remain broken/open before attempting to reset. | | `BreakDurationGenerator` | `null` | This delegate allows you to **dynamically** calculate the break duration by utilizing information that is only available at runtime (like failure count). | | `ManualControl` | `null` | If provided then the circuit's state can be manually controlled via a `CircuitBreakerManualControl` object. | | `StateProvider` | `null` | If provided then the circuit's current state can be retrieved via a `CircuitBreakerStateProvider` object. | @@ -148,7 +148,7 @@ Resilience event occurred. EventName: 'OnCircuitClosed', Source: 'MyPipeline/MyP > > Also the `Result` will be **always empty** for the `OnCircuitHalfOpened` telemetry event. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/strategies/fallback.md b/docs/strategies/fallback.md index c77bd0ad173..c5c4012ac5c 100644 --- a/docs/strategies/fallback.md +++ b/docs/strategies/fallback.md @@ -99,7 +99,7 @@ Resilience event occurred. EventName: 'OnFallback', Source: '(null)/(null)/Fallb > > Also remember that the `Result` will be **always populated** for the `OnFallback` telemetry event. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index 4ed172c4ec5..e64e1641dbf 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -113,7 +113,7 @@ Execution attempt. Source: 'MyPipeline/MyPipelineInstance/Hedging', Operation Ke > > Also remember that `Attempt: '0'` relates to the original execution attempt. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Concurrency modes diff --git a/docs/strategies/rate-limiter.md b/docs/strategies/rate-limiter.md index 9d720c970e1..74ef5e4678b 100644 --- a/docs/strategies/rate-limiter.md +++ b/docs/strategies/rate-limiter.md @@ -154,7 +154,7 @@ Resilience event occurred. EventName: 'OnRateLimiterRejected', Source: 'MyPipeli > > Also remember that the `Result` will be **always empty** for the `OnRateLimiterRejected` telemetry event. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams diff --git a/docs/strategies/retry.md b/docs/strategies/retry.md index 08b6f9cc987..4b4bc349fa3 100644 --- a/docs/strategies/retry.md +++ b/docs/strategies/retry.md @@ -168,7 +168,7 @@ Execution attempt. Source: 'MyPipeline/MyPipelineInstance/MyRetryStrategy', Oper > > Also remember that `Attempt: '0'` relates to the original execution attempt. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Calculation of the next delay diff --git a/docs/strategies/timeout.md b/docs/strategies/timeout.md index a39f49c2a6a..54897c4486a 100644 --- a/docs/strategies/timeout.md +++ b/docs/strategies/timeout.md @@ -113,7 +113,7 @@ catch (TimeoutRejectedException) | Property | Default Value | Description | |--------------------|---------------|--------------------------------------------------------------------------------------------------------------------------------------| -| `Timeout` | 30 seconds | Defines a **static** period within which the delegate should complete, otherwise it will be cancelled. | +| `Timeout` | 30 seconds | Defines a **fixed** period within which the delegate should complete, otherwise it will be cancelled. | | `TimeoutGenerator` | `null` | This delegate allows you to **dynamically** calculate the timeout period by utilizing information that is only available at runtime. | | `OnTimeout` | `null` | If provided then it will be invoked after the timeout occurred. | @@ -153,7 +153,7 @@ Resilience event occurred. EventName: 'OnTimeout', Source: 'MyPipeline/MyPipelin > > Also remember that the `Result` will be **always empty** for the `OnTimeout` telemetry event. -For further information please check out the [telemetry page](https://www.pollydocs.org/advanced/telemetry). +For further information please check out the [telemetry page](../advanced/telemetry.md). ## Diagrams