Skip to content

Commit 8f5a96b

Browse files
Merge pull request #266451 from hhunter-ms/hh-196413
[Dapr/ACA] Add circuit breaker policy to Dapr component resiliency
2 parents e566aea + 4fe9d67 commit 8f5a96b

File tree

2 files changed

+70
-6
lines changed

2 files changed

+70
-6
lines changed

articles/container-apps/dapr-component-resiliency.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: container-apps
66
author: hhunter-ms
77
ms.service: container-apps
88
ms.topic: conceptual
9-
ms.date: 12/13/2023
9+
ms.date: 02/22/2024
1010
ms.author: hannahhunter
1111
ms.custom: ignite-fall-2023, ignite-2023, devx-track-azurecli
1212
# Customer Intent: As a developer, I'd like to learn how to make my container apps resilient using Azure Container Apps.
@@ -16,7 +16,7 @@ ms.custom: ignite-fall-2023, ignite-2023, devx-track-azurecli
1616

1717
Resiliency policies proactively prevent, detect, and recover from your container app failures. In this article, you learn how to apply resiliency policies for applications that use Dapr to integrate with different cloud services, like state stores, pub/sub message brokers, secret stores, and more.
1818

19-
You can configure resiliency policies like retries and timeouts for the following outbound and inbound operation directions via a Dapr component:
19+
You can configure resiliency policies like retries, timeouts, and circuit breakers for the following outbound and inbound operation directions via a Dapr component:
2020

2121
- **Outbound operations:** Calls from the Dapr sidecar to a component, such as:
2222
- Persisting or retrieving state
@@ -34,6 +34,7 @@ The following screenshot shows how an application uses a retry policy to attempt
3434

3535
- [Timeouts](#timeouts)
3636
- [Retries (HTTP)](#retries)
37+
- [Circuit breakers](#circuit-breakers)
3738

3839
## Configure resiliency policies
3940

@@ -44,7 +45,7 @@ You can choose whether to create resiliency policies using Bicep, the CLI, or th
4445
The following resiliency example demonstrates all of the available configurations.
4546

4647
```bicep
47-
resource myPolicyDoc 'Microsoft.App/managedEnvironments/daprComponents/resiliencyPolicies@2023-08-01-preview' = {
48+
resource myPolicyDoc 'Microsoft.App/managedEnvironments/daprComponents/resiliencyPolicies@2023-11-02-preview' = {
4849
name: 'my-component-resiliency-policies'
4950
parent: '${componentName}'
5051
properties: {
@@ -58,7 +59,12 @@ resource myPolicyDoc 'Microsoft.App/managedEnvironments/daprComponents/resilienc
5859
initialDelayInMilliseconds: 1000
5960
maxIntervalInMilliseconds: 10000
6061
}
61-
}
62+
}
63+
circuitBreakerPolicy: {
64+
intervalInSeconds: 15
65+
consecutiveErrors: 10
66+
timeoutInSeconds: 5
67+
}
6268
}
6369
inboundPolicy: {
6470
timeoutPolicy: {
@@ -70,7 +76,12 @@ resource myPolicyDoc 'Microsoft.App/managedEnvironments/daprComponents/resilienc
7076
initialDelayInMilliseconds: 1000
7177
maxIntervalInMilliseconds: 10000
7278
}
73-
}
79+
}
80+
circuitBreakerPolicy: {
81+
intervalInSeconds: 15
82+
consecutiveErrors: 10
83+
timeoutInSeconds: 5
84+
}
7485
}
7586
}
7687
}
@@ -125,12 +136,20 @@ outboundPolicy:
125136
maxIntervalInMilliseconds: 10000
126137
timeoutPolicy:
127138
responseTimeoutInSeconds: 15
139+
circuitBreakerPolicy:
140+
intervalInSeconds: 15
141+
consecutiveErrors: 10
142+
timeoutInSeconds: 5
128143
inboundPolicy:
129144
httpRetryPolicy:
130145
maxRetries: 3
131146
retryBackOff:
132147
initialDelayInMilliseconds: 500
133148
maxIntervalInMilliseconds: 5000
149+
circuitBreakerPolicy:
150+
intervalInSeconds: 15
151+
consecutiveErrors: 10
152+
timeoutInSeconds: 5
134153
```
135154
136155
### Update specific policies
@@ -187,6 +206,9 @@ In the resiliency policy pane, select **Outbound** or **Inbound** to set policie
187206

188207
Click **Save** to save the resiliency policies.
189208

209+
> [!NOTE]
210+
> Currently, you can only set timeout and retry policies via the Azure portal.
211+
190212
You can edit or remove the resiliency policies by selecting **Edit resiliency**.
191213

192214
:::image type="content" source="media/dapr-component-resiliency/edit-dapr-component-resiliency.png" alt-text="Screenshot showing how you can edit existing resiliency policies for the applicable Dapr component.":::
@@ -256,6 +278,48 @@ properties: {
256278
| `retryBackOff.initialDelayInMilliseconds` | Yes | Delay between first error and first retry. | `1000` |
257279
| `retryBackOff.maxIntervalInMilliseconds` | Yes | Maximum delay between retries. | `10000` |
258280

281+
### Circuit breakers
282+
283+
Define a `circuitBreakerPolicy` to monitor requests causing elevated failure rates and shut off all traffic to the impacted service when a certain criteria is met.
284+
285+
```bicep
286+
properties: {
287+
outbound: {
288+
circuitBreakerPolicy: {
289+
intervalInSeconds: 15
290+
consecutiveErrors: 10
291+
timeoutInSeconds: 5
292+
}
293+
},
294+
inbound: {
295+
circuitBreakerPolicy: {
296+
intervalInSeconds: 15
297+
consecutiveErrors: 10
298+
timeoutInSeconds: 5
299+
}
300+
}
301+
}
302+
```
303+
304+
| Metadata | Required | Description | Example |
305+
| -------- | --------- | ----------- | ------- |
306+
| `intervalInSeconds` | No | Cyclical period of time (in seconds) used by the circuit breaker to clear its internal counts. If not provided, the interval is set to the same value as provided for `timeoutInSeconds`. | `15` |
307+
| `consecutiveErrors` | Yes | Number of request errors allowed to occur before the circuit trips and opens. | `10` |
308+
| `timeoutInSeconds` | Yes | Time period (in seconds) of open state, directly after failure. | `5` |
309+
310+
#### Circuit breaker process
311+
312+
Specifying `consecutiveErrors` (the circuit trip condition as
313+
`consecutiveFailures > $(consecutiveErrors)-1`) sets the number of errors allowed to occur before the circuit trips and opens halfway.
314+
315+
The circuit waits half-open for the `timeoutInSeconds` amount of time, during which the `consecutiveErrors` number of requests must consecutively succeed.
316+
- _If the requests succeed,_ the circuit closes.
317+
- _If the requests fail,_ the circuit remains in a half-opened state.
318+
319+
If you didn't set any `intervalInSeconds` value, the circuit resets to a closed state after the amount of time you set for `timeoutInSeconds`, regardless of consecutive request success or failure. If you set `intervalInSeconds` to `0`, the circuit never automatically resets, only moving from half-open to closed state by successfully completing `consecutiveErrors` requests in a row.
320+
321+
If you did set an `intervalInSeconds` value, that determines the amount of time before the circuit is reset to closed state, independent of whether the requests sent in half-opened state succeeded or not.
322+
259323
## Resiliency logs
260324

261325
From the *Monitoring* section of your container app, select **Logs**.

articles/container-apps/service-discovery-resiliency.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ When you apply a policy to a container app, the rules are applied to all request
4747
The following resiliency example demonstrates all of the available configurations.
4848

4949
```bicep
50-
resource myPolicyDoc 'Microsoft.App/containerApps/resiliencyPolicies@2023-08-01-preview' = {
50+
resource myPolicyDoc 'Microsoft.App/containerApps/resiliencyPolicies@2023-11-02-preview' = {
5151
name: 'my-app-resiliency-policies'
5252
parent: '${appName}'
5353
properties: {

0 commit comments

Comments
 (0)