Repository: cdklabs/cdk-monitoring-constructs (language: python)

Issue:
[Lambda] Iterator age graph is missing from the lambda monitoring instance
### Version

v0.0.43

### Steps and/or minimal code example to reproduce

Hi there, 

Previously when adding a threshold for an iterator age on a lambda, the annotation for the iterator age would be added to the latency graph of the lambda. Although this was wrong and did not belong with the latency graph it was still useful. Please note: This was while using the internal version of the repo.

Is it possible to add a flag or something to display this graph on the detailed dashboard?

### Expected behavior

A widget with the iterator age and appropriate annotations will be displayed when a monitor is added for the iterator age on the lambda.

### Actual behavior

No graphs or annotations are added.

### Other details

_No response_


Discussion / hints:
Looks like we could add it as a third widget on the second row alongside the invocation and error count widgets. Does that seem reasonable to you?

https://github.com/cdklabs/cdk-monitoring-constructs/blob/main/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts#L483-L486
Yeah that is perfect.

Fix patch:
diff --git a/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts b/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts
index 625a5c8c..825b8c37 100644
--- a/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts
+++ b/lib/monitoring/aws-lambda/LambdaFunctionMonitoring.ts
@@ -37,7 +37,6 @@ import {
   ThirdWidth,
   TimeAxisMillisFromZero,
   TpsAlarmFactory,
-  TwoThirdsWidth,
   UsageAlarmFactory,
   UsageThreshold,
   UsageType,
@@ -129,6 +128,7 @@ export class LambdaFunctionMonitoring extends Monitoring {
   protected readonly tpsAnnotations: HorizontalAnnotation[];
   protected readonly cpuTotalTimeAnnotations: HorizontalAnnotation[];
   protected readonly memoryUsageAnnotations: HorizontalAnnotation[];
+  protected readonly maxIteratorAgeAnnotations: HorizontalAnnotation[];
 
   protected readonly tpsMetric: MetricWithAlarmSupport;
   protected readonly p50LatencyMetric: MetricWithAlarmSupport;
@@ -186,6 +186,7 @@ export class LambdaFunctionMonitoring extends Monitoring {
     this.tpsAnnotations = [];
     this.cpuTotalTimeAnnotations = [];
     this.memoryUsageAnnotations = [];
+    this.maxIteratorAgeAnnotations = [];
 
     this.metricFactory = new LambdaFunctionMetricFactory(
       scope.createMetricFactory(),
@@ -456,6 +457,7 @@ export class LambdaFunctionMonitoring extends Monitoring {
         alarmProps,
         disambiguator
       );
+      this.maxIteratorAgeAnnotations.push(createdAlarm.annotation);
       this.addAlarm(createdAlarm);
     }
 
@@ -481,7 +483,8 @@ export class LambdaFunctionMonitoring extends Monitoring {
         this.createRateWidget(QuarterWidth, DefaultGraphWidgetHeight)
       ),
       new Row(
-        this.createInvocationWidget(TwoThirdsWidth, DefaultGraphWidgetHeight),
+        this.createInvocationWidget(ThirdWidth, DefaultGraphWidgetHeight),
+        this.createIteratorAgeWidget(ThirdWidth, DefaultGraphWidgetHeight),
         this.createErrorCountWidget(ThirdWidth, DefaultGraphWidgetHeight)
       ),
     ];
@@ -594,6 +597,17 @@ export class LambdaFunctionMonitoring extends Monitoring {
     });
   }
 
+  protected createIteratorAgeWidget(width: number, height: number) {
+    return new GraphWidget({
+      width,
+      height,
+      title: "Iterator",
+      left: [this.maxIteratorAgeMetric],
+      leftYAxis: TimeAxisMillisFromZero,
+      leftAnnotations: this.maxIteratorAgeAnnotations,
+    });
+  }
+
   protected createLambdaInsightsCpuWidget(width: number, height: number) {
     return new GraphWidget({
       width,


Test patch:
diff --git a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
index ec6b7034..013af500 100644
--- a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
+++ b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
@@ -4088,7 +4088,7 @@ Object {
               Object {
                 "Ref": "DummyFunction3BB5AE03",
               },
-              "\\",{\\"label\\":\\"Provisioned Concurrency Spillovers (avg)\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":16,\\"height\\":5,\\"x\\":0,\\"y\\":6,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Invocations\\",\\"region\\":\\"",
+              "\\",{\\"label\\":\\"Provisioned Concurrency Spillovers (avg)\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Rate\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":0,\\"y\\":6,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Invocations\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -4108,7 +4108,15 @@ Object {
               Object {
                 "Ref": "DummyFunction3BB5AE03",
               },
-              "\\",{\\"label\\":\\"Provisioned Concurrency Spillovers\\",\\"stat\\":\\"Sum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":16,\\"y\\":6,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Errors\\",\\"region\\":\\"",
+              "\\",{\\"label\\":\\"Provisioned Concurrency Spillovers\\",\\"stat\\":\\"Sum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"Count\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":8,\\"y\\":6,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Iterator\\",\\"region\\":\\"",
+              Object {
+                "Ref": "AWS::Region",
+              },
+              "\\",\\"metrics\\":[[\\"AWS/Lambda\\",\\"IteratorAge\\",\\"FunctionName\\",\\"",
+              Object {
+                "Ref": "DummyFunction3BB5AE03",
+              },
+              "\\",{\\"label\\":\\"Iterator Age\\",\\"stat\\":\\"Maximum\\"}]],\\"yAxis\\":{\\"left\\":{\\"min\\":0,\\"label\\":\\"ms\\",\\"showUnits\\":false}}}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":5,\\"x\\":16,\\"y\\":6,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"Errors\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },