Skip to content

Commit 8f413ed

Browse files
author
Eugene Cheung
authored
feat(custom): use addToSummaryDashboard from CustomMonitoringProps if not specified in metric groups (#278)
It's confusing that the top-level `addToSummaryDashboard` didn't do anything. This is now the lowest-precedence way to add things to the summary dashboard. This still defaults to `false` to maintain existing behaviour. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 8d01b3c commit 8f413ed

File tree

4 files changed

+127
-8
lines changed

4 files changed

+127
-8
lines changed

API.md

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/monitoring/custom/CustomMonitoring.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,12 @@ export interface CustomMetricGroup {
171171
readonly graphWidgetLegend?: LegendPosition;
172172
/**
173173
* @deprecated use addToSummaryDashboard. addToSummaryDashboard will take precedence over important.
174-
* Flag indicating, whether this is an important metric group that should be included in the summary as well.
175-
* @default false
174+
* @see addToSummaryDashboard
176175
*/
177176
readonly important?: boolean;
178177
/**
179178
* Flag indicating this metric group should be included in the summary as well.
180-
* @default false
179+
* @default - addToSummaryDashboard from CustomMonitoringProps, defaulting to false
181180
*/
182181
readonly addToSummaryDashboard?: boolean;
183182
/**
@@ -238,6 +237,7 @@ export class CustomMonitoring extends Monitoring {
238237
readonly description?: string;
239238
readonly descriptionWidgetHeight?: number;
240239
readonly height?: number;
240+
readonly addToSummaryDashboard: boolean;
241241
readonly customAlarmFactory: CustomAlarmFactory;
242242
readonly anomalyDetectingAlarmFactory: AnomalyDetectingAlarmFactory;
243243
readonly metricGroups: CustomMetricGroupWithAnnotations[];
@@ -251,6 +251,7 @@ export class CustomMonitoring extends Monitoring {
251251
this.description = props.description;
252252
this.descriptionWidgetHeight = props.descriptionWidgetHeight;
253253
this.height = props.height;
254+
this.addToSummaryDashboard = props.addToSummaryDashboard ?? false;
254255

255256
const alarmFactory = this.createAlarmFactory(
256257
namingStrategy.resolveAlarmFriendlyName()
@@ -313,7 +314,7 @@ export class CustomMonitoring extends Monitoring {
313314
(group) =>
314315
group.metricGroup.addToSummaryDashboard ??
315316
group.metricGroup.important ??
316-
false
317+
this.addToSummaryDashboard
317318
)
318319
: this.metricGroups;
319320

test/monitoring/custom/CustomMonitoring.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,34 @@ test("addToSummaryDashboard attribute takes precedence over important in metric
189189
metricGroups: [
190190
{
191191
title: "DummyGroup1",
192-
important: false,
193192
addToSummaryDashboard: true,
193+
important: false,
194+
metrics: [
195+
// regular metric
196+
new Metric({ metricName: "DummyMetric1", namespace, dimensionsMap }),
197+
],
198+
},
199+
],
200+
});
201+
202+
addMonitoringDashboardsToStack(stack, monitoring);
203+
expect(Template.fromStack(stack)).toMatchSnapshot();
204+
});
205+
206+
test("addToSummaryDashboard attribute takes value from CustomMonitoringProps if not specified in metric group", () => {
207+
const stack = new Stack();
208+
const scope = new TestMonitoringScope(stack, "Scope");
209+
210+
const monitoring = new CustomMonitoring(scope, {
211+
alarmFriendlyName: "DummyAlarmName",
212+
humanReadableName: "DummyName",
213+
description: "Monitoring widget that shows up in the summary dashboard",
214+
descriptionWidgetHeight: 2,
215+
height: 100,
216+
addToSummaryDashboard: true,
217+
metricGroups: [
218+
{
219+
title: "DummyGroup1",
194220
metrics: [
195221
// regular metric
196222
new Metric({ metricName: "DummyMetric1", namespace, dimensionsMap }),

test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)