-
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(cloudwatch): added defaultInterval prop to cw-dashboard #24707
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
import { Lazy, Resource, Stack, Token, Annotations } from '@aws-cdk/core'; | ||||||
import { Lazy, Resource, Stack, Token, Annotations, Duration } from '@aws-cdk/core'; | ||||||
import { Construct } from 'constructs'; | ||||||
import { CfnDashboard } from './cloudwatch.generated'; | ||||||
import { Column, Row } from './layout'; | ||||||
|
@@ -31,6 +31,14 @@ export interface DashboardProps { | |||||
*/ | ||||||
readonly dashboardName?: string; | ||||||
|
||||||
/** | ||||||
* Interval duration for metrics. | ||||||
* You can specify defaultInterval with the relative time(eg. cdk.Duration.days(7)). | ||||||
* | ||||||
* @default When the dashboard loads, the defaultInterval time will be the default time range. | ||||||
*/ | ||||||
readonly defaultInterval?: Duration | ||||||
|
||||||
/** | ||||||
* The start of the time range to use for each widget on the dashboard. | ||||||
* You can specify start without specifying end to specify a relative time range that ends with the current time. | ||||||
|
@@ -107,15 +115,19 @@ export class Dashboard extends Resource { | |||||
} | ||||||
} | ||||||
|
||||||
if (props.start !== undefined && props.defaultInterval !== undefined) { | ||||||
throw ('both properties defaultInterval and start cannot be set at once'); | ||||||
} | ||||||
|
||||||
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, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
end: props.defaultInterval !== undefined ? undefined : props.end, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
periodOverride: props.periodOverride, | ||||||
widgets: column.toJson(), | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"30.0.0"} | ||
{"version":"31.0.0"} |
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.
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.
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.