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(cloudwatch): added defaultInterval prop to cw-dashboard #24707

Merged
merged 3 commits into from
Mar 21, 2023

Conversation

pattasai
Copy link
Contributor

This PR adds defaultInterval to cloudwatch dashboard, which allows interval duration in relative time eg. 7 days.

const dashboard = cw.Dashboard(stack, 'Dash', {
      defaultInterval: cdk.Duration.days(7),
    });

Here, the dashboard would show the metrics for the last 7 days.

Closes #.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team March 20, 2023 19:18
@github-actions github-actions bot added the p2 label Mar 20, 2023
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 20, 2023
@pattasai pattasai requested a review from rix0rrr March 20, 2023 19:19
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@pattasai pattasai changed the title feat: added defaultInterval prop to cw-dashboard feat(aws-cloudwatch): added defaultInterval prop to cw-dashboard Mar 20, 2023
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

@pattasai looks great! Just a couple of cosmetic suggestions.

@@ -107,15 +115,19 @@ export class Dashboard extends Resource {
}
}

if (props.start !== undefined && props.defaultInterval !== undefined) {
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
if (props.start !== undefined && props.defaultInterval !== undefined) {
if (props.start && props.defaultInterval) {

Copy link
Contributor

Choose a reason for hiding this comment

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

In some cases it is safe to omit !== undefined, and in some cases it leads to bugs (for example, in the case of nullable integers, and occasionally in the case of nullable strings depending on what you want to do with the string).

When you're not super experienced yet, it's probably safer to always write !== undefined. So I support the current use.

const dashboard = new CfnDashboard(this, 'Resource', {
dashboardName: this.physicalName,
dashboardBody: Lazy.string({
produce: () => {
const column = new Column(...this.rows);
column.position(0, 0);
return Stack.of(this).toJsonString({
start: props.start,
end: props.end,
start: props.defaultInterval !== undefined ? `-${props.defaultInterval?.toIsoString()}` : props.start,
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
start: props.defaultInterval !== undefined ? `-${props.defaultInterval?.toIsoString()}` : props.start,
start: props.defaultInterval ? `-${props.defaultInterval?.toIsoString()}` : props.start,

Copy link
Contributor

@rix0rrr rix0rrr Mar 21, 2023

Choose a reason for hiding this comment

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

Here it would be safe to leave out, but also it doesn't hurt that much. Readability might be slightly better without.

start: props.start,
end: props.end,
start: props.defaultInterval !== undefined ? `-${props.defaultInterval?.toIsoString()}` : props.start,
end: props.defaultInterval !== undefined ? undefined : props.end,
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
end: props.defaultInterval !== undefined ? undefined : props.end,
end: props.defaultInterval ? undefined : props.end,

Copy link
Contributor

Choose a reason for hiding this comment

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

Here it would be safe to leave out, but also it doesn't hurt that much. Readability might be slightly better without.

@rix0rrr rix0rrr dismissed corymhall’s stale review March 21, 2023 14:06

Overruled by the senate, peace treaty signed :P

@pattasai pattasai changed the title feat(aws-cloudwatch): added defaultInterval prop to cw-dashboard feat(cloudwatch): added defaultInterval prop to cw-dashboard Mar 21, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 21, 2023 21:03

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@mergify
Copy link
Contributor

mergify bot commented Mar 21, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@pattasai pattasai self-assigned this Mar 21, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: a4d3a4d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit d4717cf into main Mar 21, 2023
@mergify mergify bot deleted the adding-defaultInterval-to-cloudwatch-dashboard branch March 21, 2023 21:46
@mergify
Copy link
Contributor

mergify bot commented Mar 21, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
This PR adds defaultInterval to cloudwatch dashboard, which allows interval duration in relative time eg. 7 days.

```ts
const dashboard = cw.Dashboard(stack, 'Dash', {
      defaultInterval: cdk.Duration.days(7),
    });
```
Here, the dashboard would show the metrics for the last 7 days.

> [CONTRIBUTING GUIDE]: https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md
> [DESIGN GUIDELINES]: https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md

Closes #<issue number here>.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants