Fault Injection

This task shows how to inject delays and test the resiliency of your application.

Before you begin

  • Setup Istio by following the instructions in the Installation guide.

  • Deploy the BookInfo sample application.

  • Initialize the application version routing by either first doing the request routing task or by running following commands:

    Note: This assumes you don’t have any routes set yet. If you’ve already created conflicting route rules for the sample, you’ll need to use replace rather than create in one or both of the following commands.

    istioctl create -f samples/bookinfo/kube/route-rule-all-v1.yaml
    istioctl create -f samples/bookinfo/kube/route-rule-reviews-test-v2.yaml

Note: This task assumes you are deploying the application on Kubernetes. All of the example commands are using the Kubernetes version of the rule yaml files (e.g., samples/bookinfo/kube/route-rule-all-v1.yaml). If you are running this task in a different environment, change kube to the directory that corresponds to your runtime (e.g., samples/bookinfo/consul/route-rule-all-v1.yaml for the Consul-based runtime).

Fault injection

To test our BookInfo application microservices for resiliency, we will inject a 7s delay between the reviews:v2 and ratings microservices, for user “jason”. Since the reviews:v2 service has a 10s timeout for its calls to the ratings service, we expect the end-to-end flow to continue without any errors.

  1. Create a fault injection rule to delay traffic coming from user “jason” (our test user)

    istioctl create -f samples/bookinfo/kube/route-rule-ratings-test-delay.yaml

    Confirm the rule is created:

    istioctl get routerule ratings-test-delay -o yaml
    apiVersion: config.istio.io/v1alpha2
    kind: RouteRule
      name: ratings-test-delay
      namespace: default
        name: ratings
          fixedDelay: 7.000s
          percent: 100
              regex: ^(.*?;)?(user=jason)(;.*)?$
      precedence: 2
      - labels:
          version: v1

    Allow several seconds to account for rule propagation delay to all pods.

  2. Observe application behavior

    Log in as user “jason”. If the application’s front page was set to correctly handle delays, we expect it to load within approximately 7 seconds. To see the web page response times, open the Developer Tools menu in IE, Chrome or Firefox (typically, key combination Ctrl+Shift+I or Alt+Cmd+I), tab Network, and reload the productpage web page.

    You will see that the webpage loads in about 6 seconds. The reviews section will show Sorry, product reviews are currently unavailable for this book.

Understanding what happened

The reason that the entire reviews service has failed is because our BookInfo application has a bug. The timeout between the productpage and reviews service is less (3s + 1 retry = 6s total) than the timeout between the reviews and ratings service (10s). These kinds of bugs can occur in typical enterprise applications where different teams develop different microservices independently. Istio’s fault injection rules help you identify such anomalies without impacting end users.

Notice that we are restricting the failure impact to user “jason” only. If you login as any other user, you would not experience any delays.

Fixing the bug: At this point we would normally fix the problem by either increasing the productpage timeout or decreasing the reviews to ratings service timeout, terminate and restart the fixed microservice, and then confirm that the productpage returns its response without any errors.

However, we already have this fix running in v3 of the reviews service, so we can simply fix the problem by migrating all traffic to reviews:v3 as described in the traffic shifting task.

(Left as an exercise for the reader - change the delay rule to use a 2.8 second delay and then run it against the v3 version of reviews.)


  • Remove the application routing rules:

    istioctl delete -f samples/bookinfo/kube/route-rule-all-v1.yaml
    istioctl delete -f samples/bookinfo/kube/route-rule-reviews-test-v2.yaml
    istioctl delete -f samples/bookinfo/kube/route-rule-ratings-test-delay.yaml
  • If you are not planning to explore any follow-on tasks, refer to the BookInfo cleanup instructions to shutdown the application.

Further reading