Wednesday, July 1, 2020

How to increase a Kong timeout with no down time?

I have a Kong API gateway deployment with several services. The default Kong timeout is set to 1 mins, which fails several of our API requests. Now I want to change them to 10 mins, without going through too much trouble. What should I do? I found this nice tool called Deck, thanks to a blogpost.

The default status of a service configuration
First, install Deck.

Then, we test backup, alter, and restore Kong configurations.

To test, let's create a service definition.
$ curl -i -X POST --url http://localhost:8001/services/ --data 'name=v4' --data 'url=http://172.20.11.223:9099/services/v4'

Check the services via a browser (or a curl command, if you prefer it that way).

http://localhost:8001/services

Notice the timeouts are 60,000. This is 60,000 ms. i.e., 1 min by default. Let's increase it to 10 min, with Deck!

Steps:

1. Dump the configuration:


$ deck dump

This creates a kong.yaml in the current directory.

$ cat kong.yaml
_format_version: "1.1"
services:
- connect_timeout: 60000
  host: 172.20.11.223
  name: v4
  path: /services/v4
  port: 9099
  protocol: http
  read_timeout: 60000
  retries: 5
  write_timeout: 60000



  Modify the connect_timeout, read_timeout, and write_timeout as 600000 (from their default value of 60000) via a text editor.

2.  Check the changes:


  $ deck diff

updating service v4  {
-  "connect_timeout": 60000,
+  "connect_timeout": 600000,
-  "created_at": 1.593636546e+09,
   "host": "172.20.11.223",
   "id": "5c25f92f-d3d0-486f-9a8e-9c406a130501",
   "name": "v4",
   "path": "/services/v4",
   "port": 9099,
   "protocol": "http",
-  "read_timeout": 60000,
+  "read_timeout": 600000,
   "retries": 5,
-  "updated_at": 1.593636546e+09,
-  "write_timeout": 60000
+  "write_timeout": 600000
 }

Summary:
  Created: 0
  Updated: 1
  Deleted: 0


3. Commit the changes:


$ deck sync

Confirm the changes are reflected, from the browser. Yep, it worked. Everything updated with zero downtime.

Timeouts are set to 10 mins (600,000) now, from 1 mins!

No comments:

Post a Comment

You are welcome to provide your opinions in the comments. Spam comments and comments with random links will be deleted.