Inject faults in a percentage of your requests to test how your app handles the errors. By using the policy, you can avoid deleting pods, delaying packets, or corrupting packets.

You can set two types of faults injection:

  • Delays: Delays are timing failures, such as network latency or overloaded upstreams.
  • Aborts: Aborts are crash failures, such as HTTP error codes or TCP connection failures.

For more information, see the following resources.

Before you begin

  1. Complete the multicluster getting started guide to set up the following testing environment.

    • Three clusters along with environment variables for the clusters and their Kubernetes contexts.
    • The Gloo meshctl CLI, along with other CLI tools such as kubectl and istioctl.
    • The Gloo management server in the management cluster, and the Gloo agents in the workload clusters.
    • Istio installed in the workload clusters.
    • A simple Gloo workspace setup.
  2. Install Bookinfo and other sample apps.

Configure fault injection policies

You can apply a fault injection policy at the route level. For more information, see Applying policies.

Review the following sample configuration files.

Verify fault injection policies

  1. Create the example fault injection policy for the ratings app.
      kubectl apply --context ${REMOTE_CONTEXT1} -f - << EOF
    kind: FaultInjectionPolicy
      annotations: ""
      name: faultinjection-basic
      namespace: bookinfo
      - route:
            route: ratings
          httpStatus: 418
  2. Create a route table for the ratings app. Because the policy applies at the route level, Gloo checks for the route in a route table resource.

      kubectl apply --context ${REMOTE_CONTEXT1} -f - << EOF
    kind: RouteTable
      name: ratings-rt
      namespace: bookinfo
      - ratings
      - forwardTo:
          - ref:
              name: ratings
              namespace: bookinfo
          route: ratings
      - {}

    Review the following table to understand this configuration. For more information, see the API docs.

    hostsThe host that the route table routes traffic for. In this example, the ratings host matches the ratings service within the mesh.
    http.forwardTo.destinationsThe destination to forward requests that come in along the host route. In this example, the ratings service is selected.
    http.labelsThe label for the route. This label must match the label that the policy selects.
    workloadSelectorsThe source workloads within the mesh that this route table routes traffic for. In the example, all workloads are selected. This way, the curl container that you create in subsequent steps can send a request along the ratings route.
  3. Send a request to the ratings app from within the mesh.
  4. Verify that you notice the fault from the previous examples.
    • Abort: All inbound requests to the ratings service result in a 418 Unknown HTTP status code.
    • Delay: All inbound requests to the ratings service have a five second delay.
    • Both abort and delay: 10% of the calls return 418 Unknown HTTP status code responses, and 40% have a five second delay before they send a response.
  5. Optional: Clean up the resources that you created.
      kubectl --context $REMOTE_CONTEXT1 -n bookinfo delete routetable ratings-rt
    kubectl --context $REMOTE_CONTEXT1 -n bookinfo delete faultinjectionpolicy faultinjection-basic