-
Notifications
You must be signed in to change notification settings - Fork 3
Fix: Race between layer and Lambda update (#5927) #7436
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
base: develop
Are you sure you want to change the base?
Fix: Race between layer and Lambda update (#5927) #7436
Conversation
96b44a5 to
716938c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7436 +/- ##
===========================================
- Coverage 85.36% 85.26% -0.10%
===========================================
Files 156 156
Lines 22484 22517 +33
===========================================
+ Hits 19193 19200 +7
- Misses 3291 3317 +26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5e5c308 to
55c8486
Compare
c17cd0b to
f4ce177
Compare
795948a to
525b8b5
Compare
525b8b5 to
cb90aee
Compare
|
Reran reproduction steps #5927 (comment)
|
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 good in general.
Is there a reason behind the fixup! commit? I personally have mix feelings about comments, but if you must use them, you should be as direct and brief as possible to keep it lean. Try to reevaluate your comments and see if they truly add necessary meaning/context in their placement, and if so to ensure they are as informative as they are concise.
src/azul/lambdas.py
Outdated
| # Concurrency settings apply to the function as a whole, | ||
| # including all published versions and the unpublished | ||
| # 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.
| # Concurrency settings apply to the function as a whole, | |
| # including all published versions and the unpublished | |
| # version | |
| # Concurrency settings apply to the function as a whole, | |
| # including all published versions and unpublished |
Or try to minimize the lines, make the comment as concise possible.
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 originally thought the comments would be useful to explain why we specify the Lambda alias in some boto3 calls (e.g. list_event_source_mappings) and not others (e.g. put_function_concurrency), but I agree it's a bit redundant since it's available from boto3's documentation. I will remove.
src/azul/lambdas.py
Outdated
| # You can’t modify the configuration of a published version, | ||
| # only the unpublished 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.
| # You can’t modify the configuration of a published version, | |
| # only the unpublished version | |
| # Configuration modifications allowed only to unpublished version |
The fixup commit was from development, and separated the original design which referenced function versions by the version number, with the fixup commit that implemented function aliases. Now that the alias approach appears viable I've merged the commits. |
8237d18 to
7447335
Compare
| @@ -0,0 +1,45 @@ | |||
| """ | |||
| Delete all published versions of the AWS Lambda function except for the version specified to keep. | |||
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 the versions are ordered, I'd prefer to delete only versions prior to the specified version.
src/azul/lambdas.py
Outdated
|
|
||
| def list_lambdas(self) -> list[Lambda]: | ||
| # Note that this method returns the unpublished "$LATEST" version of | ||
| # Note that this method returns the unpublished version ("$LATEST") of |
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.
This is needlessly touched by two commits.
src/azul/lambdas.py
Outdated
| function_name: str, | ||
| keep_version: str) -> None: | ||
| """ | ||
| Delete all published versions of a Lambda function except for the |
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.
PL, please.
src/azul/lambdas.py
Outdated
| return aws.lambda_ | ||
|
|
||
| def list_lambdas(self) -> list[Lambda]: | ||
| # Note that this method returns the unpublished version ("$LATEST") of |
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.
| # Note that this method returns the unpublished version ("$LATEST") of | |
| # Note that this method returns the $LATEST version which is what Amazon calls the "unpublished version". |
src/azul/lambdas.py
Outdated
| function_name: str, | ||
| keep_version: str) -> None: | ||
| """ | ||
| Delete all published versions of a Lambda function except for the |
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 published versions of a Lambda function except for the | |
| Delete all versions of a Lambda function prior to the specified one. |
src/azul/lambdas.py
Outdated
| function['Version'] | ||
| for page in paginator.paginate(FunctionName=function_name) | ||
| for function in page['Versions'] | ||
| if function['Version'] != '$LATEST' # unpublished 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.
| if function['Version'] != '$LATEST' # unpublished version | |
| if function['Version'] != '$LATEST' # The so-called "unpublished" version |
| 'triggers_replace': ['${aws_lambda_alias.%s.function_version}' % resource_name], | ||
| 'provisioner': { | ||
| 'local-exec': { | ||
| # Script deletes any published version *except* the specified one |
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.
| # Script deletes any published version *except* the specified one |
| # Script deletes any published version *except* the specified one | ||
| 'command': ' '.join([ | ||
| 'python', | ||
| f'{config.project_root}/scripts/delete_other_function_versions.py', |
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.
| f'{config.project_root}/scripts/delete_other_function_versions.py', | |
| f'{config.project_root}/scripts/delete_older_function_versions.py', |
a7b5e09 to
d18c854
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.
You seem to have missed a bunch of earlier comments.
src/azul/lambdas.py
Outdated
| for function in page['Versions'] | ||
| if ( | ||
| function['Version'] != '$LATEST' # The so-called "unpublished" version | ||
| and int(function['Version']) <= int(keep_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.
| and int(function['Version']) <= int(keep_version) | |
| and int(function['Version']) = int(keep_version) |
src/azul/lambdas.py
Outdated
| try: | ||
| versions.remove(keep_version) | ||
| except ValueError: | ||
| assert False, R( | ||
| 'Function version not found', | ||
| function_name, keep_version, versions) |
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.
| try: | |
| versions.remove(keep_version) | |
| except ValueError: | |
| assert False, R( | |
| 'Function version not found', | |
| function_name, keep_version, versions) |
I don't see the point of this.
src/azul/lambdas.py
Outdated
|
|
||
| def delete_older_function_versions(self, | ||
| function_name: str, | ||
| keep_version: str) -> 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.
| keep_version: str) -> None: | |
| keep_version: int) -> None: |
Always convert to the canonical representation as soon as possible, at the perimeter of the system/module/program.
d18c854 to
dc40f0d
Compare
| Delete all versions of a Lambda function prior to the specified one. | ||
| :param function_name: The fully qualified name of the function | ||
| e.g. 'azul-service-dev' |
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.
| e.g. 'azul-service-dev' | |
| e.g. 'azul-service-dev' | |
src/azul/chalice.py
Outdated
| self.metric_alarm(metric=metric, | ||
| threshold=0, | ||
| period=5 * 60) |
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.
| self.metric_alarm(metric=metric, | |
| threshold=0, | |
| period=5 * 60) | |
| self.metric_alarm(metric=metric, threshold=0, period=5 * 60) |
| parser.add_argument('--function-version', '-v', | ||
| type=int, | ||
| required=True, | ||
| help='The Lambda function version to keep') |
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.
| help='The Lambda function version to keep') | |
| help='The Lambda function version to keep. Must be an integer') |
| @@ -0,0 +1,47 @@ | |||
| """ | |||
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.
New scripts and modules should be covered by mypy.
src/azul/queues.py
Outdated
| def _manage_sqs_push(self, function_name: str, queue: 'Queue', enable: bool): | ||
| def _manage_sqs_push(self, | ||
| *, | ||
| function_name: str, |
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.
| function_name: str, | |
| function: str, |
src/azul/lambdas.py
Outdated
| paginator = self._lambda.get_paginator('list_functions') | ||
| lambda_prefixes = [config.qualified_resource_name(lambda_infix) for lambda_infix in config.lambda_names()] | ||
| lambda_prefixes = [ | ||
| config.qualified_resource_name(lambda_infix) | ||
| for lambda_infix in config.lambda_names() | ||
| ] | ||
| assert all(lambda_prefixes) | ||
| for lambda_page in paginator.paginate(FunctionVersion='ALL', MaxItems=500): | ||
| 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(): | ||
| if any(lambda_.name.startswith(prefix) for prefix in lambda_prefixes): | ||
| self.manage_lambda(lambda_.name, enabled) |
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.
This looks like a refactoring, not needed by nor directly related to the other changes of the commit it is in.
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.
Reverted the refactoring, however note that I removed FunctionVersion='ALL' since keeping it would cause the list_functions operation to return multiple versions of each function (e.g. $LATEST and 23), which would then cause manage_lambda to attempt to enable or disable each function more than once.
src/azul/queues.py
Outdated
| submit(self._manage_sqs_push, function, queue, enable) | ||
| submit(self._manage_sqs_push, | ||
| function_name=function, | ||
| alias='active', |
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.
This …
| }, | ||
| 'aws_lambda_alias': { | ||
| resource_name: { | ||
| 'name': 'active', |
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.
… and this are coupled in very brittle way.
dc40f0d to
134898b
Compare
Linked issues: #5927
Checklist
Author
developissues/<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)
ptag to titles of partial commitspartialor completely resolves all linked issuespartiallabelAuthor (reindex)
rtag to commit title or the changes introduced by this PR will not require reindexing of any deploymentreindex:devor the changes introduced by it will not require reindexing ofdevreindex:anvildevor the changes introduced by it will not require reindexing ofanvildevreindex:anvilprodor the changes introduced by it will not require reindexing ofanvilprodreindex:prodor the changes introduced by it will not require reindexing ofprodreindex:partialand its description documents the specific reindexing procedure fordev,anvildev,anvilprodandprodor requires a full reindex or carries none of the labelsreindex:dev,reindex:anvildev,reindex:anvilprodandreindex:prodAuthor (API changes)
APIor 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.pyor this PR does not modify a REST APIAuthor (upgrading deployments)
make docker_images.jsonand committed the resulting changes or this PR does not modifyazul_docker_images, or any other variables referenced in the definition of that variableutag to commit title or this PR does not require upgrading deploymentsupgradeor does not require upgrading deploymentsdeploy:sharedor does not modifydocker_images.json, and does not require deploying thesharedcomponent for any other reasondeploy:gitlabor does not require deploying thegitlabcomponentdeploy:runneror does not require deploying therunnerimageAuthor (hotfixes)
Ftag to main commit title or this PR does not include permanent fix for a temporary hotfixanvilprodandprod) have temporary hotfixes for any of the issues linked to this PRAuthor (before every review)
develop, squashed fixups from prior reviewsmake requirements_updateor this PR does not modifyrequirements*.txt,common.mk,Makefile,Dockerfileorenvironment.bootRtag to commit title or this PR does not modifyrequirements*.txtreqsor does not modifyrequirements*.txtmake integration_testpasses in personal deployment or this PR does not modify functionality that could affect the IT outcomePeer reviewer (after approval)
Note that when requesting changes, the PR must be assigned back to the author.
System administrator (after approval)
demoorno demono demono sandboxN reviewslabel is accurateOperator
reindex:…labels andrcommit title tagno demodevelopOperator (deploy
.sharedand.gitlabcomponents)_select dev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unusedor this PR is not labeleddeploy:shared_select dev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab applyor this PR is not labeleddeploy:gitlab_select anvildev.shared && CI_COMMIT_REF_NAME=develop make -C terraform/shared apply_keep_unusedor this PR is not labeleddeploy:shared_select anvildev.gitlab && CI_COMMIT_REF_NAME=develop make -C terraform/gitlab applyor this PR is not labeleddeploy:gitlabdeploy:gitlabdeploy:gitlabSystem administrator (post-deploy of
.gitlabcomponent)dev.gitlabare complete or this PR is not labeleddeploy:gitlabanvildev.gitlabare complete or this PR is not labeleddeploy:gitlabOperator (deploy runner image)
_select dev.gitlab && make -C terraform/gitlab/runneror this PR is not labeleddeploy:runner_select anvildev.gitlab && make -C terraform/gitlab/runneror this PR is not labeleddeploy:runnerOperator (sandbox build)
sandboxlabel or PR is labeledno sandboxdevor PR is labeledno sandboxanvildevor PR is labeledno sandboxsandboxdeployment or PR is labeledno sandboxanvilboxdeployment or PR is labeledno sandboxsandboxdeployment or PR is labeledno sandboxanvilboxdeployment or PR is labeledno sandboxsandboxor this PR does not remove catalogs or otherwise causes unreferenced indices indevanvilboxor this PR does not remove catalogs or otherwise causes unreferenced indices inanvildevsandboxor this PR is not labeledreindex:devanvilboxor this PR is not labeledreindex:anvildevsandboxor this PR is not labeledreindex:devanvilboxor this PR is not labeledreindex:anvildevOperator (merge the branch)
pif the PR is also labeledpartialOperator (main build)
devanvildevdevdevanvildevanvildev_select dev.shared && make -C terraform/shared applyor this PR is not labeleddeploy:shared_select anvildev.shared && make -C terraform/shared applyor this PR is not labeleddeploy:shareddevanvildevOperator (reindex)
devor this PR is neither labeledreindex:partialnorreindex:devanvildevor this PR is neither labeledreindex:partialnorreindex:anvildevdevor this PR is neither labeledreindex:partialnorreindex:devanvildevor this PR is neither labeledreindex:partialnorreindex:anvildevdevor this PR is neither labeledreindex:partialnorreindex:devanvildevor this PR is neither labeledreindex:partialnorreindex:anvildevdevor this PR does not require reindexingdevanvildevor this PR does not require reindexinganvildevdevor this PR does not require reindexingdevanvildevor this PR does not require reindexinganvildevdevor this PR does not require reindexingdevanvildevor this PR does not require reindexinganvildevdevor this PR does not require reindexingdevdevor this PR does not require reindexingdevdeploy_browserjob in the GitLab pipeline for this PR indevor this PR does not require reindexingdevanvildevor this PR does not require reindexinganvildevdeploy_browserjob in the GitLab pipeline for this PR inanvildevor this PR does not require reindexinganvildevOperator (mirroring)
devor this PR does not require mirroringdevanvildevor this PR does not require mirroringanvildevdevor this PR does not require mirroringdevanvildevor this PR does not require mirroringanvildevdevor this PR does not require mirroringdevanvildevor this PR does not require mirroringanvildevOperator
deploy:shared,deploy:gitlab,deploy:runner,API,reindex:partial,reindex:anvilprodandreindex:prodlabels to the next promotion PRs or this PR carries none of these labelsdeploy:shared,deploy:gitlab,deploy:runner,API,reindex:partial,reindex:anvilprodandreindex:prodlabels, from the description of this PR to that of the next promotion PRs or this PR carries none of these labelsShorthand for review comments
Lline is too longWline wrapping is wrongQbad quotesFother formatting problem