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: Rename: Datadog -> DatadogLambda #285

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Aug 28, 2024

What does this PR do?

  1. Rename Datadog class as DatadogLambda, including:
    1. rename datadog.ts as datadog-lambda.ts
    2. rename datadog.spec.ts as datadog-lambda.spec.ts
  2. Make all references of Datadog use DatadogLambda
  3. Create a new Datadog class which just wraps (extends) the new DatadogLambda class, so its behavior will be the same as the old Datadog class. Let me know if you think I should wrap it in a different way.
  4. Create an example stack lambda-function-stack-legacy-datadog-api.ts, which uses Datadog instead of DatadogLambda, showing how to use the legacy Datadog API
  5. Create a test datadog.spec.ts to ensure the Datadog API still works

Motivation

To make it cleaner to add DatadogStepFunction class later. Details in [RFC] Changing API for Datadog CDK Construct

Testing Guidelines

Automated testing

  1. pass existing automated tests
  2. pass the new datadog.spec.ts

Manual testing

1. using DatadogLambda API

Steps:

  1. In examples/typescript-stack/lib/cdk-typescript-stack.ts, replace the CdkTypeScriptStack class with the ExampleStack class in integration_tests/stacks/lambda-function-stack.ts. I can't use the existing CdkTypeScriptStack class due to some docker permission issue.
    • The ExampleStack class uses DatadogLambda API
  2. Follow the instructions in Datadog CDK Constructs internal wiki to install the local package deploy the stack

Result:

  • Deployment is successful. The Lambda functions have Datadog layers installed.
2. using Datadog API

Step:

  • In the test above, make the ExampleStack class use Datadog class instead of DatadogLambda. Deploy again.

Result:

  • Deployment is also successful. The Lambda functions have Datadog layers installed.

Additional Notes

Next steps:

  1. update README.md, recommending users to use DatadogLambda instead of Datadog

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

props: DatadogProps;
transport: Transport;
constructor(scope: Construct, id: string, props: DatadogProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
Expected '===' and instead saw '=='. (...read more)

In JavaScript, == and != comparisons do type coercion, which can be confusing and may introduce potential errors. Use the type-safe equality operators === and !== instead.

View in Datadog  Leave us feedback  Documentation

public addGitCommitMetadata(
lambdaFunctions: LambdaFunction[],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Choose a reason for hiding this comment

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

Code Quality Violation

Disallow `// tslint:` comments (...read more)

Correct your types instead of disabling TypeScript.

View in Datadog  Leave us feedback  Documentation

Comment on lines +127 to +135
public addGitCommitMetadata(
lambdaFunctions: LambdaFunction[],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
gitCommitSha?: string,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
gitRepoUrl?: string,
): void {

Choose a reason for hiding this comment

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

Code Quality Violation

Too many parameters (7). Maximum allowed is 4. (...read more)

Having too many parameters can make your code hard to read. The parameters must be used in appropriate order. Forgetting the order of parameters can cause mistakes.

Too many parameters is a code smell. You should refactor your code in smaller reusable bits. While it may be valid to require more than four parameters, you should use object destructuring.

View in Datadog  Leave us feedback  Documentation

} from "./index";
import { LambdaFunction } from "./interfaces";

const versionJson = require("../version.json");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Require statement not part of import statement. (...read more)

Use ESM instead of CommonJS imports.

View in Datadog  Leave us feedback  Documentation

console.log(
"Instrumenting Lambda Functions in TypeScript stack with Datadog"
);
console.log("Instrumenting Lambda 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

props: DatadogProps;
transport: Transport;
constructor(scope: Construct, id: string, props: DatadogProps) {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {

Choose a reason for hiding this comment

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

Code Quality Violation

Suggested change
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() == "true") {
if (process.env.DD_CONSTRUCT_DEBUG_LOGS?.toLowerCase() === "true") {
Expected '===' and instead saw '=='. (...read more)

In JavaScript, == and != comparisons do type coercion, which can be confusing and may introduce potential errors. Use the type-safe equality operators === and !== instead.

View in Datadog  Leave us feedback  Documentation

public addGitCommitMetadata(
lambdaFunctions: LambdaFunction[],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Choose a reason for hiding this comment

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

Code Quality Violation

Disallow `// tslint:` comments (...read more)

Correct your types instead of disabling TypeScript.

View in Datadog  Leave us feedback  Documentation

Comment on lines +127 to +135
public addGitCommitMetadata(
lambdaFunctions: LambdaFunction[],
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
gitCommitSha?: string,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
gitRepoUrl?: string,
): void {

Choose a reason for hiding this comment

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

Code Quality Violation

Too many parameters (7). Maximum allowed is 4. (...read more)

Having too many parameters can make your code hard to read. The parameters must be used in appropriate order. Forgetting the order of parameters can cause mistakes.

Too many parameters is a code smell. You should refactor your code in smaller reusable bits. While it may be valid to require more than four parameters, you should use object destructuring.

View in Datadog  Leave us feedback  Documentation

} from "./index";
import { LambdaFunction } from "./interfaces";

const versionJson = require("../version.json");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Require statement not part of import statement. (...read more)

Use ESM instead of CommonJS imports.

View in Datadog  Leave us feedback  Documentation

console.log(
"Instrumenting Lambda Functions in TypeScript stack with Datadog"
);
console.log("Instrumenting Lambda 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

@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch 2 times, most recently from aa63b23 to de6d7e4 Compare August 28, 2024 21:17
@lym953 lym953 force-pushed the yiming.luo/auto-format branch 3 times, most recently from 983592b to 46a3573 Compare August 29, 2024 15:24
Base automatically changed from yiming.luo/auto-format to main August 29, 2024 15:30
@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch from de6d7e4 to 2208e0e Compare August 29, 2024 15:51
// @ts-ignore
gitCommitSha?: string,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Choose a reason for hiding this comment

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

Code Quality Violation

Disallow `// tslint:` comments (...read more)

Correct your types instead of disabling TypeScript.

View in Datadog  Leave us feedback  Documentation

@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch from 2208e0e to 635722f Compare August 29, 2024 16:14
Comment on lines +27 to +32
new LambdaRestApi(this, "rest-test", {
handler: lambdaFunction,
deployOptions: {
accessLogDestination: new LogGroupLogDestination(restLogGroup),
},
});

Choose a reason for hiding this comment

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

Code Quality Violation

Do not use 'new' for side effects. (...read more)

A lonely instance is almost always useless. Do not create objects without assigning them to a variable that you will use later.

View in Datadog  Leave us feedback  Documentation

import * as lambda from "aws-cdk-lib/aws-lambda";
import { LogGroup } from "aws-cdk-lib/aws-logs";
import { addCdkConstructVersionTag, checkForMultipleApiKeys, DatadogLambda, DD_HANDLER_ENV_VAR } from "../src/index";
const { ISecret } = require("aws-cdk-lib/aws-secretsmanager");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Require statement not part of import statement. (...read more)

Use ESM instead of CommonJS imports.

View in Datadog  Leave us feedback  Documentation

const app = new App();
const env = { account: "601427279990", region: "sa-east-1" };
const stack = new ExampleStack(app, "lambda-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

import { LogGroup } from "aws-cdk-lib/aws-logs";
import { addCdkConstructVersionTag, checkForMultipleApiKeys, DatadogLambda, DD_HANDLER_ENV_VAR } from "../src/index";
const { ISecret } = require("aws-cdk-lib/aws-secretsmanager");
const versionJson = require("../version.json");

Choose a reason for hiding this comment

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

🟠 Code Quality Violation

Require statement not part of import statement. (...read more)

Use ESM instead of CommonJS imports.

View in Datadog  Leave us feedback  Documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are just comments on existing code. Let me address them in a separate PR.

@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch from 635722f to 3646d05 Compare August 29, 2024 16:15
@lym953 lym953 force-pushed the yiming.luo/step-function-refactor branch from 3646d05 to a61fe64 Compare August 29, 2024 16:17
@@ -0,0 +1,52 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied and modified from integration_tests/stacks/lambda-function-stack.ts

@@ -0,0 +1,365 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is renamed from datadog.ts

@lym953 lym953 marked this pull request as ready for review August 29, 2024 17:28
@lym953 lym953 requested a review from a team as a code owner August 29, 2024 17:28
@@ -1,537 +1,11 @@
import { App, Stack, Token } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
import { App, Stack } from "aws-cdk-lib";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was first renamed as datadog-lambda.spec.ts. Then datadog.spec.ts was created again with one test, to ensure the Datadog API still works.

@lym953
Copy link
Contributor Author

lym953 commented Aug 29, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Aug 29, 2024

🚂 MergeQueue: pull request added to the queue

The median merge time in main is 4m.

Use /merge -c to cancel this operation!

@dd-mergequeue dd-mergequeue bot merged commit 44c50db into main Aug 29, 2024
17 checks passed
@dd-mergequeue dd-mergequeue bot deleted the yiming.luo/step-function-refactor branch August 29, 2024 18:51
@pwrmiller
Copy link

Just an FYI, this is a breaking change. Packages that depend on datadog-cdk-constructs will now fail, with errors similar to (in Python, for example)

ImportError: cannot import name 'DatadogProps' from 'datadog_cdk_constructs_v2'

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.

3 participants