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: [Step Function] Subscribe forwarder to log group #319

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

lym953
Copy link
Contributor

@lym953 lym953 commented Nov 1, 2024

What does this PR do?

Enables adding a subscription filter to subscribe the forwarder to the state machine's log group.

Motivation

This is the second step of instrumenting a step function.

Testing Guidelines

Automated testing

Passed the added test for forwarder setup

Manual testing

Step:

  1. Deploy the example stacks in step-functions-typescript-stack.

Result:

  1. The subscription filter appeared in AWS UI
image

@DylanLovesCoffee sorry I borrowed your forwarder.

Additional Notes

It takes a lot of code to extract log group from the log config of a state machine, if the user sets the log group themselves.

      // Extract log group from logging config
      const destinations = cfnStateMachine.loggingConfiguration.destinations;
      if (!this.isLogDestinationPropertyArray(destinations)) {
        throw new Error("destinations is not an array");
      }

      const destination = destinations[0];
      if (!("cloudWatchLogsLogGroup" in destination)) {
        throw new Error("cloudWatchLogsLogGroup is not in destination");
      }

      const logGroupConfig = destination.cloudWatchLogsLogGroup;
      if (logGroupConfig === undefined) {
        throw new Error("cloudWatchLogsLogGroup is undefined");
      }

      if (!("logGroupArn" in logGroupConfig)) {
        throw new Error("logGroupArn is not in cloudWatchLogsLogGroup");
      }

      const logGroupArn = logGroupConfig.logGroupArn;
      if (logGroupArn === undefined) {
        throw new Error("logGroupArn is undefined");
      }

      logGroup = logs.LogGroup.fromLogGroupArn(this, "LogGroup", logGroupArn);

There are so many checks because at each level, the variable can often have multiple possible types, e.g. logGroupConfig can be

IResolvable | sfn.CfnStateMachine.CloudWatchLogsLogGroupProperty | undefined

To be able to parse the log group, we assume that nothing is an unresolved token (i.e. IResolvable), and throw if anything is an unresolved token. I'm not sure in what case and if it's common that anything is an unresolved token. I think we can start from handling the simple case, and come back later if anyone asks for supporting the unresolved token cases.

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 1, 2024 21:07
}

private isLogDestinationPropertyArray(
destinations: any,

Choose a reason for hiding this comment

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

Code Quality Violation

Unexpected any. Specify a different type. (...read more)

Do not use the any type, as it is too broad and can lead to unexpected behavior.

View in Datadog  Leave us feedback  Documentation

@lym953 lym953 force-pushed the yiming.luo/step-function-support-test-2 branch from 35a2757 to b10f59c Compare November 5, 2024 17:08
@lym953
Copy link
Contributor Author

lym953 commented Nov 7, 2024

/merge

@dd-devflow
Copy link

dd-devflow bot commented Nov 7, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-11-07 15:44:07 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 8m.

@dd-mergequeue dd-mergequeue bot merged commit b91b796 into main Nov 7, 2024
13 checks passed
@dd-mergequeue dd-mergequeue bot deleted the yiming.luo/step-function-support-test-2 branch November 7, 2024 15:52
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