How will kong know which plugin to execute when a request comes at the kong node?

3.1k Views Asked by At

I was working with kong then wanted to understand how will kong know which plugin to execute for a request that has just arrived at the gateway.

Let's say we have configured rate limit plugin on a service entity and has a route associated with it how will kong now know it has to execute rate limit plugin when a request comes on that route.

Is it based on the plugin configuration? If so does kong pull in this details from the Database

Please explain the mechanism of plugin execution.

PS: I'm aware of the execution order but not how kong decides which plugin to execute.

1

There are 1 best solutions below

0
On

Not sure to understand what you are looking for.

Of course this is based on the plugin configuration. The configuration of the plugins is stored as your kong configuration, you can configure it to be in memory or in database, see datastore section for more details

If you have question when you have several plugins, the plugins have a hardcoded priority to know the order of execution, see plugins order

If you question is which plugins will be executed, the Plugins can be configured for various entities, combination of entities, or even globally.

A plugin will always be run once and only once per request. But the configuration with which it will run depends on the entities it has been configured for. The more specific a plugin is with regards to how many entities it has been configured on, the higher its priority, you can get more details about precedence

Example: if the rate-limiting plugin is applied twice (with different configurations): for a Service (Plugin config A), and for a Consumer (Plugin config B), then requests authenticating this Consumer will run Plugin config B and ignore A. However, requests that do not authenticate this Consumer will fallback to running Plugin config A. Note that if config B is disabled (its enabled flag is set to false), config A will apply to requests that would have otherwise matched config B.