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
Allow setting cache loader = boot on staging and never reload the config [THREESCALE-756] #651
Allow setting cache loader = boot on staging and never reload the config [THREESCALE-756] #651
Conversation
deb6ca7
to
75dd839
Compare
local function default_config_cache(options, context, configuration_loader) | ||
local configuration_cache = options.cache or context.configuration_cache | ||
|
||
if not configuration_cache and configuration_loader == 'lazy' 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.
Can't we delegate this to the environment configurations ?
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.
Yes, that's better 👍
388eabd
to
fa4c034
Compare
@@ -110,10 +110,15 @@ local function openresty_binary(candidates) | |||
end | |||
|
|||
local function build_env(options, config, context) | |||
local configuration_cache = options.cache or context.configuration_cache | |||
if configuration_cache then -- Avoid calling tostring() on nil, would return "nil". | |||
configuration_cache = tostring(configuration_cache) |
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.
Maybe it is not necessary to call tostring
here because it is done in the update_env
function?
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.
I think it's needed. The result of this method is not only used in update_env
, it's also used in the call to exec
at the end of mt:__call
.
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.
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.
But nil
keys are being removed from the table, so it won't even get there.
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.
update_env
does not mutate the table that it receives in the params. so if we do not apply tostring
here, it will never be applied before it reaches that exec
.
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.
exec does not call tostring
on the value: https://github.com/3scale/lua-resty-execvp/blob/bfa07e3f82fdd8bfb41be5c152438f03ccd60b9f/src/resty/execvp.lua#L48
and update_env
does: https://github.com/3scale/apicast/blob/30984b947c3abaef6335d5dbb591e0136c07f247/gateway/src/apicast/cli/command/start.lua#L47
that means the values in this table should be either a string
or nil
.
lua tables don't have nil
values, so assigning nil will make the key disappear so it is never iterated by pairs
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.
Not sure I follow. I probably didn't explain this well. Let me try:
build_env
constructs a tablet
and returns it. We're discussing whether we should calltostring
in some values oft
here or not. I think we should.- The table
t
returned in the previous step is sent toupdate_env
. But that function does not mutatet
. t
is sent as a param of the call toexec
. As 2) didn't modify it, it will be sent as we left it in 1). That's why we need to calltostring()
inbuild_env
. Otherwise,exec
might receive a table that contains things that are not strings.
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.
Looks like I was really confused 😄
We are saying the same. This table now needs to contain nil
or string
and that is what you are ensuring.
I think it would be good if we could clean it up by changing the exec
to serialize the env:
https://github.com/3scale/lua-resty-execvp/blob/bfa07e3f82fdd8bfb41be5c152438f03ccd60b9f/src/resty/execvp.lua#L48
Then we don't have to really think about the serialization anymore.
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. I think that fixes the root problem: 3scale/lua-resty-execvp#1
@davidor Can we try to test this? Would blackbox test with env do the trick? |
@mikz : I tried and it didn't work. I've been investigating, and I found that It's read here when it hasn't been set yet: I'll try to fix it. |
@davidor it should be possible to set the |
@mikz It turns out that it was easier than I thought, using |
9fdf001
to
30984b9
Compare
@@ -60,7 +60,7 @@ end | |||
_M.mock = mock_loader.save | |||
|
|||
local function ttl() | |||
return tonumber(env.get('APICAST_CONFIGURATION_CACHE'), 10) | |||
return tonumber(env.get('APICAST_CONFIGURATION_CACHE') or 0, 10) |
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.
env.get
can return empty string, so it should do the or
after tonumber
or use env.value
?
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. Changed 👍
$ENV{APICAST_CONFIGURATION_LOADER} = 'boot'; | ||
$ENV{APICAST_CONFIGURATION_CACHE} = ''; | ||
|
||
filters { configuration => 'fixture=echo.json' }; |
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.
❤️
30984b9
to
72b814a
Compare
The new version of lua-resty-execvp makes sure that tostring() is called in the envs that it receives via params, so we no longer need to worry about it.
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.
Awesome 👍
APIcast crashes when it starts with:
Error msg:
This is because by default, the staging deployment env sets
configuration_cache
to 0, which is incompatible with the 'boot' mode. This PR solves the issue by avoiding setting that default.Ref: https://issues.jboss.org/browse/THREESCALE-756