All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure fault injection

Last Updated:Oct 07, 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. 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 then 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: 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
  2. Use the istioctl tool to run the following command to deploy a Layer 7 waypoint proxy for the HTTPBin service:

    istioctl x waypoint apply --service-account httpbin
  3. Use the following content to create a virtual service, configure a traffic rule for the HTTPBin service, and inject faults. 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
  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 then 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: 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

      The output indicates that the response is delayed for 5 seconds and the fault injection is successful.