feat(iot): add Action to capture CloudWatch metrics#17503
feat(iot): add Action to capture CloudWatch metrics#17503mergify[bot] merged 5 commits intoaws:masterfrom
Conversation
skinny85
left a comment
There was a problem hiding this comment.
Looks great as usual, @yamatatsu! A few minor comments.
packages/@aws-cdk/aws-iot-actions/lib/cloudwatch-metric-action.ts
Outdated
Show resolved
Hide resolved
| * @see https://docs.aws.amazon.com/iot/latest/developerguide/iot-substitution-templates.html | ||
| */ | ||
| readonly metricValue: string, | ||
| } |
There was a problem hiding this comment.
Can't we use the Metric class from the CloudWatch module instead of all these separate props here?
There was a problem hiding this comment.
@skinny85
I thought it too. But if using Metric class, we will not be able to use substitution templates.
So I think it is better that we provide fromMetric() method.
There was a problem hiding this comment.
Interesting... what's the problem that prevents using Metric with substitution templates?
There was a problem hiding this comment.
@skinny85
I had envisioned using Metric class as following.
const metric = new cloudwatch.Metric({
namespace: 'test-namespace',
metricName: 'test-name',
unit: cloudwatch.Unit.COUNT,
});
new CloudWatchPutMetricAction(metric, {
metricValue: '${temperature}',
metricTimestamp: '${timestamp}',
});In above case, I predicted that users might think "I cannot use substitution templates in namespace, metricName and unit".
Hmmm🤔. As I was writing this, I realized that there was nothing preventing from using substitution templates in properties besides unit as following.
const metric = new cloudwatch.Metric({
namespace: '${namespace}',
metricName: '${topic(2)}',
});I'm a little uncomfortable with it, in that substitution templates are written in Metric class props. How about?
And unit cannot be used with substitution templates because unit is enum in Metric.
There was a problem hiding this comment.
How common it is to use a dynamic Unit, do you think?
We can work around it by having something like:
new CloudWatchPutMetricAction(metric, {
dynamicUnit: `${sth}`,
});It is a little bit awkward, I agree.
There was a problem hiding this comment.
I think it's a pretty rare case that a unit is used dynamically.
For just one thing, How about this?
We keep current props, and we provide metric() method like metric-filter.ts.
Because, in many case, CloudWatchPutMetricAction will generate new custom metric for example temperature, weight and moisture. And alerms will be created with this metrics.
So I think users maybe will want metric after they make the topic rules.
packages/@aws-cdk/aws-iot-actions/lib/cloudwatch-metric-action.ts
Outdated
Show resolved
Hide resolved
| role.addToPrincipalPolicy(new iam.PolicyStatement({ | ||
| actions: ['cloudwatch:PutMetricData'], | ||
| resources: ['*'], | ||
| })); |
There was a problem hiding this comment.
Use the Metric.grantPutMetricData() method instead.
packages/@aws-cdk/aws-iot-actions/test/cloudwatch-metric/integ.cloudwatch-metric-action.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-iot-actions/test/cloudwatch-metric/integ.cloudwatch-metric-action.ts
Show resolved
Hide resolved
Pull request has been modified.
skinny85
left a comment
There was a problem hiding this comment.
Looks great @yamatatsu!
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
I'm trying to implement aws-iot L2 Constructs. This PR is one of steps after following PR: - aws#16681 (comment) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
I'm trying to implement aws-iot L2 Constructs. This PR is one of steps after following PR: - aws#16681 (comment) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
I'm trying to implement aws-iot L2 Constructs.
This PR is one of steps after following PR:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license