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

Load service configs one by one lazily #1099

Merged
merged 8 commits into from
Jul 30, 2019
Merged

Conversation

davidor
Copy link
Contributor

@davidor davidor commented Jul 22, 2019

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.

@davidor davidor requested review from a team as code owners July 22, 2019 14:16
@davidor davidor requested review from a team and removed request for a team July 22, 2019 14:16
CHANGELOG.md Show resolved Hide resolved
doc/parameters.md Outdated Show resolved Hide resolved
doc/parameters.md Outdated Show resolved Hide resolved
Copy link
Contributor

@porueesq porueesq left a 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)
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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 👍

@davidor
Copy link
Contributor Author

davidor commented Jul 24, 2019

@porueesq I added your suggestions here 40f9796

@davidor davidor force-pushed the load-configs-as-they-are-needed branch from 40f9796 to 2001c04 Compare July 25, 2019 10:48
@davidor davidor requested a review from porueesq July 25, 2019 10:49
@davidor davidor force-pushed the load-configs-as-they-are-needed branch from 2001c04 to 2476642 Compare July 25, 2019 13:25
@davidor davidor requested a review from eloycoto July 25, 2019 13:37
@davidor davidor force-pushed the load-configs-as-they-are-needed branch from 2476642 to c66dc53 Compare July 25, 2019 13:56
@davidor davidor force-pushed the load-configs-as-they-are-needed branch from c66dc53 to 26aca49 Compare July 30, 2019 08:39
@davidor
Copy link
Contributor Author

davidor commented Jul 30, 2019

Fixed conflicts in the changelog.

@davidor davidor merged commit 0a3038f into master Jul 30, 2019
@davidor davidor deleted the load-configs-as-they-are-needed branch July 30, 2019 08:46
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.

3 participants