We have a custom kong plugin that needs to now support different configurations based on a http header value. There are two approaches to this
- Modify the plugin to support multiple configurations instead of one value right now. It will read the header value and act accordingly
- Define multiple routes with the same path and different header values. Each route is configured with the plugin that has a unique configuration
The advantage of the second approach is clear that we don’t need any code modifications in the plugin and it remains simple. My worry is would it have any effect on kong’s performance.
What is the impact of configuring one plugin at the service level vs multiple plugins for each route? Which of these is most efficient?
Below is a sample config demonstrating the problem
Approach 1
services:
- name: local-leads-app
url: http://localhost:8080/api/leads/v1
routes:
- name: local-leads-app-route
paths:
- /api/leads/v1
strip_path: true
plugins:
- name: custom-rate-limiting
config:
minute: ["x_user_id_v1_50", "x_user_id_v2_100"]
policy: local
Approach 2
services:
- name: local-leads-app
url: http://localhost:8080/api/leads/v1
routes:
- name: local-leads-app-route-1
paths:
- /api/leads/v1
strip_path: true
headers:
x-user-id: [ "v1" ]
plugins:
- name: rate-limiting
config:
minute: 5
policy: local
- name: local-leads-app-route-2
paths:
- /api/leads/v1
strip_path: true
headers:
x-user-id: [ "v2" ]
plugins:
- name: rate-limiting
config:
minute: 100
policy: local
Thanks.