Change the default route-level timeout of 15 seconds with an HTTPRoute or Gloo Gateway GlooTrafficPolicy. To ensure that your apps are available even if they are temporarily unavailable, you can use timeouts alongside Retries.

Before you begin

  1. Follow the Get started guide to install Gloo Gateway.

  2. Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.

  3. Get the external address of the gateway and save it in an environment variable.

Set up timeouts

Specify timeouts for a specific route.

  1. Configure a timeout for a specific route by using the Kubernetes Gateway API-native configuration in an HTTPRoute or by using Gloo Gateway’s GlooTrafficPolicy. In the following example, you set a timeout of 20 seconds for httpbin’s /headers path. However, no timeout is set along the /anything path.

  2. Send a request to the httpbin app along the /headers path that you configured a custom timeout for. Verify that the request succeeds and that you see a X-Envoy-Expected-Rq-Timeout-Ms header with the custom timeout of 20 seconds (20000).

    Example output for a successful response:

      {
     "headers": {
       "Accept": [
         "*/*"
       ],
       "Host": [
         "www.example.com:8080"
       ],
       "User-Agent": [
         "curl/7.77.0"
       ],
       "X-Envoy-Expected-Rq-Timeout-Ms": [
         "20000"
       ],
       "X-Forwarded-Proto": [
         "http"
       ],
       "X-Request-Id": [
         "0ae53bc3-2644-44f2-8603-158d2ccf9f78"
       ]
     }
    }
      
  3. Send a request to the httpbin app along the anything path that does not have a custom timeout. Verify that the request succeeds and that you see a X-Envoy-Expected-Rq-Timeout-Ms header with the default timeout of 15 seconds (15000).

    Example output for a successful response:

      {
     "headers": {
       "Accept": [
         "*/*"
       ],
       "Host": [
         "www.example.com:8080"
       ],
       "User-Agent": [
         "curl/7.77.0"
       ],
       "X-Envoy-Expected-Rq-Timeout-Ms": [
         "15000"
       ],
       "X-Forwarded-Proto": [
         "http"
       ],
       "X-Request-Id": [
         "0ae53bc3-2644-44f2-8603-158d2ccf9f78"
       ]
     }
    }
      

Cleanup

You can remove the resources that you created in this guide.
  kubectl delete httproute httpbin-timeout -n httpbin
kubectl delete GlooTrafficPolicy timeout -n httpbin