-
Notifications
You must be signed in to change notification settings - Fork 2
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: Race between layer and Lambda update (#5927) #6259
base: develop
Are you sure you want to change the base?
Fix: Race between layer and Lambda update (#5927) #6259
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6259 +/- ##
===========================================
- Coverage 85.38% 85.35% -0.03%
===========================================
Files 155 155
Lines 20735 20743 +8
===========================================
+ Hits 17704 17706 +2
- Misses 3031 3037 +6 ☔ View full report in Codecov by Sentry. |
1de4271
to
6275fec
Compare
|
It seems AWS keeps an internal counter of the published version of each Lambda, so even if the published version(s) are deleted before the deploy, the next published version will be +1 larger than the last. Since this is the case, there seems no benefit in running the delete prior to the deploy as opposed to after, so I opted for the latter. |
src/azul/terraform.py
Outdated
# race conditions when an update to the function's configuration and | ||
# code rely on the update of each other in order to work correctly. |
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.
# race conditions when an update to the function's configuration and | |
# code rely on the update of each other in order to work correctly. | |
# race conditions when there's a cyclic dependency between an update | |
# to the function's configuration and an update to its code |
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 my way is easier to read, assuming I've correctly parsed the intent here
scripts/delete_lambda_versions.py
Outdated
if version['Version'] == '$LATEST': | ||
pass | ||
else: | ||
version_number = version['Version'] | ||
log.info('Deleting published version %s of %s', version_number, lambda_.name) | ||
aws.lambda_.delete_function( | ||
FunctionName=lambda_.name, | ||
Qualifier=version_number | ||
) |
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.
if version['Version'] == '$LATEST': | |
pass | |
else: | |
version_number = version['Version'] | |
log.info('Deleting published version %s of %s', version_number, lambda_.name) | |
aws.lambda_.delete_function( | |
FunctionName=lambda_.name, | |
Qualifier=version_number | |
) | |
version = version['Version'] | |
if version == '$LATEST': | |
pass | |
else: | |
log.info('Deleting published version %s of %s', version, lambda_.name) | |
aws.lambda_.delete_function( | |
FunctionName=lambda_.name, | |
Qualifier=version | |
) |
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 better to reuse the version
variable instead of introducing a new one (especially since I'm confused about the difference in their names). Also, we can assign to it earlier to avoid repeating the dictionary lookup.
scripts/delete_lambda_versions.py
Outdated
response = aws.lambda_.list_versions_by_function( | ||
FunctionName=lambda_.name | ||
) |
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.
Fits on one line
response = aws.lambda_.list_versions_by_function( | |
FunctionName=lambda_.name | |
) | |
response = aws.lambda_.list_versions_by_function(FunctionName=lambda_.name) |
6275fec
to
e5d5938
Compare
|
e5d5938
to
d126563
Compare
src/azul/lambdas.py
Outdated
return [ | ||
Lambda.from_response(function) | ||
for response in self._lambda.get_paginator('list_functions').paginate() | ||
for function in response['Functions'] | ||
if deployment_only is False or deployment(function) == config.deployment_stage |
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.
if deployment_only is False or deployment(function) == config.deployment_stage | |
if not deployment_only or deployment(function) == config.deployment_stage |
d126563
to
184a0e0
Compare
c04e0bc
to
fd98952
Compare
manage_lambdas.py
manage_queues.py purge_all
|
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 did not ask for any code changes in my previous review, only for additional evidence, yet the code was changed. Was this intentional, and if so, why?
Yes, a fixup commit was added to re-combine the two Background: When I refactored the code out of When testing
This prompted me to take another look at the two |
src/azul/lambdas.py
Outdated
all_versions: bool = False | ||
) -> list[Lambda]: | ||
""" | ||
Return a list of AWS Lambda functions |
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.
Return a list of AWS Lambda functions | |
Return a list of all AWS Lambda functions (or function versions) in the current account, or the given deployment. |
src/azul/lambdas.py
Outdated
for lambda_name in [metadata['FunctionName'] for metadata in lambda_page['Functions']]: | ||
if any(lambda_name.startswith(prefix) for prefix in lambda_prefixes): | ||
self.manage_lambda(lambda_name, enabled) | ||
for lambda_ in self.list_lambdas(deployment=config.deployment_stage): |
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.
for lambda_ in self.list_lambdas(deployment=config.deployment_stage): | |
for function in self.list_lambdas(deployment=config.deployment_stage): |
As noted before, we are phasing this term out. You don't have to remove all usages but just don't add new ones.
src/azul/lambdas.py
Outdated
|
||
def delete_stale_function_versions(self): | ||
""" | ||
Delete all but the latest published version of every AWS Lambda 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.
Delete all but the latest published version of every AWS Lambda function | |
Delete all but the latest published version of every AWS Lambda function |
Can there be more than one published version? If not, "the latest" qualifier seems redundant.
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 there be more than one published version?
Yes, however I was using the term "published" incorrectly. In AWS terminology a published version is a copy of the unpublished ($LATEST) version. There can be many published versions (each with a unique version number), but only one unpublished version.
https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html
In my latest fixup commit I've changed the name and docstring of this method accordingly.
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.
Then I believe either the deletion logic is wrong or the publish
TF functionality doesn't work. One of the published versions must be live so the logic below deletes it, or the latest version is live which raises the question as to why we published an immutable version.
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 might of misunderstood your original question. There can be multiple published versions of a function in the sense that AWS allows it, however with this PR there will only ever be at most one published version, along with the unpublished version.
Both the published and unpublished versions are live, however only the unpublished version is used since our code does not qualify the function ARN with a version. https://docs.aws.amazon.com/lambda/latest/dg/configuration-versions.html#versioning-versions-using
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.
Still don't understand it. Please raise in PL.
src/azul/lambdas.py
Outdated
paginator = self._lambda.get_paginator('list_functions') | ||
lambda_prefixes = [ | ||
config.qualified_resource_name(lambda_infix, stage=deployment) | ||
for lambda_infix in config.lambda_names() |
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.
for lambda_infix in config.lambda_names() | |
for lambda_name in config.lambda_names() |
src/azul/lambdas.py
Outdated
lambda_prefixes = [ | ||
config.qualified_resource_name(lambda_infix, stage=deployment) | ||
for lambda_infix in config.lambda_names() | ||
if deployment is not None |
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.
In larger constructs I see the point of a constant comprehension guard, but here no.
src/azul/lambdas.py
Outdated
for function in response['Functions'] | ||
if deployment is None or any( |
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.
if deployment is None or any( | |
if lambda_prefixes is None or any( |
fd98952
to
d21db43
Compare
src/azul/lambdas.py
Outdated
|
||
def delete_stale_function_versions(self): | ||
""" | ||
Delete all but the latest published version of every AWS Lambda 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.
Then I believe either the deletion logic is wrong or the publish
TF functionality doesn't work. One of the published versions must be live so the logic below deletes it, or the latest version is live which raises the question as to why we published an immutable version.
d21db43
to
2567ecb
Compare
2567ecb
to
0ba2a94
Compare
0ba2a94
to
f612650
Compare
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.
Connected issues: #5927
Checklist
Author
develop
issues/<GitHub handle of author>/<issue#>-<slug>
1 when the issue title describes a problem, the corresponding PR
title is
Fix:
followed by the issue titleAuthor (partiality)
p
tag to titles of partial commitspartial
or completely resolves all connected issuespartial
labelAuthor (chains)
base
or this PR is not chained to another PRchained
or is not chained to another PRAuthor (reindex, API changes)
r
tag to commit title or the changes introduced by this PR will not require reindexing of any deploymentreindex:dev
or the changes introduced by it will not require reindexing ofdev
reindex:anvildev
or the changes introduced by it will not require reindexing ofanvildev
reindex:anvilprod
or the changes introduced by it will not require reindexing ofanvilprod
reindex:prod
or the changes introduced by it will not require reindexing ofprod
reindex:partial
and its description documents the specific reindexing procedure fordev
,anvildev
,anvilprod
andprod
or requires a full reindex or carries none of the labelsreindex:dev
,reindex:anvildev
,reindex:anvilprod
andreindex:prod
API
or this PR does not modify a REST APIa
(A
) tag to commit title for backwards (in)compatible changes or this PR does not modify a REST APIapp.py
or this PR does not modify a REST APIAuthor (upgrading deployments)
make image_manifests.json
and committed the resulting changes or this PR does not modifyazul_docker_images
, or any other variables referenced in the definition of that variableu
tag to commit title or this PR does not require upgrading deploymentsupgrade
or does not require upgrading deploymentsdeploy:shared
or does not modifyimage_manifests.json
, and does not require deploying theshared
component for any other reasondeploy:gitlab
or does not require deploying thegitlab
componentdeploy:runner
or does not require deploying therunner
imageAuthor (hotfixes)
F
tag to main commit title or this PR does not include permanent fix for a temporary hotfixanvilprod
andprod
) have temporary hotfixes for any of the issues connected to this PRAuthor (before every review)
develop
, squashed old fixupsmake requirements_update
or this PR does not modifyrequirements*.txt
,common.mk
,Makefile
andDockerfile
R
tag to commit title or this PR does not modifyrequirements*.txt
reqs
or does not modifyrequirements*.txt
make integration_test
passes in personal deployment or this PR does not modify functionality that could affect the IT outcomePeer reviewer (after approval)
System administrator (after approval)
demo
orno demo
no demo
no sandbox
N reviews
label is accurateOperator (before pushing merge the commit)
reindex:…
labels andr
commit title tagno demo
develop
_select dev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unused
or this PR is not labeleddeploy:shared
_select dev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab apply
or this PR is not labeleddeploy:gitlab
_select anvildev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unused
or this PR is not labeleddeploy:shared
_select anvildev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab apply
or this PR is not labeleddeploy:gitlab
deploy:gitlab
deploy:gitlab
System administrator
dev.gitlab
are complete or this PR is not labeleddeploy:gitlab
anvildev.gitlab
are complete or this PR is not labeleddeploy:gitlab
Operator (before pushing merge the commit)
_select dev.gitlab && make -C terraform/gitlab/runner
or this PR is not labeleddeploy:runner
_select anvildev.gitlab && make -C terraform/gitlab/runner
or this PR is not labeleddeploy:runner
sandbox
label or PR is labeledno sandbox
dev
or PR is labeledno sandbox
anvildev
or PR is labeledno sandbox
sandbox
deployment or PR is labeledno sandbox
anvilbox
deployment or PR is labeledno sandbox
sandbox
deployment or PR is labeledno sandbox
anvilbox
deployment or PR is labeledno sandbox
sandbox
or this PR does not remove catalogs or otherwise causes unreferenced indices indev
anvilbox
or this PR does not remove catalogs or otherwise causes unreferenced indices inanvildev
sandbox
or this PR is not labeledreindex:dev
anvilbox
or this PR is not labeledreindex:anvildev
sandbox
or this PR is not labeledreindex:dev
anvilbox
or this PR is not labeledreindex:anvildev
p
if the PR is also labeledpartial
Operator (chain shortening)
develop
or this PR is not labeledbase
chained
label from the blocked PR or this PR is not labeledbase
base
base
label from this PR or this PR is not labeledbase
Operator (after pushing the merge commit)
dev
anvildev
dev
dev
anvildev
anvildev
_select dev.shared && make -C terraform/shared apply
or this PR is not labeleddeploy:shared
_select anvildev.shared && make -C terraform/shared apply
or this PR is not labeleddeploy:shared
dev
anvildev
Operator (reindex)
dev
or this PR is neither labeledreindex:partial
norreindex:dev
anvildev
or this PR is neither labeledreindex:partial
norreindex:anvildev
dev
or this PR is neither labeledreindex:partial
norreindex:dev
anvildev
or this PR is neither labeledreindex:partial
norreindex:anvildev
dev
or this PR is neither labeledreindex:partial
norreindex:dev
anvildev
or this PR is neither labeledreindex:partial
norreindex:anvildev
dev
or this PR does not require reindexingdev
anvildev
or this PR does not require reindexinganvildev
dev
or this PR does not require reindexingdev
anvildev
or this PR does not require reindexinganvildev
dev
or this PR does not require reindexingdev
anvildev
or this PR does not require reindexinganvildev
Operator
deploy:shared
,deploy:gitlab
,deploy:runner
,reindex:partial
,reindex:anvilprod
andreindex:prod
labels to the next promotion PRs or this PR carries none of these labelsdeploy:shared
,deploy:gitlab
,deploy:runner
,reindex:partial
,reindex:anvilprod
andreindex:prod
labels, from the description of this PR to that of the next promotion PRs or this PR carries none of these labelsShorthand for review comments
L
line is too longW
line wrapping is wrongQ
bad quotesF
other formatting problem