-
Notifications
You must be signed in to change notification settings - Fork 4k
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(iot): add Action to capture CloudWatch metrics #17503
feat(iot): add Action to capture CloudWatch metrics #17503
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... what's the problem that prevents using Metric
with substitution templates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, sounds good.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the Metric.grantPutMetricData()
method instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
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
Outdated
Show resolved
Hide resolved
Pull request has been modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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