Skip to content

Commit f8f311d

Browse files
author
Eugene Cheung
authored
fix(dashboard): fix dynamic dashboard range (#436)
Fixes #430 --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent b04296a commit f8f311d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/dashboard/DynamicDashboardFactory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ export class DynamicDashboardFactory
8888
dashboardConfig.renderingPreference ??
8989
DashboardRenderingPreference.INTERACTIVE_ONLY;
9090
const start: string =
91-
"-" + (dashboardConfig.range ?? Duration.hours(8).toIsoString());
91+
"-" +
92+
(dashboardConfig.range?.toIsoString() ??
93+
Duration.hours(8).toIsoString());
9294

9395
const dashboard = this.createDashboard(
9496
renderingPreference,

test/dashboard/DynamicDashboardFactory.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stack } from "aws-cdk-lib";
1+
import { Duration, Stack } from "aws-cdk-lib";
22
import { Template } from "aws-cdk-lib/assertions";
33
import { IWidget, TextWidget } from "aws-cdk-lib/aws-cloudwatch";
44
import { DynamicDashboardFactory, IDynamicDashboardSegment } from "../../lib";
@@ -28,7 +28,7 @@ test("dynamic dashboards created", () => {
2828
dashboardNamePrefix: "testPrefix",
2929
dashboardConfigs: [
3030
{ name: TestDashboards.Dynamic1 },
31-
{ name: TestDashboards.Dynamic2 },
31+
{ name: TestDashboards.Dynamic2, range: Duration.days(7) },
3232
],
3333
});
3434

@@ -45,7 +45,7 @@ test("dynamic dashboards created", () => {
4545
DashboardName: "testPrefix-Dynamic1",
4646
});
4747
result.hasResourceProperties("AWS::CloudWatch::Dashboard", {
48-
DashboardBody: `{"start":"-PT8H","periodOverride":"inherit","widgets":[{"type":"text","width":6,"height":2,"x":0,"y":0,"properties":{"markdown":"Dynamic2"}}]}`,
48+
DashboardBody: `{"start":"-P7D","periodOverride":"inherit","widgets":[{"type":"text","width":6,"height":2,"x":0,"y":0,"properties":{"markdown":"Dynamic2"}}]}`,
4949
DashboardName: "testPrefix-Dynamic2",
5050
});
5151
});

0 commit comments

Comments
 (0)