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(aws-logs-destinations): add Firehose Log Subscription Destination #14918

Closed
wants to merge 11 commits into from
Closed

feat(aws-logs-destinations): add Firehose Log Subscription Destination #14918

wants to merge 11 commits into from

Conversation

yerzhan7
Copy link
Contributor

@yerzhan7 yerzhan7 commented May 29, 2021

Add FIrehose CW Logs Subscription Destination for delivering logs from CW directly into Firehose (in batches, gziped).

Currently, this package contains only Kinesis Logs Subscription Destination, but it's possible to send directly to Firehose without Kinesis stream. See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#FirehoseExample

Implementation is based on these official instructions.

Also, Firehose does not have high level CDK constructs, so I used native Cfn level stuff.

Tested by deploying test stack and sending logs to the log stream. Validated that logs are delivered to S3 via Firehose.


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 May 29, 2021

@yerzhan7 yerzhan7 marked this pull request as ready for review May 29, 2021 22:57
@BenChaimberg BenChaimberg self-assigned this Jun 1, 2021
@BenChaimberg
Copy link
Contributor

Thank you very much for your contribution (especially the documentation)! We are currently working on the design for the Firehose L2 (see #10810) which should be used here. To avoid rewriting the API in the future, I am going to mark this as blocked for now. Please reach out here if you have questions!

@BenChaimberg BenChaimberg added the pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. label Jun 1, 2021
A short description here.
This library supplies constructs for working with CloudWatch Logs Subscription Destinations.

## Logs Destinations
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're feeling up for it, it would be great to have these snippets compile in their first iteration. I'm thinking an initial snippet showing how to set up a log group, then each individual destination uses a fixture seeded with a log group to create the destination. Though ellipses are supported, giving a full specification of the destination resource would be ideal. See: CONTRIBUTING#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.

Will wait for L2

assumedBy: new iam.ServicePrincipal(`logs.${region}.amazonaws.com`),
});

iam.Grant.addToPrincipal({
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be necessary when the L2 is created, but I'd prefer

role.addToPrincipalPolicy({ ... })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will wait for L2

});

// THEN: we have a single role to write to the Firehose
expect(stack).toCountResources('AWS::IAM::Role', 2); // TODO: Fix to 1 - somehow it still creates 2 roles...
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this to 1 so the build will fail until this has been fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any tips on what might be the issue here? I have no idea...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh this is actually correct, since you create two separate log groups and create the role under the log group scope. You should create a separate test that attaches two destinations to the same log group and asserts that only one role is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But in my first revision it was not working when I used scope of Stack.

My initial intention was to have a single role for each Firehose destination. (i.e. 2 log groups will re-use the same role). What scope is the correct one to use for this role?

@mergify mergify bot dismissed BenChaimberg’s stale review June 1, 2021 21:14

Pull request has been modified.

@BenChaimberg
Copy link
Contributor

In the future, please add more commits onto your working branch instead of amending the old commit and force-pushing. This makes it easier to see what you've changed :)

@yerzhan7
Copy link
Contributor Author

yerzhan7 commented Jun 2, 2021

In the future, please add more commits onto your working branch instead of amending the old commit and force-pushing. This makes it easier to see what you've changed :)

Will do, thanks. I presumed github can do diffs between revisions.

So, do I still need to squash commits after approval?

@BenChaimberg
Copy link
Contributor

One would hope but doesn't seem to be the case...or I just haven't found the right buttons to click. No need to squash or manually merge – our workflows will take care of that.

@yerzhan7
Copy link
Contributor Author

@BenChaimberg any ETA for Firehose L2? I saw #14860 got closed.

Is it possible to merge this PR without Firehose L2?

Thanks

@BenChaimberg
Copy link
Contributor

BenChaimberg commented Jun 15, 2021

The PR in question was closed in favour of a different branch, but the work is still actively ongoing! We are hoping to open a first PR for review by 6/17. Because the changes in this PR would be immediately overwritten and aws-logs-destinations is a stable module, we will not be merging this in its current state. Thanks for your patience!

@BenChaimberg BenChaimberg added p1 and removed p2 labels Jun 22, 2021
Copy link
Contributor

@BenChaimberg BenChaimberg left a comment

Choose a reason for hiding this comment

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

we're almost there! #15544 is nearing completion and we can restart this work when it's complete

requesting changes just to get this off my queue

@BenChaimberg
Copy link
Contributor

Hello! #15544 has been merged and the DeliveryStream L2 is ready and raring to go! Please go take a look – it should have all we need to complete this PR.

@BenChaimberg BenChaimberg removed pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. @aws-cdk/aws-kinesisfirehose Related to Amazon Kinesis Data Firehose labels Jul 23, 2021
@yerzhan7
Copy link
Contributor Author

Awesome! Thanks, will post an update in a few days

@mergify mergify bot dismissed BenChaimberg’s stale review July 24, 2021 11:04

Pull request has been modified.

* Use a Kinesis Firehose as the destination for a log subscription
*/
export class KinesisFirehoseDestination implements logs.ILogSubscriptionDestination {
constructor(private readonly deliveryStream: firehose.DeliveryStream) {
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
constructor(private readonly deliveryStream: firehose.DeliveryStream) {
constructor(private readonly deliveryStream: firehose.IDeliveryStream) {

}

public bind(_scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig {
const { region } = Stack.of(this.deliveryStream);
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
const { region } = Stack.of(this.deliveryStream);
const region = this.deliveryStream.env.region;

Comment on lines 23 to 24
const role = this.deliveryStream.node.tryFindChild(roleId) as iam.IRole ??
new iam.Role(this.deliveryStream, roleId, {
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
const role = this.deliveryStream.node.tryFindChild(roleId) as iam.IRole ??
new iam.Role(this.deliveryStream, roleId, {
const role = scope.node.tryFindChild(roleId) as iam.IRole ??
new iam.Role(scope, roleId, {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With your suggested change we would create 2 identical IAM roles that will fail my unit test in https://github.com/aws/aws-cdk/pull/14918/files#diff-4dab4ab34393d725389edf0c2c55b924e6e9c569d86f78b21ad5d36b8f29b076R104

Do we really want to create 2 identical roles in that unit test case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we do. There should be a logical mapping between the actor and the role, which would be violated if we create one role per delivery stream (as that is the resource). The test case can be modified to demonstrate that we re-use the role if there are multiple Firehose subscriptions from the same log group

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test case can be modified to demonstrate that we re-use the role if there are multiple Firehose subscriptions from the same log group

This would still create 2 separate roles because scope would be different for 2 separate subscriptions even if they are applied to the same log group.

So, it looks like scope.node.tryFindChild(roleId) as iam.IRole ?? is a redundant check as that condition will never be true.

Anyway, I will just remove this unit test case for now as it's impossible to test that condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah because the destination is bound under SubscriptionFilter, not LogGroup. Okay, no problem with having multiple roles then

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, yes we should remove the tryFindChild and always create a new role

constructor(private readonly deliveryStream: firehose.DeliveryStream) {
}

public bind(_scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig {
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
public bind(_scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig {
public bind(scope: Construct, _sourceLogGroup: logs.ILogGroup): logs.LogSubscriptionDestinationConfig {

removalPolicy: cdk.RemovalPolicy.DESTROY,
});

// TODO: For some reason creation of this resource fails: `Subscription (Subscription391C9821) destinationArn for vendor firehose cannot be used with roleArn (Service: AWSLogs; Status Code: 400; Error Code: InvalidParameterException; Request ID: 0e598426-5fcb-4fde-b9d3-11b14c129eb6; Proxy: null)`
Copy link
Contributor

Choose a reason for hiding this comment

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

CloudWatch Logs currently has a bug where destination ARNs that contain the string "destination" are rejected from creating a subscription. Workaround is to change the stack name below to remove the "destination" – maybe replace with "dests"

Internal reference: P48761216

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What a weird bug! Thanks for digging into this.

@mergify mergify bot dismissed BenChaimberg’s stale review July 26, 2021 19:43

Pull request has been modified.

@yerzhan7
Copy link
Contributor Author

@BenChaimberg , could you please help me with CodeBuild failure above? Thanks

aws-cdk-lib: �[96mlib/aws-logs-destinations/lib/kinesisfirehose.ts�[0m:�[93m11�[0m:�[93m59�[0m - �[91merror�[0m�[90m TS2694: �[0mNamespace '"/codebuild/output/src850447146/src/github.com/aws/aws-cdk/packages/aws-cdk-lib/lib/aws-kinesisfirehose/index"' has no exported member 'IDeliveryStream'.
aws-cdk-lib: �[7m11�[0m     constructor(private readonly deliveryStream: firehose.IDeliveryStream) {

@BenChaimberg
Copy link
Contributor

aws-cdk-lib is the v2 library which removes experimental modules (except for the L1s), meaning stable modules that are included cannot currently depend on experimental modules. The team is currently working on this issue so we may have a fix in the pipeline, but this PR will be blocked until then.

@BenChaimberg BenChaimberg added the pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason. label Jul 27, 2021
@nikovirtala
Copy link
Contributor

@BenChaimberg, is there anything that one could do to get this merged? – The issue with experimental modules with v2 is, in my understanding, solved.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: d706e74
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@yerzhan7
Copy link
Contributor Author

yerzhan7 commented Nov 19, 2021

The issue with experimental modules with v2 is, in my understanding, solved.

@nikovirtala I've just merged latest stuff from master and, as you see above, the build still fails with the same error message.

How do you know that the issue is solved? Maybe I am missing some config

@BenChaimberg
Copy link
Contributor

@kaizen3031593 can you please respond to the query above -- I have not been following the developments on experimental modules.

@kaizencc
Copy link
Contributor

@nikovirtala my quick understanding of the issue is that stable modules cannot depend on experimental modules; this is by design. In that sense, there is nothing to resolve. Instead, we are waiting for kinesis-firehose to be stabilized, in which case we can take another look at this PR. I will double-check for you, but if you don't hear otherwise that is the signal we are looking for.

@kaizencc kaizencc assigned kaizencc and unassigned BenChaimberg Nov 22, 2021
@nikovirtala
Copy link
Contributor

nikovirtala commented Nov 24, 2021

@nikovirtala my quick understanding of the issue is that stable modules cannot depend on experimental modules; this is by design. In that sense, there is nothing to resolve. Instead, we are waiting for kinesis-firehose to be stabilized, in which case we can take another look at this PR. I will double-check for you, but if you don't hear otherwise that is the signal we are looking for.

It is not an option to release these changes as experimental too? – If that (release an experimental version of a currently stable package) is not possible we are going to find ourselves in this situation over and over again.

@kaizencc
Copy link
Contributor

kaizencc commented Dec 7, 2021

@nikovirtala we can release changes as experimental in a stable module by using the beta prefix (i.e. myExperimentalConstruct-Beta). However what we are talking about is having a stable module depend on an experimental one, which is a different ballgame (and not possible). It is possible to release this as an entirely new experimental construct that can then depend on both experimental and stable modules, but that is overkill here. I think it makes more sense to wait for kinesis-firehose to stabilize.

I am going to remove my assignment from this for now but feel free to ping me if you want my attention. When kinesis-firehose is stable I will revisit this PR.

@kaizencc kaizencc removed their assignment Dec 7, 2021
@aws-cdk-automation
Copy link
Collaborator

This PR has been in BUILD FAILING for 21 days, and looks abandoned. It will be closed in 10 days if no further commits are pushed to it.

@github-actions
Copy link

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@github-actions github-actions bot added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Apr 20, 2022
@github-actions github-actions bot closed this Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-logs-destinations closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p1 pr/blocked This PR cannot be merged or reviewed, because it is blocked for some reason.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants