-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(aws-lambda): Refactor AWS initialization #11534
Conversation
f9dd95c
to
22b9e78
Compare
e644ff9
to
595aabf
Compare
595aabf
to
fb3c7fc
Compare
Hmm, CI seems failing, did a quick test(with adding some logging) and there is some circular loading inside
|
@windmgc Thanks for pointing at this again. I'll need to talk to Thijs to get some input how we can make late initialization of lua-resty-aws possible. It might need to be changed for that. |
fb3c7fc
to
6fcb5a6
Compare
@hanshuebner I found a way to work around this - We need to manually call global aws config before |
@windmgc I have been investigating where we can @Tieske and I discussed this and we're going to fix this by globally replacing the |
@hanshuebner Hmm, If I understand correctly, the reason of the yield is because that |
The problem that we have is that we need to require |
A worker singleton is a worker-global variable that is initialized only once. The get_worker_singleton function is used to access a worker singleton by name. It makes sure that when the variable is not yet initialized and multiple coroutines try to access it, only one calls the initialization functions and other coroutines wait. If get_worker_singleton is called in the init_worker phase, initialization is performed by the first call without locking as there are no other coroutines yet.
2bd5352
to
dea77bd
Compare
The init() function added in ea85db8 was perceived to have too little overall value. It is thus removed.
0817f31
to
fd95058
Compare
Superseded by #11614 |
Summary
#11350 introduced a new plugin callback function
init()
which would be called after plugin schemas had been initialized. The purpose of the function was to provide a hook in the init phase, as that is the only time in which the full process environment is accessible. The AWS Lambda plugin was changed to use this function to initialize the global AWS configuration, which uses a couple of environment variables, as well as initialize the global AWS instance.The instance initialization reaches out to the AWS metadata service using an HTTP request, and as that happened during the initialization of the AWS Lambda plugin (which is enabled by default), the AWS metadata request would be made during Kong startup, even if no AWS Lambda plugin was configured or when not running in AWS. This caused a five second startup delay in most non-AWS environments before the metadata request would time out.
This PR changes the initialization of the global AWS instance so that it is done when the AWS Lambda plugin is first used. This means that the first request making use of AWS Lambda will see an additional delay caused by the initialization, but as the metadata endpoint is always local to the host running Kong, while the Lambda environment might be in a different data center and need to bring up the Lambda function, the additional delay is not significant.
As the
init()
function is no longer needed, it is completely removed again.Supersedes #11528
Checklist
CHANGELOG/unreleased/kong
or addingskip-changelog
label on PR if unnecessary. README.mdFull changelog
1bf074ad18 feat(concurrency): add new get_worker_singleton function
40b2d2a780 refactor(aws-lambda): use worker singleton for AWS instance
af75f1e656 refactor(core): remove plugin init() function
Issue reference
KAG-2551