Skip to content

Commit

Permalink
fix(dashboard): fix dynamic dashboard range (#436)
Browse files Browse the repository at this point in the history
Fixes #430

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
  • Loading branch information
echeung-amzn authored Sep 28, 2023
1 parent b04296a commit f8f311d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/dashboard/DynamicDashboardFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class DynamicDashboardFactory
dashboardConfig.renderingPreference ??
DashboardRenderingPreference.INTERACTIVE_ONLY;
const start: string =
"-" + (dashboardConfig.range ?? Duration.hours(8).toIsoString());
"-" +
(dashboardConfig.range?.toIsoString() ??
Duration.hours(8).toIsoString());

const dashboard = this.createDashboard(
renderingPreference,
Expand Down
6 changes: 3 additions & 3 deletions test/dashboard/DynamicDashboardFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack } from "aws-cdk-lib";
import { Duration, Stack } from "aws-cdk-lib";
import { Template } from "aws-cdk-lib/assertions";
import { IWidget, TextWidget } from "aws-cdk-lib/aws-cloudwatch";
import { DynamicDashboardFactory, IDynamicDashboardSegment } from "../../lib";
Expand Down Expand Up @@ -28,7 +28,7 @@ test("dynamic dashboards created", () => {
dashboardNamePrefix: "testPrefix",
dashboardConfigs: [
{ name: TestDashboards.Dynamic1 },
{ name: TestDashboards.Dynamic2 },
{ name: TestDashboards.Dynamic2, range: Duration.days(7) },
],
});

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

0 comments on commit f8f311d

Please sign in to comment.