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

chore: Add snapshot test for TypeScript step function stack #327

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Nov 13, 2024

What does this PR do?

Add a snapshot test for a TypeScript step function stack to ensure future changes don't unintentionally change the synthesized CloudFormation template.

Motivation

Testing Guidelines

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

@lym953 lym953 requested a review from a team as a code owner November 13, 2024 21:17
Comment on lines 16 to 87
export class ExampleStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Creating Hello World TypeScript stack");

/* Set up the child state machine */

const passState = new sfn.Pass(this, "PassState");
const waitState = new sfn.Wait(this, "WaitState", { time: sfn.WaitTime.duration(Duration.seconds(1)) });
const successState = new sfn.Succeed(this, "SuccessState");

const childStateMachine = new sfn.StateMachine(this, "CdkTypeScriptTestChildStateMachine", {
definitionBody: sfn.DefinitionBody.fromChainable(passState.next(waitState).next(successState)),
});

/* Set up the parent state machine */

const invokeChildStateMachineTask = new tasks.StepFunctionsStartExecution(this, "InvokeChildStateMachineTask", {
stateMachine: childStateMachine,
input: sfn.TaskInput.fromObject(
DatadogStepFunctions.buildStepFunctionTaskPayloadToMergeTraces({ "custom-key": "custom-value" }),
),
});

const helloLambdaFunction = new lambda.Function(this, "hello-python", {
runtime: lambda.Runtime.PYTHON_3_12,
handler: "index.handler",
code: lambda.Code.fromInline(`
def handler(event, context):
return "Hello, world!"
`),
});

const lambdaTask = new tasks.LambdaInvoke(this, "MyLambdaTask", {
lambdaFunction: helloLambdaFunction,
payload: sfn.TaskInput.fromObject(DatadogStepFunctions.buildLambdaPayloadToMergeTraces()),
});

const parentStateMachine = new sfn.StateMachine(this, "CdkTypeScriptTestStateMachine", {
definitionBody: sfn.DefinitionBody.fromChainable(lambdaTask.next(invokeChildStateMachineTask)),
});

/* Instrument the lambda functions and the state machines */

console.log("Instrumenting Step Functions in TypeScript stack with Datadog");

const datadogSfn = new DatadogStepFunctions(this, "DatadogSfn", {
env: "dev",
service: "cdk-test-service",
version: "1.0.0",
forwarderArn: process.env.DD_FORWARDER_ARN,
tags: "custom-tag-1:tag-value-1,custom-tag-2:tag-value-2",
});
datadogSfn.addStateMachines([childStateMachine, parentStateMachine]);

const datadogLambda = new DatadogLambda(this, "DatadogLambda", {
pythonLayerVersion: 101,
extensionLayerVersion: 65,
addLayers: true,
apiKey: process.env.DD_API_KEY,
enableDatadogTracing: true,
enableDatadogASM: true,
flushMetricsToLogs: true,
site: "datadoghq.com",
env: "dev",
service: "cdk-test-service",
version: "1.0.0",
});
datadogLambda.addLambdaFunctions([helloLambdaFunction]);
}
}

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.

View in Datadog  Leave us feedback  Documentation

const app = new App();
const env = { account: "601427279990", region: "sa-east-1" };
const stack = new ExampleStack(app, "step-function-stack", { env: env });
console.log("Stack name: " + stack.stackName);

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Unexpected console statement. (...read more)

Debugging with console is not considered a bad practice, but it's easy to forget about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation


/* Instrument the lambda functions and the state machines */

console.log("Instrumenting Step Functions in TypeScript stack with Datadog");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Unexpected console statement. (...read more)

Debugging with console is not considered a bad practice, but it's easy to forget about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation

constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

console.log("Creating Hello World TypeScript stack");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Unexpected console statement. (...read more)

Debugging with console is not considered a bad practice, but it's easy to forget about console statements and leave them in production code. There is no need to pollute production builds with debugging statements.

View in Datadog  Leave us feedback  Documentation

@lym953 lym953 changed the title Add snapshot test for TypeScript step function stack chore: Add snapshot test for TypeScript step function stack Nov 13, 2024
@lym953 lym953 force-pushed the yiming.luo/step-function-support-8 branch 2 times, most recently from dcb1f10 to 3c9612d Compare November 13, 2024 22:37
Copy link

@avedmala avedmala left a comment

Choose a reason for hiding this comment

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

🚢

@lym953 lym953 force-pushed the yiming.luo/step-function-support-7 branch from b58f77d to 44dabdc Compare November 14, 2024 18:29
Base automatically changed from yiming.luo/step-function-support-7 to main November 14, 2024 18:30
@lym953 lym953 force-pushed the yiming.luo/step-function-support-8 branch from 3c9612d to a38a4f3 Compare November 14, 2024 18:37
@lym953
Copy link
Contributor Author

lym953 commented Nov 14, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 14, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-14 18:39:14 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 8m.


2024-11-14 18:39:16 UTC ℹ️ MergeQueue: merge request added to the queue

The median merge time in main is 8m.

@dd-mergequeue dd-mergequeue bot merged commit 197f1f0 into main Nov 14, 2024
13 checks passed
@dd-mergequeue dd-mergequeue bot deleted the yiming.luo/step-function-support-8 branch November 14, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants