Skip to content

Commit 01ceb2a

Browse files
vohomergify[bot]
andauthored
feat(custom): add height property to .monitorCustom() (#261)
Allows users to set a custom height for custom monitoring. Useful for different graph types or very big search queries. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_ Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 61b36ba commit 01ceb2a

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

API.md

Lines changed: 47 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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,24 @@ export interface CustomMetricGroup {
191191
}
192192

193193
export interface CustomMonitoringProps extends BaseMonitoringProps {
194+
/**
195+
* optional description of the whole section, in markdown
196+
* @default no description
197+
*/
194198
readonly description?: string;
199+
/**
200+
* optional height of the description widget, so the content fits
201+
* @default minimum height (should fit one or two lines of text)
202+
*/
195203
readonly descriptionWidgetHeight?: number;
204+
/**
205+
* height override
206+
* @default default height
207+
*/
208+
readonly height?: number;
209+
/**
210+
* define metric groups and metrics inside them (each metric group represents a widget)
211+
*/
196212
readonly metricGroups: CustomMetricGroup[];
197213
}
198214

@@ -201,6 +217,7 @@ export interface CustomMetricGroupWithAnnotations {
201217
readonly annotations: HorizontalAnnotation[];
202218
readonly rightAnnotations: HorizontalAnnotation[];
203219
readonly titleAddons: string[];
220+
readonly height?: number;
204221
}
205222

206223
/**
@@ -214,6 +231,7 @@ export class CustomMonitoring extends Monitoring {
214231
readonly title: string;
215232
readonly description?: string;
216233
readonly descriptionWidgetHeight?: number;
234+
readonly height?: number;
217235
readonly customAlarmFactory: CustomAlarmFactory;
218236
readonly anomalyDetectingAlarmFactory: AnomalyDetectingAlarmFactory;
219237
readonly metricGroups: CustomMetricGroupWithAnnotations[];
@@ -226,6 +244,7 @@ export class CustomMonitoring extends Monitoring {
226244

227245
this.description = props.description;
228246
this.descriptionWidgetHeight = props.descriptionWidgetHeight;
247+
this.height = props.height;
229248

230249
const alarmFactory = this.createAlarmFactory(
231250
namingStrategy.resolveAlarmFriendlyName()
@@ -257,7 +276,7 @@ export class CustomMonitoring extends Monitoring {
257276
metricGroup.metrics.forEach((metric) => {
258277
if (this.hasAlarm(metric) && this.hasAnomalyDetection(metric)) {
259278
throw new Error(
260-
"Adding both a regular alarm and an anomoly detection alarm at the same time is not supported"
279+
"Adding both a regular alarm and an anomaly detection alarm at the same time is not supported"
261280
);
262281
}
263282

@@ -338,6 +357,11 @@ export class CustomMonitoring extends Monitoring {
338357
const metricGroupWidgetWidth = recommendedWidgetWidth(
339358
annotatedGroups.length
340359
);
360+
const metricGroupWidgetHeightDefault = summary
361+
? DefaultSummaryWidgetHeight
362+
: DefaultGraphWidgetHeight;
363+
const metricGroupWidgetHeight =
364+
this.height ?? metricGroupWidgetHeightDefault;
341365

342366
annotatedGroups.forEach((annotatedGroup) => {
343367
const metrics = annotatedGroup.metricGroup.metrics;
@@ -367,7 +391,7 @@ export class CustomMonitoring extends Monitoring {
367391
const graphWidgetProps: GraphWidgetProps = {
368392
title,
369393
width: metricGroupWidgetWidth,
370-
height: summary ? DefaultSummaryWidgetHeight : DefaultGraphWidgetHeight,
394+
height: metricGroupWidgetHeight,
371395
left,
372396
right,
373397
leftAnnotations: annotatedGroup.annotations,

test/monitoring/custom/CustomMonitoring.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ test("snapshot test", () => {
3333
description:
3434
"This is a very long description.\nSecond line of this very long description.\nThird line of this very long description.",
3535
descriptionWidgetHeight: 2,
36+
height: 100,
3637
metricGroups: [
3738
{
3839
title: "DummyGroup1",
@@ -436,6 +437,6 @@ test("throws error if attempting to add both a regular alarm and an anomoly dete
436437
],
437438
})
438439
).toThrow(
439-
"Adding both a regular alarm and an anomoly detection alarm at the same time is not supported"
440+
"Adding both a regular alarm and an anomaly detection alarm at the same time is not supported"
440441
);
441442
});

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

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

0 commit comments

Comments
 (0)