Skip to content

cloudwatch: fix functionality of metrics for multi-accounts and region #9945

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 5 commits into from
Feb 2, 2024

Conversation

sannya-singal
Copy link
Contributor

@sannya-singal sannya-singal commented Dec 27, 2023

Motivation

When using values other than 000000000000 for account ID or us-east-1 for region, cloudwatch tests should still create the consequent resources in these accounts and region.

Changes

This PR adds account_id parameter to the cloudwatch client when publishing the lambda metric on function invoke. The remaining changes involves propagating its value to the corresponding functions.

Testing

The tests were failing previously when executed with a non-default account ID, set through environment variables (TEST_AWS_ACCOUNT_ID=111111111111, TEST_AWS_ACCESS_KEY_ID=111111111111, TEST_AWS_REGION=us-west-1). This PR fixes:

tests.aws.services.cloudwatch.test_cloudwatch_metrics.TestCloudWatchLambdaMetrics.test_lambda_invoke_successful
tests.aws.services.cloudwatch.test_cloudwatch_metrics.TestCloudWatchLambdaMetrics.test_lambda_invoke_error

@sannya-singal sannya-singal self-assigned this Dec 27, 2023
@sannya-singal sannya-singal added the semver: patch Non-breaking changes which can be included in patch releases label Dec 27, 2023
@sannya-singal sannya-singal marked this pull request as ready for review December 27, 2023 09:17
@sannya-singal sannya-singal marked this pull request as draft December 27, 2023 09:26
Copy link

github-actions bot commented Dec 27, 2023

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 22m 53s ⏱️ + 2m 25s
2 616 tests ±0  2 368 ✅ ±0  248 💤 ±0  0 ❌ ±0 
2 618 runs  ±0  2 368 ✅ ±0  250 💤 ±0  0 ❌ ±0 

Results for commit 2b2d7e8. ± Comparison against base commit 4a5f76e.

♻️ This comment has been updated with latest results.

@sannya-singal sannya-singal marked this pull request as ready for review December 27, 2023 10:38
Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this @sannya-singal

I can confirm that using a different account failed before the fix and now works properly 👏👏👏: TEST_AWS_ACCOUNT_ID=111111111111 LAMBDA_DEV_PORT_EXPOSE=1 TEST_PATH="tests/aws/services/cloudwatch/test_cloudwatch_metrics.py::TestCloudWatchLambdaMetrics::test_lambda_invoke_successful" make test

The region should already work properly.

Parsing the account_id from the function ARN requires regex matching for every CloudWatch metric submission. We can speed things up by passing the account_id explicitly instead of parsing it. Hence, I suggest passing something like account_id=self.function_version.id.account, in version_manager.py.

@sannya-singal sannya-singal added the aws:cloudwatch Amazon CloudWatch label Jan 31, 2024
@coveralls
Copy link

Coverage Status

coverage: 83.822% (-0.02%) from 83.841%
when pulling 2b2d7e8 on cloudwatch_multi_acc
into 4a5f76e on master.

@sannya-singal
Copy link
Contributor Author

@sannya-singal sannya-singal requested a review from joe4dev January 31, 2024 07:39
Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Thank you @sannya-singal for fixing multi-accounts for Lambda CloudWatch metrics 🥳

@sannya-singal
Copy link
Contributor Author

Thanks @joe4dev 🚀 🎉

@sannya-singal sannya-singal merged commit f3811b7 into master Feb 2, 2024
@sannya-singal sannya-singal deleted the cloudwatch_multi_acc branch February 2, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:cloudwatch Amazon CloudWatch semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants