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

Issue:
feat: allow specifying regions/accounts at a more granular level
This allows users to target different regions/account for specific things within a facade rather than relying on 1 facade per region/account with the facade's global settings, so something like:

```ts
this.facade
  .monitorDynamoTable({
    ...,
  })
  .monitorDynamoTable({
    ...,
    region: <some_other_region>,
    account: <some_other_account>,
  })
```

---

_By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_


Discussion / hints:

Fix patch:
diff --git a/API.md b/API.md
index 1e104104..2e8dafc3 100644
--- a/API.md
+++ b/API.md
@@ -13586,10 +13586,12 @@ const customMetricSearch: CustomMetricSearch = { ... }
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.dimensionsMap">dimensionsMap</a></code> | <code>{[ key: string ]: string}</code> | search dimensions (can be empty). |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.searchQuery">searchQuery</a></code> | <code>string</code> | search query (can be empty). |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.statistic">statistic</a></code> | <code><a href="#cdk-monitoring-constructs.MetricStatistic">MetricStatistic</a></code> | metric statistic. |
+| <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.account">account</a></code> | <code>string</code> | Account which this metric comes from. |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.label">label</a></code> | <code>string</code> | custom label for the metrics. |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.namespace">namespace</a></code> | <code>string</code> | metric namespace. |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.period">period</a></code> | <code>aws-cdk-lib.Duration</code> | metric period. |
 | <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.position">position</a></code> | <code><a href="#cdk-monitoring-constructs.AxisPosition">AxisPosition</a></code> | axis (right or left) on which to graph metric default: AxisPosition.LEFT. |
+| <code><a href="#cdk-monitoring-constructs.CustomMetricSearch.property.region">region</a></code> | <code>string</code> | Region which this metric comes from. |
 
 ---
 
@@ -13629,6 +13631,21 @@ metric statistic.
 
 ---
 
+##### `account`<sup>Optional</sup> <a name="account" id="cdk-monitoring-constructs.CustomMetricSearch.property.account"></a>
+
+```typescript
+public readonly account: string;
+```
+
+- *Type:* string
+- *Default:* Deployment account.
+
+Account which this metric comes from.
+
+Note that alarms cannot be created for cross-account metrics.
+
+---
+
 ##### `label`<sup>Optional</sup> <a name="label" id="cdk-monitoring-constructs.CustomMetricSearch.property.label"></a>
 
 ```typescript
@@ -13680,6 +13697,21 @@ axis (right or left) on which to graph metric default: AxisPosition.LEFT.
 
 ---
 
+##### `region`<sup>Optional</sup> <a name="region" id="cdk-monitoring-constructs.CustomMetricSearch.property.region"></a>
+
+```typescript
+public readonly region: string;
+```
+
+- *Type:* string
+- *Default:* Deployment region.
+
+Region which this metric comes from.
+
+Note that alarms cannot be created for cross-region metrics.
+
+---
+
 ### CustomMetricWithAlarm <a name="CustomMetricWithAlarm" id="cdk-monitoring-constructs.CustomMetricWithAlarm"></a>
 
 Custom metric with an alarm defined.
diff --git a/lib/monitoring/custom/CustomMonitoring.ts b/lib/monitoring/custom/CustomMonitoring.ts
index f736ec25..74aa7839 100644
--- a/lib/monitoring/custom/CustomMonitoring.ts
+++ b/lib/monitoring/custom/CustomMonitoring.ts
@@ -127,6 +127,22 @@ export interface CustomMetricSearch {
    * default: AxisPosition.LEFT
    */
   readonly position?: AxisPosition;
+
+  /**
+   * Account which this metric comes from.
+   * Note that alarms cannot be created for cross-account metrics.
+   *
+   * @default - Deployment account.
+   */
+  readonly account?: string;
+
+  /**
+   * Region which this metric comes from.
+   * Note that alarms cannot be created for cross-region metrics.
+   *
+   * @default - Deployment region.
+   */
+  readonly region?: string;
 }
 
 /**
@@ -482,6 +498,8 @@ export class CustomMonitoring extends Monitoring {
           metric.namespace,
           metric.label,
           metric.period,
+          metric.region,
+          metric.account,
         );
       } else {
         // general metric


Test patch:
diff --git a/test/monitoring/custom/CustomMonitoring.test.ts b/test/monitoring/custom/CustomMonitoring.test.ts
index 2888e240..e11929e0 100644
--- a/test/monitoring/custom/CustomMonitoring.test.ts
+++ b/test/monitoring/custom/CustomMonitoring.test.ts
@@ -44,7 +44,13 @@ test("snapshot test", () => {
           // regular metric
           new Metric({ metricName: "DummyMetric1", namespace, dimensionsMap }),
           // metric with alarm
-          new Metric({ metricName: "DummyMetric2", namespace, dimensionsMap }),
+          new Metric({
+            metricName: "DummyMetric2",
+            namespace,
+            dimensionsMap,
+            account: "01234567890",
+            region: "us-west-2",
+          }),
           {
             metric: new Metric({
               metricName: "DummyMetric3",
@@ -71,6 +77,14 @@ test("snapshot test", () => {
             dimensionsMap,
             statistic: MetricStatistic.SUM,
           },
+          {
+            searchQuery: "DummyMetric5-",
+            namespace,
+            dimensionsMap,
+            statistic: MetricStatistic.SUM,
+            account: "01234567890",
+            region: "us-west-2",
+          },
         ],
       },
       {
diff --git a/test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap b/test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap
index efa55fc6..ca5f9f20 100644
--- a/test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap
+++ b/test/monitoring/custom/__snapshots__/CustomMonitoring.test.ts.snap
@@ -652,7 +652,7 @@ Object {
               Object {
                 "Ref": "AWS::Region",
               },
-              "\\",\\"metrics\\":[[\\"DummyCustomNamespace\\",\\"DummyMetric1\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric2\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric3\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric4-', 'Sum', 300)\\"}]],\\"annotations\\":{\\"horizontal\\":[{\\"label\\":\\"DummyMetric3 < 90 for 3 datapoints within 15 minutes\\",\\"value\\":90,\\"yAxis\\":\\"left\\"},{\\"label\\":\\"DummyMetric3 < 50 for 3 datapoints within 15 minutes\\",\\"value\\":50,\\"yAxis\\":\\"left\\"}]},\\"yAxis\\":{}}},{\\"type\\":\\"metric\\",\\"width\\":2,\\"height\\":100,\\"x\\":6,\\"y\\":3,\\"properties\\":{\\"view\\":\\"bar\\",\\"title\\":\\"DummyGroup2\\",\\"region\\":\\"",
+              "\\",\\"metrics\\":[[\\"DummyCustomNamespace\\",\\"DummyMetric1\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric2\\",\\"CustomDimension\\",\\"CustomDimensionValue\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}],[\\"DummyCustomNamespace\\",\\"DummyMetric3\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric4-', 'Sum', 300)\\"}],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric5-', 'Sum', 300)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}]],\\"annotations\\":{\\"horizontal\\":[{\\"label\\":\\"DummyMetric3 < 90 for 3 datapoints within 15 minutes\\",\\"value\\":90,\\"yAxis\\":\\"left\\"},{\\"label\\":\\"DummyMetric3 < 50 for 3 datapoints within 15 minutes\\",\\"value\\":50,\\"yAxis\\":\\"left\\"}]},\\"yAxis\\":{}}},{\\"type\\":\\"metric\\",\\"width\\":2,\\"height\\":100,\\"x\\":6,\\"y\\":3,\\"properties\\":{\\"view\\":\\"bar\\",\\"title\\":\\"DummyGroup2\\",\\"region\\":\\"",
               Object {
                 "Ref": "AWS::Region",
               },
@@ -907,7 +907,7 @@ Min number of samples to alarm: 5",
               Object {
                 "Ref": "AWS::Region",
               },
-              "\\",\\"metrics\\":[[\\"DummyCustomNamespace\\",\\"DummyMetric1\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric2\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric3\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric4-', 'Sum', 300)\\"}]],\\"annotations\\":{\\"horizontal\\":[{\\"label\\":\\"DummyMetric3 < 90 for 3 datapoints within 15 minutes\\",\\"value\\":90,\\"yAxis\\":\\"left\\"},{\\"label\\":\\"DummyMetric3 < 50 for 3 datapoints within 15 minutes\\",\\"value\\":50,\\"yAxis\\":\\"left\\"}]},\\"yAxis\\":{}}}]}",
+              "\\",\\"metrics\\":[[\\"DummyCustomNamespace\\",\\"DummyMetric1\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[\\"DummyCustomNamespace\\",\\"DummyMetric2\\",\\"CustomDimension\\",\\"CustomDimensionValue\\",{\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}],[\\"DummyCustomNamespace\\",\\"DummyMetric3\\",\\"CustomDimension\\",\\"CustomDimensionValue\\"],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric4-', 'Sum', 300)\\"}],[{\\"label\\":\\" \\",\\"expression\\":\\"SEARCH('{DummyCustomNamespace,CustomDimension} CustomDimension=\\\\\\"CustomDimensionValue\\\\\\" DummyMetric5-', 'Sum', 300)\\",\\"accountId\\":\\"01234567890\\",\\"region\\":\\"us-west-2\\"}]],\\"annotations\\":{\\"horizontal\\":[{\\"label\\":\\"DummyMetric3 < 90 for 3 datapoints within 15 minutes\\",\\"value\\":90,\\"yAxis\\":\\"left\\"},{\\"label\\":\\"DummyMetric3 < 50 for 3 datapoints within 15 minutes\\",\\"value\\":50,\\"yAxis\\":\\"left\\"}]},\\"yAxis\\":{}}}]}",
             ],
           ],
         },