Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor/resolver] lighter kong.lua #708

Merged
merged 5 commits into from
Nov 10, 2015
Merged

[refactor/resolver] lighter kong.lua #708

merged 5 commits into from
Nov 10, 2015

Conversation

thibaultcha
Copy link
Member

It's been a while I was thinking kong.lua needed a refactor to be better organized. To be properly decoupled it needed a module to load the plugins for a given request, a module to be run manually at given points during a request, and kong.lua orchestrating both.

Changes:

  • resolver is not plugin-like anymore.
  • introduce kong.core: per-context handlers that need to be run before or after given Nginx contexts. It carries information about a request from one context to the next ones using ngx,ctx. Timers, plugins to execute, etc...
  • kong.core.resolver is now ran as part of the before_access handler of kong.core.
  • rename $backend_host and $backend_url to $upstream_host and $upstream_url.
  • plugins can now access the ngx.ctx.upstream_url variable to modify it. kong.core will copy the value to $upstream_url just before the request is proxied,
  • drop the redundant ngx.ctx.stop_phases variable.
  • custom iterator to iterate through plugins in Nginx contexts. This makes kong.lua much lighter.
  • fix: latency headers are now properly included in responses (that was not the case before).
  • fix: fault-tolerant to interrupted contexts. This fixes Kong's interaction with binary nginx access modules #594. I was originally thinking I should check for ngx.status == ngx.OK, but this was not suited for plugin which still want to be executed when previous contexts failed.

Next (TODO):

  • This is also a step towards removing dao and configuration from the globals. Instead, we want them to be allocated in kong.lua and passed along plugins through ngx.ctx (the job of kong.core).

- resolver is not a plugin anymore
- resolver has `before` and `after` methods for each context
- the resolver is responsible for carrying context variables from one
  context to another (using `ngx.ctx`)
- it might be renamed in the future. It does not just do resolving
  anymore.
- fix: now includes latency headers in responses (was missing before)
When a plugin sends a response, it is always through `ngx.exit` which
already exits all phase handlers.
- it handles reports, ctx variables being carried along the request,
resolver execution (to find the correct API to route).
- rename nginx $backend_url to $upstream_url
- rename nginx $backend_host to $upstream_host
- use `ngx.ctx.upstream_url` to store the currenct upstream URL. All
  plguins can stil laccess and modify this value before it is given to
  `ngx.var.upstream_url` for proxy_pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant