logs: SubscriptionFilter does not provide metric* helpers
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
The [AWS Logs SubscriptionFilter](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.SubscriptionFilter.html) construct should provide `metric*` methods that CDK resources typically provide. See for example:
* [CDK metric objects documentation](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-cloudwatch-readme.html#metric-objects)
* [CDK Lambda `Function#metrics*` methods](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html#metricmetricname-props)
### Use Case
All `SubscriptionFilter` metrics (e.g. see `ForwardedLogEvents`, `DeliveryErrors`, `DeliveryThrottling` in the [Monitoring AWS Logs with CloudWatch Metrics](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch-Logs-Monitoring-CloudWatch-Metrics.html) docs) requires some dimensions to be specified:
* `LogGroupName`
* `DestinationType`
* `FilterName`
The first two are easy to specify since the `LogGroupName` is also required while creating the construct and `DestinationType` a service name (e.g. `Lambda`). However, there appears to be no way to get `FilterName` using CDK:
* The CDK construct (and the underlying CloudFormation resource: [AWS::Logs::SubscriptionFilter](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.CfnSubscriptionFilter.html)) does not let me specify the `FilterName` - so it can't be directly specified ( and is always dynamically generated).
* There are no [properties on the SubscriptionFilter object](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.SubscriptionFilter.html#properties) that will return this.
* In fact, unlike most other CDK constructs, this one seems pretty bare and returns absolutely no information about the resource.
* The synthesized `FilterName` is like `MyStackName-MyLogicalID29669D87-GCMA0Q4KKALH` (in CloudFormation): so it can't directly be specified using a `Fn.ref` (since the logicalId for CDK constructs is dynamic). Possibly related to: https://github.com/aws/aws-cdk-rfcs/issues/162.
### Proposed Solution
* Please provide `metric*` methods on [SubscriptionFilter](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.SubscriptionFilter.html) construct.
* Also provide properties on the `SubscriptionFilter` construct to get references to properties, such as the related `logGroup` (which is required as a constructor argument), like most CDK constructs.
### Other
For more details, see this [StackOverflow question](https://stackoverflow.com/q/61927995/117750).
As shown in the SO post above, a possible workaround is to use the [Stack#getLogicalId](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Stack.html#get-wbr-logical-wbr-idelement) method.
* [ ] :wave: I may be able to implement this feature request
* [ ] :warning: This feature might incur a breaking change
---
This is a :rocket: Feature Request
Contributor guide
Research direction
Start with the AWS Logs SubscriptionFilter construct and its underlying CfnSubscriptionFilter resource, then compare the metric* entry points on the CDK Lambda Function construct. Check the Stack#getLogicalId workaround and the linked AWS CloudWatch metric documentation. Done means SubscriptionFilter exposes the requested metric helpers and references such as its related log group.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100