updates per Nick review

Signed-off-by: Hannah Hunter <hannahhunter@microsoft.com>
This commit is contained in:
Hannah Hunter 2022-11-16 15:49:55 -06:00
parent 5b7b832bc4
commit 68f8951f74
1 changed files with 59 additions and 64 deletions

View File

@ -1,7 +1,7 @@
--- ---
type: docs type: docs
title: "Quickstart: Service-to-component resiliency" title: "Quickstart: Service-to-component resiliency"
linkTitle: "Resiliency: State Management" linkTitle: "Resiliency: App-to-service"
weight: 110 weight: 110
description: "Get started with Dapr's resiliency capabilities via the state management API" description: "Get started with Dapr's resiliency capabilities via the state management API"
--- ---
@ -13,8 +13,8 @@ description: "Get started with Dapr's resiliency capabilities via the state mana
Observe Dapr resiliency capabilities by simulating a system failure. In this Quickstart, you will: Observe Dapr resiliency capabilities by simulating a system failure. In this Quickstart, you will:
- Execute a microservice application with resiliency enabled that continuously persists and retrieves state via Dapr's state management API. - Execute a microservice application with resiliency enabled that continuously persists and retrieves state via Dapr's state management API.
- Trigger the resiliency spec by simulating a system failure. - Trigger resiliency policies by simulating a system failure.
- Remove the failure to allow the microservice application to resume. - Resolve the failure and the microservice application will resume.
<img src="/images/resiliency-quickstart-svc-component.png" width="1000" alt="Diagram showing the resiliency applied to Dapr APIs"> <img src="/images/resiliency-quickstart-svc-component.png" width="1000" alt="Diagram showing the resiliency applied to Dapr APIs">
@ -56,13 +56,8 @@ pip3 install -r requirements.txt
### Step 2: Run the application with resiliency enabled ### Step 2: Run the application with resiliency enabled
Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. By enabling resiliency, the resiliency spec located in the components directory is loaded by the `order-processor` sidecar. The resilency spec is:
```bash
dapr run --app-id order-processor ../config.yaml --components-path ../../../components/ -- python3
```
The resilency spec is:
- Located in the `components` directory. - Located in the `components` directory.
- Automatically discovered by the Dapr sidecar when run in standalone mode. - Automatically discovered by the Dapr sidecar when run in standalone mode.
@ -95,6 +90,11 @@ The resilency spec is:
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
```bash
dapr run --app-id order-processor ../config.yaml --components-path ../../../components/ -- python3
```
Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}). Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}).
```bash ```bash
@ -110,9 +110,9 @@ Once the application has started, the `order-processor`service writes and reads
### Step 3: Introduce a fault ### Step 3: Introduce a fault
Simulate a fault by stopping the Redis `statestore.yaml` instance that was initalized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the order-processor service begin to fail. Simulate a fault by stopping the Redis container instance that was initialized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the `order-processor` service begin to fail.
Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a target, all failed requests will apply retry and circuit breaker policies: Since the `resiliency.yaml` spec defines the `statestore` as component target, all failed requests will apply retry and circuit breaker policies:
```yaml ```yaml
targets: targets:
@ -123,19 +123,19 @@ Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a ta
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
In a new terminal window, run the following command: In a new terminal window, run the following command to stop Redis:
```bash ```bash
docker stop dapr_redis docker stop dapr_redis
``` ```
Once the first request fails, the retry policy titled `retryForever` is applied: Once Redis is stopped, the requests begin to fail and the retry policy titled `retryForever` is applied. The output shows the logs from the `order-processor` service:
```bash ```bash
INFO[0006] Error processing operation component[statestore] output. Retrying... INFO[0006] Error processing operation component[statestore] output. Retrying...
``` ```
Retries will continue for each failed request indefinitely, in 5 second intervals. As per the `retryFroever` policy, retries will continue for each failed request indefinitely, in 5 second intervals.
```yaml ```yaml
retryForever: retryForever:
@ -228,13 +228,8 @@ npm install
### Step 2: Run the application with resiliency enabled ### Step 2: Run the application with resiliency enabled
Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. By enabling resiliency, the resiliency spec located in the components directory is loaded by the `order-processor` sidecar. The resilency spec is:
```bash
dapr run --app-id order-processor ../config.yaml --components-path ../../../components/ -- npm start
```
The resilency spec is:
- Located in the `components` directory. - Located in the `components` directory.
- Automatically discovered by the Dapr sidecar when run in standalone mode. - Automatically discovered by the Dapr sidecar when run in standalone mode.
@ -267,6 +262,10 @@ The resilency spec is:
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
```bash
dapr run --app-id order-processor ../config.yaml --components-path ../../../components/ -- npm start
```
Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}). Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}).
```bash ```bash
@ -282,9 +281,9 @@ Once the application has started, the `order-processor`service writes and reads
### Step 3: Introduce a fault ### Step 3: Introduce a fault
Simulate a fault by stopping the Redis `statestore.yaml` instance that was initalized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the order-processor service begin to fail. Simulate a fault by stopping the Redis container instance that was initialized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the `order-processor` service begin to fail.
Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a target, all failed requests will apply retry and circuit breaker policies: Since the `resiliency.yaml` spec defines the `statestore` as component target, all failed requests will apply retry and circuit breaker policies:
```yaml ```yaml
targets: targets:
@ -295,19 +294,19 @@ Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a ta
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
In a new terminal window, run the following command: In a new terminal window, run the following command to stop Redis:
```bash ```bash
docker stop dapr_redis docker stop dapr_redis
``` ```
Once the first request fails, the retry policy titled `retryForever` is applied: Once Redis is stopped, the requests begin to fail and the retry policy titled `retryForever` is applied. The output shows the logs from the `order-processor` service:
```bash ```bash
INFO[0006] Error processing operation component[statestore] output. Retrying... INFO[0006] Error processing operation component[statestore] output. Retrying...
``` ```
Retries will continue for each failed request indefinitely, in 5 second intervals. As per the `retryFroever` policy, retries will continue for each failed request indefinitely, in 5 second intervals.
```yaml ```yaml
retryForever: retryForever:
@ -401,13 +400,8 @@ dotnet build
### Step 2: Run the application with resiliency enabled ### Step 2: Run the application with resiliency enabled
Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. By enabling resiliency, the resiliency spec located in the components directory is loaded by the `order-processor` sidecar. The resilency spec is:
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components/ -- dotnet run
```
The resilency spec is:
- Located in the `components` directory. - Located in the `components` directory.
- Automatically discovered by the Dapr sidecar when run in standalone mode. - Automatically discovered by the Dapr sidecar when run in standalone mode.
@ -440,6 +434,10 @@ The resilency spec is:
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components/ -- dotnet run
```
Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}). Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}).
```bash ```bash
@ -455,9 +453,9 @@ Once the application has started, the `order-processor`service writes and reads
### Step 3: Introduce a fault ### Step 3: Introduce a fault
Simulate a fault by stopping the Redis `statestore.yaml` instance that was initalized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the order-processor service begin to fail. Simulate a fault by stopping the Redis container instance that was initialized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the `order-processor` service begin to fail.
Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a target, all failed requests will apply retry and circuit breaker policies: Since the `resiliency.yaml` spec defines the `statestore` as component target, all failed requests will apply retry and circuit breaker policies:
```yaml ```yaml
targets: targets:
@ -468,19 +466,19 @@ Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a ta
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
In a new terminal window, run the following command: In a new terminal window, run the following command to stop Redis:
```bash ```bash
docker stop dapr_redis docker stop dapr_redis
``` ```
Once the first request fails, the retry policy titled `retryForever` is applied: Once Redis is stopped, the requests begin to fail and the retry policy titled `retryForever` is applied. The output shows the logs from the `order-processor` service:
```bash ```bash
INFO[0006] Error processing operation component[statestore] output. Retrying... INFO[0006] Error processing operation component[statestore] output. Retrying...
``` ```
Retries will continue for each failed request indefinitely, in 5 second intervals. As per the `retryFroever` policy, retries will continue for each failed request indefinitely, in 5 second intervals.
```yaml ```yaml
retryForever: retryForever:
@ -576,13 +574,8 @@ mvn clean install
### Step 2: Run the application with resiliency enabled ### Step 2: Run the application with resiliency enabled
Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. By enabling resiliency, the resiliency spec located in the components directory is loaded by the `order-processor` sidecar. The resilency spec is:
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components/ -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar
```
The resilency spec is:
- Located in the `components` directory. - Located in the `components` directory.
- Automatically discovered by the Dapr sidecar when run in standalone mode. - Automatically discovered by the Dapr sidecar when run in standalone mode.
@ -615,6 +608,10 @@ The resilency spec is:
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components/ -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar
```
Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}). Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}).
```bash ```bash
@ -630,9 +627,9 @@ Once the application has started, the `order-processor`service writes and reads
### Step 3: Introduce a fault ### Step 3: Introduce a fault
Simulate a fault by stopping the Redis `statestore.yaml` instance that was initalized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the order-processor service begin to fail. Simulate a fault by stopping the Redis container instance that was initialized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the `order-processor` service begin to fail.
Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a target, all failed requests will apply retry and circuit breaker policies: Since the `resiliency.yaml` spec defines the `statestore` as component target, all failed requests will apply retry and circuit breaker policies:
```yaml ```yaml
targets: targets:
@ -643,19 +640,19 @@ Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a ta
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
In a new terminal window, run the following command: In a new terminal window, run the following command to stop Redis:
```bash ```bash
docker stop dapr_redis docker stop dapr_redis
``` ```
Once the first request fails, the retry policy titled `retryForever` is applied: Once Redis is stopped, the requests begin to fail and the retry policy titled `retryForever` is applied. The output shows the logs from the `order-processor` service:
```bash ```bash
INFO[0006] Error processing operation component[statestore] output. Retrying... INFO[0006] Error processing operation component[statestore] output. Retrying...
``` ```
Retries will continue for each failed request indefinitely, in 5 second intervals. As per the `retryFroever` policy, retries will continue for each failed request indefinitely, in 5 second intervals.
```yaml ```yaml
retryForever: retryForever:
@ -748,13 +745,8 @@ go build .
### Step 2: Run the application with resiliency enabled ### Step 2: Run the application with resiliency enabled
Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. Run the `order-processor` service alongside a Dapr sidecar. In the `dapr run` command below the `--config` parameter applies a Dapr configuration that enables the resiliency feature. By enabling resiliency, the resiliency spec located in the components directory is loaded by the `order-processor` sidecar. The resilency spec is:
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components -- go run .
```
The resilency spec is:
- Located in the `components` directory. - Located in the `components` directory.
- Automatically discovered by the Dapr sidecar when run in standalone mode. - Automatically discovered by the Dapr sidecar when run in standalone mode.
@ -764,7 +756,7 @@ The resilency spec is:
metadata: metadata:
name: myresiliency name: myresiliency
scopes: scopes:
- order-processor - checkout
spec: spec:
policies: policies:
@ -781,13 +773,16 @@ The resilency spec is:
trip: consecutiveFailures >= 5 trip: consecutiveFailures >= 5
targets: targets:
components: apps:
statestore: order-processor:
outbound:
retry: retryForever retry: retryForever
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
```bash
dapr run --app-id order-processor --config ../config.yaml --components-path ../../../components -- go run .
```
Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}). Once the application has started, the `order-processor`service writes and reads `orderId` key/value pairs to the `statestore` Redis instance [defined in the `statestore.yaml` component]({{< ref "statemanagement-quickstart.md#statestoreyaml-component-file" >}}).
```bash ```bash
@ -803,9 +798,9 @@ Once the application has started, the `order-processor`service writes and reads
### Step 3: Introduce a fault ### Step 3: Introduce a fault
Simulate a fault by stopping the Redis `statestore.yaml` instance that was initalized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the order-processor service begin to fail. Simulate a fault by stopping the Redis container instance that was initialized when executing `dapr init` on your development machine. Once the instance is stopped, write and read operations from the `order-processor` service begin to fail.
Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a target, all failed requests will apply retry and circuit breaker policies: Since the `resiliency.yaml` spec defines the `statestore` as component target, all failed requests will apply retry and circuit breaker policies:
```yaml ```yaml
targets: targets:
@ -816,19 +811,19 @@ Since the `resiliency.yaml` spec defines the `statestore.yaml` component as a ta
circuitBreaker: simpleCB circuitBreaker: simpleCB
``` ```
In a new terminal window, run the following command: In a new terminal window, run the following command to stop Redis:
```bash ```bash
docker stop dapr_redis docker stop dapr_redis
``` ```
Once the first request fails, the retry policy titled `retryForever` is applied: Once Redis is stopped, the requests begin to fail and the retry policy titled `retryForever` is applied. The output shows the logs from the `order-processor` service:
```bash ```bash
INFO[0006] Error processing operation component[statestore] output. Retrying... INFO[0006] Error processing operation component[statestore] output. Retrying...
``` ```
Retries will continue for each failed request indefinitely, in 5 second intervals. As per the `retryFroever` policy, retries will continue for each failed request indefinitely, in 5 second intervals.
```yaml ```yaml
retryForever: retryForever: