-
Notifications
You must be signed in to change notification settings - Fork 28
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: add skeleton of step function class and example stack #290
base: yiming.luo/step-function-refactor2
Are you sure you want to change the base?
feat: add skeleton of step function class and example stack #290
Conversation
import { CdkStepFunctionsTypeScriptStack } from "../lib/cdk-step-functions-typescript-stack"; | ||
|
||
const app = new cdk.App(); | ||
new CdkStepFunctionsTypeScriptStack(app, "CdkStepFunctionsTypeScriptStack", {}); |
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.
@@ -91,3 +91,5 @@ export interface Node { | |||
} | |||
|
|||
export type LambdaFunction = lambda.Function | lambda.SingletonFunction; | |||
|
|||
export interface DatadogStepFunctionsProps {} |
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.
), | ||
}); | ||
|
||
console.log("Instrumenting Step Functions in TypeScript stack with Datadog"); |
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.
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); |
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.
@@ -0,0 +1,6 @@ | |||
*.ts |
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.
Copied from examples/typescript-stack/.npmignore
@@ -0,0 +1,3 @@ | |||
# Datadog CDK TypeScript Example |
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.
Written from scratch
@@ -0,0 +1,7 @@ | |||
#!/usr/bin/env node |
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.
Modified from examples/typescript-stack/bin/index.ts
@@ -0,0 +1,39 @@ | |||
{ |
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.
Copied from examples/typescript-stack/cdk.json
@@ -0,0 +1,40 @@ | |||
import * as lambda from "aws-cdk-lib/aws-lambda"; |
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.
Written from scratch
@@ -0,0 +1,20 @@ | |||
{ |
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.
Copied from examples/typescript-stack/package.json
@@ -0,0 +1,23 @@ | |||
/* |
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.
Written from scratch.
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.
Approved with some suggestions, thanks!
@@ -0,0 +1,3 @@ | |||
# Datadog CDK TypeScript Example | |||
|
|||
This example is used for testing the [datadog-cdk-constructs](https://github.com/DataDog/datadog-cdk-constructs) v2 library for Step Functions. The Step Functions support is still being built. Once it's ready, this example will be merged into the `typescript-stack` so that a single stack can be used for testing both Lambda functions and Step Functions, making it easier for CDK construct developers to test changes and ensure that their changes don't break things. The two examples are kept separate for now so that the incomplete Step Function support won't break the testing of 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.
This example is used for testing the [datadog-cdk-constructs](https://github.com/DataDog/datadog-cdk-constructs) v2 library for Step Functions. The Step Functions support is still being built. Once it's ready, this example will be merged into the `typescript-stack` so that a single stack can be used for testing both Lambda functions and Step Functions, making it easier for CDK construct developers to test changes and ensure that their changes don't break things. The two examples are kept separate for now so that the incomplete Step Function support won't break the testing of Lambda functions. | |
This example is used to test the [datadog-cdk-constructs](https://github.com/DataDog/datadog-cdk-constructs) v2 library for Step Functions. The Step Functions support is still in development. Once it's ready, this example will be merged into the `typescript-stack` so that a single stack can be used for testing both Lambda functions and Step Functions, making it easier for CDK construct developers to test their changes. The two examples are kept separate for now, so the incomplete Step Function support won't break the testing of Lambda functions. |
I skipped the explanation of why someone would test, just because your audience likely already knows that. But if you wanted to keep it in, you can leave that part. I might say "easier for CDK construct developers to ensure that their changes don't cause regressions" or something along those lines, just for simplicity.
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.
Make sense! I prefer simplicity as well. Will remove the redundant part.
0807af8
to
14a7971
Compare
43990ce
to
1fe6976
Compare
14a7971
to
7ed97a7
Compare
export class CdkStepFunctionsTypeScriptStack extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
console.log("Creating Hello World TypeScript stack"); | ||
|
||
const helloLambdaFunction = new lambda.Function(this, "hello-python", { | ||
runtime: lambda.Runtime.PYTHON_3_12, | ||
timeout: Duration.seconds(10), | ||
memorySize: 256, | ||
code: lambda.Code.fromAsset("../lambda/python", { | ||
bundling: { | ||
image: lambda.Runtime.PYTHON_3_12.bundlingImage, | ||
command: ["bash", "-c", "pip install -r requirements.txt -t /asset-output && cp -aT . /asset-output"], | ||
}, | ||
}), | ||
handler: "hello.lambda_handler", | ||
}); | ||
|
||
const stateMachine = new sfn.StateMachine(this, "MyStateMachine", { | ||
definitionBody: sfn.DefinitionBody.fromChainable( | ||
new tasks.LambdaInvoke(this, "MyLambdaTask", { | ||
lambdaFunction: helloLambdaFunction, | ||
}).next(new sfn.Succeed(this, "GreetedWorld")), | ||
), | ||
}); | ||
|
||
console.log("Instrumenting Step Functions in TypeScript stack with Datadog"); | ||
|
||
const datadogSfn = new DatadogStepFunctions(this, "Datadog", {}); | ||
datadogSfn.addStateMachines([stateMachine]); | ||
} | ||
} |
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.
⚪ Code Quality Violation
This class is unnecessary (...read more)
This rule advises against the unnecessary use of classes that contain only static members, or nothing. In JavaScript, classes are primarily used for object-oriented programming, where each instance of a class has its own state and behavior. Static members, on the other hand, belong to the class itself and not to any instance of the class.
When a class contains only static members, it does not make use of JavaScript's object-oriented capabilities, and it can be more difficult to understand, test, and maintain than necessary. In order to avoid this issue, consider using regular functions and variables instead of static class members. This makes your code easier to understand and maintain, and it allows you to make better use of JavaScript's features.
this.props = props; | ||
} | ||
|
||
public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {} |
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.
🔴 Code Quality Violation
public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {} | |
public addStateMachines(_stateMachines: sfn.StateMachine[], _construct?: Construct): void {/* empty */} |
Empty statement. (...read more)
Empty or non-functional blocks in the code can be misleading and lead to maintenance difficulties. They can also lead to a false sense of security or functionality. While they may not directly introduce security issues, their presence can suggest that some logic or error handling is implemented when it is not.
What does this PR do?
DatadogStepFunctions
class, which users will use to add Datadog monitoring for their Step FunctionsMotivation
For SVLS-4394: Customers can instrument their Step Functions with CDK macro and SAM
Testing Guidelines
Followed the internal wiki for testing local changes to CDK Construct
After
cdk deploy
, a CloudFormation stack was deployed successfully, which includes a Lambda function and a Step Function, though Datadog monitoring is not set up for them.Additional Notes
Please comment on naming. I'm using:
DatadogStepFunctions
as the class nameaddStateMachines()
as the function nameLet me know if you prefer to use:
s
), and/oraddStepFunctions()
instead ofaddStateMachines()
Next steps:
DatadogStepFunctions
class, make it do various work needed to set up Datadog monitoring. I'll do this in small steps, sending small PRs.Types of Changes
Check all that apply