All Products
Search
Document Center

Alibaba Cloud Service Mesh:Fault injection

Last Updated:Sep 29, 2026

Fault injection tests how your microservices handle failures before real failures happen. Instead of killing pods or dropping packets at the network layer, Service Mesh (ASM) injects faults at the application layer through VirtualService resources. This produces more targeted results because faults apply to specific HTTP or gRPC requests rather than raw network connections.

Two fault types are available:

  • Delays add latency before forwarding a request. Use delays to verify that timeout and retry policies behave as expected under slow-network conditions.

  • Aborts return an HTTP error code (such as 503) or a gRPC status code without forwarding the request. Use aborts to verify that your application handles upstream failures gracefully.

Both fault types support a percentage field to limit the blast radius to a fraction of traffic.

How it works

  1. A waypoint proxy intercepts traffic destined for the target service at Layer 7.

  2. The VirtualService rules evaluate each request against the fault injection configuration.

  3. Matching requests receive the injected fault -- either a delay before forwarding or an immediate abort with the specified error code.

  4. Non-matching requests pass through unaffected.

Inject a delay fault

This section walks through injecting a 5-second delay into 100% of requests to the HTTPBin service and verifying the result.

Before you begin

Complete the preparation steps and deploy the HTTPBin and sleep services. For details, see Preparations.

Step 1: Confirm that HTTPBin responds without delay

Open a shell in the sleep pod and send a request to the HTTPBin service:

kubectl exec -it deploy/sleep -- sh
curl -I httpbin:8000

Expected output:

HTTP/1.1 200 OK
Server: gunicorn/19.9.0
Date: Mon, 28 Aug 2023 06:15:30 GMT
Connection: keep-alive
Content-Type: text/html; charset=utf-8
Content-Length: 9593
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

The response returns immediately with 200 OK. The Server: gunicorn/19.9.0 header confirms the request reached HTTPBin directly, without passing through a waypoint proxy.

Step 2: Deploy a Layer 7 waypoint proxy

Run the following command to deploy a waypoint proxy for the HTTPBin service account:

istioctl x waypoint apply --service-account httpbin

Step 3: Create a VirtualService with a delay fault

Apply the following VirtualService to inject a 5-second delay into all requests to HTTPBin. For more information, see Manage virtual services.

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: httpbin-vs
  namespace: default
spec:
  hosts:
    - httpbin
  http:
    - fault:
        delay:
          fixedDelay: 5s
          percentage:
            value: 100
      route:
        - destination:
            host: httpbin

Delay fields:

FieldDescriptionExample
fixedDelayDuration to delay each request. Format: 1h, 1m, 1s, 1ms. Must be >= 1 ms.5s
percentage.valuePercentage of requests affected (0--100).100

Step 4: Verify the delay fault

Open a shell in the sleep pod and send the same request again:

kubectl exec -it deploy/sleep -- sh
curl -I httpbin:8000

Expected output:

HTTP/1.1 200 OK
server: istio-envoy
date: Fri, 11 Aug 2023 06:15:26 GMT
content-type: text/html; charset=utf-8
content-length: 9593
access-control-allow-origin: *
access-control-allow-credentials: true
x-envoy-upstream-service-time: 2

Two changes confirm that fault injection is active:

  1. 5-second response time -- The response now takes approximately 5 seconds instead of returning immediately.

  2. server: istio-envoy header -- The Server header changed from gunicorn/19.9.0 to istio-envoy, which confirms the waypoint proxy is processing the request.

Inject an abort fault

To simulate an upstream service crash instead of a delay, replace the delay block with an abort block. The following example returns an HTTP 503 error for 50% of requests to HTTPBin:

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: httpbin-vs
  namespace: default
spec:
  hosts:
    - httpbin
  http:
    - fault:
        abort:
          httpStatus: 503
          percentage:
            value: 50
      route:
        - destination:
            host: httpbin

Abort fields:

FieldDescriptionExample
httpStatusHTTP status code returned to the caller.503
grpcStatusgRPC status code (alternative to httpStatus). Use uppercase string codes such as UNAVAILABLE.UNAVAILABLE
percentage.valuePercentage of requests affected (0--100).50

Target faults to specific requests

By default, fault injection applies to all matching traffic. To limit faults to specific requests (for example, a test user), add a match condition to the VirtualService rule:

http:
  - fault:
      delay:
        fixedDelay: 5s
        percentage:
          value: 100
    match:
      - headers:
          end-user:
            exact: <test-user>
    route:
      - destination:
          host: httpbin

Only requests with the matching header receive the injected fault. Production traffic remains unaffected.

Related topics