All Products
Search
Document Center

Alibaba Cloud Service Mesh:Configure a timeout policy

Last Updated:Oct 11, 2023

Service Mesh (ASM) allows you to specify the period of time that an application does not respond before it is considered unhealthy, which is the allowed response latency of requests. This topic describes how to configure a timeout policy.

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 and require the HTTPBin service to delay one second before it sends a response message:

      curl -I httpbin:8000/delay/1

      Expected output:

      HTTP/1.1 200 OK
      server: envoy
      date: Fri, 11 Aug 2023 09:57:36 GMT
      content-type: application/json
      content-length: 481
      access-control-allow-origin: *
      access-control-allow-credentials: true
      x-envoy-upstream-service-time: 1006

      The output indicates that the response is delayed by one second.

    3. Run the following command to send a request to the HTTPBin service and require the HTTPBin service to delay two seconds before it sends a response message:

      curl -I httpbin:8000/delay/2

      Expected output:

      HTTP/1.1 200 OK
      server: envoy
      date: Fri, 11 Aug 2023 09:57:26 GMT
      content-type: application/json
      content-length: 481
      access-control-allow-origin: *
      access-control-allow-credentials: true
      x-envoy-upstream-service-time: 2004

      The output indicates that the response is delayed by two seconds.

  2. Use the following content to create a test scenario, configure a traffic rule for the HTTPBin service, and set the allowed timeout to 2s. 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:
        - route:
            - destination:
                host: httpbin
          timeout: 2s
  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 and configure the HTTPBin service to delay one second before it sends a response message:

      curl -I httpbin:8000/delay/1

      Expected output:

      HTTP/1.1 200 OK
      server: envoy
      date: Fri, 11 Aug 2023 09:56:30 GMT
      content-type: application/json
      content-length: 481
      access-control-allow-origin: *
      access-control-allow-credentials: true
      x-envoy-upstream-service-time: 1005

      The output indicates that the response is delayed by one second.

    3. Run the following command to send a request to the HTTPBin service and configure the HTTPBin service to delay two seconds before it sends a response message:

      curl -I httpbin:8000/delay/2

      Expected output:

      HTTP/1.1 504 Gateway Timeout
      content-length: 24
      content-type: text/plain
      date: Fri, 11 Aug 2023 09:56:35 GMT
      server: envoy

      An HTTP 504 status code is returned, which indicates that the timeout policy takes effect.