All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure fault injection

Last Updated:Oct 11, 2023

Fault injection is a testing method that deliberately creates defects in a service to improve fault tolerance, discover client-side bugs, or identify potential faults. Service Mesh supports fault injection. You can use virtual services to conduct fault injection testing at the application layer. This topic describes how to configure fault injection.

Prerequisites

The preparations are completed, and the HTTPBin and sleep services are deployed. For more information, see Preparations.

Procedure

  1. Check whether the service configurations take effect.

    1. Use kubectl to connect to the Container Service for Kubernetes (ACK) cluster based on the information in the kubeconfig file, and run the following command to enable bash for the sleep service:

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -I httpbin:8000

      Expected output:

      HTTP/1.1 200 OK
      server: envoy
      date: Fri, 11 Aug 2023 09:50:24 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: 3
  2. Use the following content to configure a traffic rule for the HTTPBin service and inject faults. For more information, see Manage virtual services.

  3. 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
  4. Check whether the configurations take effect.

    1. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and run the following command to enable bash for the sleep service:

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -w "Total time: %{time_total} seconds\n" -I httpbin:80

      Expected output:

      HTTP/1.1 200 OK
      server: istio-envoy
      date: Sun, 27 Aug 2023 12:41:05 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: 3
      
      Total time: 5.008333 seconds

      The output indicates that the response is delayed for 5 seconds.