Skip to content
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

feat(synthetics): add RunConfig parameters to Cloudwatch Synthetics Canary L2 construct #11865

Closed
wants to merge 23 commits into from

Conversation

flochaz
Copy link
Contributor

@flochaz flochaz commented Dec 4, 2020

Cloudwatch Synthetics recently added Environment Variables injection feature.

This PR add all new RunConfig properties (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-synthetics-canary-runconfig.html) to the Canary L2 Construct.

Those new properties are all about lambda configuration so used same naming and docs as lambda equivalent.

Fixes #10515


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Dec 4, 2020

@mergify
Copy link
Contributor

mergify bot commented Dec 4, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@mergify
Copy link
Contributor

mergify bot commented Dec 4, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@flochaz flochaz changed the title Add RunConfig parameters to Cloudwatch Synthetics Canary L2 construct feat: Add RunConfig parameters to Cloudwatch Synthetics Canary L2 construct Dec 4, 2020
@flochaz flochaz changed the title feat: Add RunConfig parameters to Cloudwatch Synthetics Canary L2 construct feat(synthetics): add RunConfig parameters to Cloudwatch Synthetics Canary L2 construct Dec 4, 2020
@github-actions github-actions bot added the @aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics label Dec 4, 2020
Copy link

@danataws danataws left a comment

Choose a reason for hiding this comment

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

Suggest using the defaults set by the service.

@NetaNir
Copy link
Contributor

NetaNir commented Dec 4, 2020

Thanks for submitting this, before I review, have you seen this issue: #9300, which discuss adding the RunConfig. We had some issues with the implementation, wondering if you considered them

@NetaNir
Copy link
Contributor

NetaNir commented Dec 4, 2020

Im also wondering about the impact of the added Lambda config to the function being updated. For example, if the environment variables are modified, will the function be redeployed? We have a lot of logic that handles this edge cases in the aws lambda construct. Wondering how we can avoid duplicating this logic

@flochaz
Copy link
Contributor Author

flochaz commented Dec 5, 2020

Im also wondering about the impact of the added Lambda config to the function being updated. For example, if the environment variables are modified, will the function be redeployed? We have a lot of logic that handles this edge cases in the aws lambda construct. Wondering how we can avoid duplicating this logic

Since those properties are not set to the lambda but to the Canary CFN resource I expect this change to be handled directly in the service. But good point, I will make a test to make sure of it.

@NetaNir
Copy link
Contributor

NetaNir commented Dec 6, 2020

I would actually assume that all Lambda properties are passed to the function as is by the Synthetics service, if that's the case we need to think how we can reuse the logic which handles these properties updates from the aws-lambda module.

@flochaz
Copy link
Contributor Author

flochaz commented Dec 7, 2020

I would actually assume that all Lambda properties are passed to the function as is by the Synthetics service, if that's the case we need to think how we can reuse the logic which handles these properties updates from the aws-lambda module.

I did some test using raw cloud Formation and creation, deletion and update of environment variables are properly propagated on stack update. Do you mind to point me to the logic in lambda construct ?

@danataws
Copy link

danataws commented Dec 8, 2020

also wondering about the impact of the added Lambda config to the function being updated. For example, if the environment variables are modified, will the function be redeployed? We have a lot of logic that handles this edge cases in the aws lambda construct. Wondering how we can avoid duplicating this

If the env vars are modified, CloudWatch Synthetics updates the function.

@colvint
Copy link

colvint commented Jan 21, 2021

@colvint you can escape hatches in the meantime

Right, thanks @NetaNir -- we're gonna hold off on canaries until this lands. Take your time. Thanks for all the work here gang!

@flochaz
Copy link
Contributor Author

flochaz commented Jan 26, 2021

@NetaNir @colvint Should be good now

@markcarroll
Copy link

Hey guys, this looks very helpful. We are deploying some canaries right now and would love to be able to ditch the L1 escape hatch code. Did this just drop off the radar?

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 9634d78
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@NetaNir
Copy link
Contributor

NetaNir commented Mar 1, 2021

We have seen some odd behavior on function update when using the Function resource. Mainly around the update of properties such as Environment Variables. Since this has been a source of bad user experience (hard to debug), before we add this I want to think about a group of integration tests we can add that will verify the behavior, this will allow us to track the behavior and document it clearly.

Sorry for the inconvenience, in the meantime please use escape hatches

@NetaNir NetaNir removed their assignment Apr 30, 2021
@jonny-rimek
Copy link

adding an env var looks like this:

        const cfnCanary = canary.node.defaultChild as synthetics.CfnCanary
        cfnCanary.addPropertyOverride('RunConfig.EnvironmentVariables', {
            API_URL: "someurl"
        })

@BenChaimberg BenChaimberg self-assigned this Jun 3, 2021
@BenChaimberg
Copy link
Contributor

@flochaz thank you for the work you've done so far on this feature! We would like to continue this work but in a more segmented manner – would you be willing to split out just the environment variable portion of this PR? If not, I am happy to modify your changes and cite you as a collaborator :)

I'll have more feedback on the implementation itself after the split

@flochaz
Copy link
Contributor Author

flochaz commented Jun 4, 2021 via email

@BenChaimberg
Copy link
Contributor

@flochaz split out your changes into #15082 – thanks again!

*
* @default 128
*/
readonly memorySize?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should use Size from @aws-cdk/core and also please add checks for the multiple of 64 and the min and max values

Comment on lines +266 to +267
* Specifies whether this canary is to use active AWS X-Ray tracing when it runs.
* Active tracing enables this canary run to be displayed in the ServiceLens and X-Ray service maps
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Specifies whether this canary is to use active AWS X-Ray tracing when it runs.
* Active tracing enables this canary run to be displayed in the ServiceLens and X-Ray service maps
* Specifies whether this canary is to use active AWS X-Ray tracing when it runs.
*
* Active tracing enables this canary run to be displayed in the ServiceLens and X-Ray service maps

*
* @default false
*/
readonly tracing?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

please note that if a role is provided, it must also have permissions documented here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_tracing.html

* Active tracing enables this canary run to be displayed in the ServiceLens and X-Ray service maps
* even if the canary does not hit an endpoint that has X-ray tracing enabled.
*
* You can enable active tracing only for canaries that use version syn-nodejs-2.0 or later for their canary runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a check for this? it should be version != SYNTHETICS_1_0

*
* @default - No environment variables.
*/
readonly environment?: { [key: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

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

remove when merging from master

Comment on lines +464 to +466
const MAX_CANARY_TIMEOUT = 840;
const RATE_IN_SECONDS = Schedule.expressionToRateInSeconds(schedule.expression);
const DEFAULT_CANARY_TIMEOUT_IN_SECONDS = RATE_IN_SECONDS <= MAX_CANARY_TIMEOUT ? RATE_IN_SECONDS : MAX_CANARY_TIMEOUT;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for all caps here


/**
* The maximum amount of memory that the canary can use while running. This value
* must be a multiple of 64. The range is 960 to 3008.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* must be a multiple of 64. The range is 960 to 3008.
* must be a multiple of 64. The range is 960 to 3008.

const DEFAULT_CANARY_TIMEOUT_IN_SECONDS = RATE_IN_SECONDS <= MAX_CANARY_TIMEOUT ? RATE_IN_SECONDS : MAX_CANARY_TIMEOUT;

return {
timeoutInSeconds: props.timeout?.toSeconds() ?? DEFAULT_CANARY_TIMEOUT_IN_SECONDS,
Copy link
Contributor

Choose a reason for hiding this comment

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

needs to check this is smaller than the rate

Comment on lines +52 to +53
const regularExpression = /^rate\(([0-9]*) ([a-z]*)\)/;
const split = regularExpression.exec(expression);
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer using just string checks instead of a regular expression

*
* @param expression Schedule expression such as 'rate(2 minutes)'
*/
public static expressionToRateInSeconds(expression: string): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

convert to a Duration

@RichiCoder1
Copy link
Contributor

Is this PR still actively moving forward? Is this something I could help pick up again?

@flochaz
Copy link
Contributor Author

flochaz commented Jan 12, 2022 via email

RichiCoder1 added a commit to RichiCoder1/aws-cdk that referenced this pull request Jan 14, 2022
This PR is a continuation of aws#11865 with the intention of filling out the remaining RunConfig values as well as adding missing VpcConfig properties.

I wasn't sure whether VPC settings should be top level (like Lambda) or in their own configuration object, so I made them seperate for now.
@RichiCoder1
Copy link
Contributor

I've created a follow up here: #18447

@kaizencc
Copy link
Contributor

Closing this PR since it looks like it's getting picked up in separate pieces by other members of the community

@kaizencc kaizencc closed this Mar 11, 2022
mergify bot pushed a commit that referenced this pull request Mar 15, 2022
This PR adds vpc support to synthetics and is a continuation of #11865.

See [Running a canary on a vpc](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_VPC.html).

Fixes #9954

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-synthetics Related to Amazon CloudWatch Synthetics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[synthetics] Support setting environment variables during canary creation