-
Notifications
You must be signed in to change notification settings - Fork 170
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
Load service configs one by one lazily #1099
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions.
end | ||
|
||
local function parse_resp_body(self, resp_body) | ||
local json = cjson.decode(resp_body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be here a call with pcall to make sure that decode works ok if not return an error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Good idea. I also added a test for it.
local proxy_configs = json.proxy_configs or {} | ||
|
||
for i=1, #proxy_configs do | ||
local proxy_config = proxy_configs[i].proxy_config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use an ipairs here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like this before, but I don't see why not use ipairs.
Changed 👍
if self == _M or not self then | ||
local host = environment | ||
local m = _M.new() | ||
local ret, err = m:index(host) | ||
|
||
if not ret then | ||
return m:call() | ||
if load_just_for_host then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not make sense to me to keep the negative condition here, I think that can be something like this:
if ret then
return ret, err
end
if load_just_for_host then
...
I think that makes things more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right. I've simplified this 👍
40f9796
to
2001c04
Compare
2001c04
to
2476642
Compare
2476642
to
c66dc53
Compare
Extracts a couple of methods that return endpoints to make this class easier to understand, and also documents the services() function.
c66dc53
to
26aca49
Compare
Fixed conflicts in the changelog. |
This PR adds the option to add service configurations lazily.
This might be useful for users with many services configured. By default, APIcast loads all the services each time it downloads its configuration from the 3scale admin portal. With a large number of services, this could become problematic.
When this option is enabled, the configurations are loaded lazily. APIcast will only load the ones configured for the host specified in the host header of the request.
The option is not enabled by default. It is enabled using the
APICAST_LOAD_SERVICES_WHEN_NEEDED
env.The PR also includes a couple of commits that clean up a bit the
remote_v2
module used in this PR and also adds some comments.