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

Issue:
ApiGatewayV2HttpApimonitoring should respect humanReadableName parameter
### Version

v1.24.1

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

1. Monitor an api gateway with humanReadableName supplied
```
monitorApiGatewayV2HttpApi({
   humanReadableName: "example-name"
})
```


### Expected behavior

We should have the humanReadableName provided being used in the dashboards. Sometimes I don't want the default behavior of the API ID and stage name in the dashboard name.

Dashboard name should be whatever I supplied in human readable name

### Actual behavior

The humanReadableName supplied gets ignored. Dashboard name currently is the default of
```
 `${props.api.apiId} ${props.apiStage ?? "$default"} ${
        props.apiMethod ?? ""
      } ${props.apiResource ?? ""}`,
```

### Other details

## Proposed Solution
Simply change [lines](https://github.com/cdklabs/cdk-monitoring-constructs/blob/main/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts#L140-L142) from
```
humanReadableName: `${props.api.apiId} ${props.apiStage ?? "$default"} ${
        props.apiMethod ?? ""
      } ${props.apiResource ?? ""}`,
```
to
```
humanReadableName: props.humanReadableName ?? `${props.api.apiId} ${props.apiStage ?? "$default"} ${
        props.apiMethod ?? ""
      } ${props.apiResource ?? ""}`,
```

I'll try to open a PR to address this as it a very small change.


Discussion / hints:

Fix patch:
diff --git a/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts b/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts
index e107b49c..375d526e 100644
--- a/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts
+++ b/lib/monitoring/aws-apigatewayv2/ApiGatewayV2HttpApiMonitoring.ts
@@ -115,10 +115,8 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
   readonly errorRateAnnotations: HorizontalAnnotation[];
 
   readonly tpsMetric: MetricWithAlarmSupport;
-
   readonly error4xxCountMetric: MetricWithAlarmSupport;
   readonly error4xxRateMetric: MetricWithAlarmSupport;
-
   readonly error5xxCountMetric: MetricWithAlarmSupport;
   readonly error5xxRateMetric: MetricWithAlarmSupport;
 
@@ -133,13 +131,23 @@ export class ApiGatewayV2HttpApiMonitoring extends Monitoring {
   ) {
     super(scope, props);
 
+    // used when humanReadableName is not provided by user
+    const fallbackNameArray = [props.api.apiId];
+    fallbackNameArray.push(props.apiStage ?? "$default");
+    if (props.apiMethod) {
+      fallbackNameArray.push(props.apiMethod);
+    }
+    if (props.apiResource) {
+      fallbackNameArray.push(props.apiResource);
+    }
+
     const namingStrategy = new MonitoringNamingStrategy({
       ...props,
       namedConstruct: props.api,
-      fallbackConstructName: props.api.apiId,
-      humanReadableName: `${props.api.apiId} ${props.apiStage ?? "$default"} ${
-        props.apiMethod ?? ""
-      } ${props.apiResource ?? ""}`,
+      fallbackConstructName: fallbackNameArray
+        .join("-")
+        .replace(/[^a-zA-Z0-9-_]/g, ""),
+      humanReadableName: props.humanReadableName ?? fallbackNameArray.join(" "),
     });
 
     this.title = namingStrategy.resolveHumanReadableName();


Test patch:
diff --git a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
index 5b716ba5..fc550b1d 100644
--- a/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
+++ b/test/facade/__snapshots__/MonitoringAspect.test.ts.snap
@@ -346,7 +346,7 @@ Object {
               Object {
                 "Ref": "DummyHttpApi8EEBCC85",
               },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              " $default**\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -424,7 +424,7 @@ Object {
               Object {
                 "Ref": "DummyHttpApi8EEBCC85",
               },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              " $default**\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
diff --git a/test/monitoring/aws-apigatewayv2/__snapshots__/ApiGatewayV2HttpApiMonitoring.test.ts.snap b/test/monitoring/aws-apigatewayv2/__snapshots__/ApiGatewayV2HttpApiMonitoring.test.ts.snap
index 4269d0b4..40bb0cb5 100644
--- a/test/monitoring/aws-apigatewayv2/__snapshots__/ApiGatewayV2HttpApiMonitoring.test.ts.snap
+++ b/test/monitoring/aws-apigatewayv2/__snapshots__/ApiGatewayV2HttpApiMonitoring.test.ts.snap
@@ -447,11 +447,7 @@ Object {
           "Fn::Join": Array [
             "",
             Array [
-              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **",
-              Object {
-                "Ref": "testHttpApiC57B300F",
-              },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **Dummy API Gateway for testing**\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -2158,11 +2154,7 @@ Object {
           "Fn::Join": Array [
             "",
             Array [
-              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **",
-              Object {
-                "Ref": "testHttpApiC57B300F",
-              },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **Dummy API Gateway for testing**\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -2391,11 +2383,7 @@ Object {
           "Fn::Join": Array [
             "",
             Array [
-              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **",
-              Object {
-                "Ref": "testHttpApiC57B300F",
-              },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **Dummy API Gateway for testing**\\"}},{\\"type\\":\\"metric\\",\\"width\\":6,\\"height\\":5,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -2468,11 +2456,7 @@ Object {
           "Fn::Join": Array [
             "",
             Array [
-              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **",
-              Object {
-                "Ref": "testHttpApiC57B300F",
-              },
-              " $default  **\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
+              "{\\"widgets\\":[{\\"type\\":\\"text\\",\\"width\\":24,\\"height\\":1,\\"x\\":0,\\"y\\":0,\\"properties\\":{\\"markdown\\":\\"### API Gateway V2 HTTP Endpoint **Dummy API Gateway for testing**\\"}},{\\"type\\":\\"metric\\",\\"width\\":8,\\"height\\":6,\\"x\\":0,\\"y\\":1,\\"properties\\":{\\"view\\":\\"timeSeries\\",\\"title\\":\\"TPS\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },