8000 APIGW: add Canary Deployment logic in invocation layer by bentsku · Pull Request #12695 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

APIGW: add Canary Deployment logic in invocation layer #12695

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

Merged
merged 3 commits into from
Jun 3, 2025

Conversation

bentsku
Copy link
Contributor
@bentsku bentsku commented May 31, 2025

Motivation

Follow-up from #12694

This is the actual implementation of canary dispatching between deployments.

Not a lot to add, the code is pretty descriptive. I wasn't sure where to add the logic to "select" a canary deployment, but I think getting this in the router somewhat makes sense, as it is where we are deciding which deployment to use. One of the limitation is that we only know the account id and region from the active deployment itself.

We could also add a handler first in the chain to fetch the stage config and overwrite the deployment?

Also added a small fix in UpdateIntegrationResponse, this will be a good revamp at some point 😅

\cc @HarshCasper, I know you've been wanting this for a long time now!

Changes

  • enable the test
  • implement the logic in the invocation layer, adding some fields in the context to support the use case

@bentsku bentsku added this to the 4.5 8000 milestone May 31, 2025
@bentsku bentsku self-assigned this May 31, 2025
@bentsku bentsku added aws:apigateway Amazon API Gateway semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels May 31, 2025
@bentsku bentsku changed the title Apigw canary logic APIGW: add Canary Deployment logic in invocation layer May 31, 2025
Copy link
github-actions bot commented May 31, 2025

Test Results - Preflight, Unit

21 593 tests  ±0   19 938 ✅ ±0   6m 33s ⏱️ -7s
     1 suites ±0    1 655 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 1239e1b. ± Comparison against base commit 374183c.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 31, 2025

LocalStack Community integration with Pro

    2 files      2 suites   18m 24s ⏱️
1 134 tests 1 069 ✅ 65 💤 0 ❌
1 136 runs  1 069 ✅ 67 💤 0 ❌

Results for commit 1239e1b.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 31, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 6s ⏱️ -8s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 1239e1b. ± Comparison against base commit 374183c.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 31, 2025

Test Results - Alternative Providers

977 tests   547 ✅  21m 46s ⏱️
  4 suites  430 💤
  4 files      0 ❌

Results for commit 1239e1b.

♻️ This comment has been updated with latest results.

Copy link
github-actions bot commented May 31, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   2h 21m 34s ⏱️
5 215 tests 4 296 ✅ 919 💤 0 ❌
5 221 runs  4 296 ✅ 925 💤 0 ❌

Results for commit 1239e1b.

♻️ This comment has been updated with latest results.

Base automatically changed from apigw-canary-crud to master June 2, 2025 18:43
@bentsku bentsku force-pushed the apigw-canary-logic branch from 4010c7c to 1239e1b Compare June 2, 2025 18:45
@bentsku bentsku marked this pull request as ready for review June 2, 2025 18:46
@bentsku bentsku requested a review from cloutierMat as a code owner June 2, 2025 18:46
Copy link
Contributor
@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean. Too bad we still need more moto helpers here, but thank you for the constant effort to keep it organized

@@ -622,7 +622,7 @@ def update_integration_response(
param = param.replace("~1", "/")
if op == "remove":
integration_response.response_templates.pop(param)
elif op == "add":
elif op in ("add", "replace"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What is this fixing? Is it a leftover from the previous pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat, this is because now that the test for the actual logic has been enabled, the test couldn't work because the update_integration_response method was not properly updating...
Here in TestCanaryDeployments.test_invoking_canary_deployment:

        aws_client.apigateway.update_integration_response(
            restApiId=api_id,
            resourceId=resource_id,
            httpMethod="GET",
            statusCode="200",
            patchOperations=[
                {
                    "op": "replace",
                    "path": "/responseTemplates/application~1json",
                    "value": json.dumps(
                        {
                            "statusCode": 200,
                            "message": "canary deployment",
                            "variable": "$stageVariables.testVar",
                            "nonExistingDefault": "$stageVariables.noStageVar",
                            "nonOverridden": "$stageVariables.defaultVar",
                            "isCanary": "$context.isCanaryRequest",
                        }
                    ),
                }
            ],
        )

So I just made that work for now 😅

@bentsku bentsku merged commit bf99fdb into master Jun 3, 2025
83 of 84 checks passed
@bentsku bentsku deleted the apigw-canary-logic branch June 3, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0