Skip to content

Commit

Permalink
feat(custom): handle cross-account/cross-region search expressions fo…
Browse files Browse the repository at this point in the history
…r dashboards (#551)

Building on top of #533, but `monitorCustom` has its own API for
simplifying search expression queries so we need to explicitly handle
it.

Regular `new Metric(...)` calls just pass in the `account`/`metric` via
that API.

---

_By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license_
  • Loading branch information
echeung-amzn authored Aug 1, 2024
1 parent 704d864 commit 839d06f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
32 changes: 32 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions lib/monitoring/custom/CustomMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -482,6 +498,8 @@ export class CustomMonitoring extends Monitoring {
metric.namespace,
metric.label,
metric.period,
metric.region,
metric.account,
);
} else {
// general metric
Expand Down
16 changes: 15 additions & 1 deletion test/monitoring/custom/CustomMonitoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -71,6 +77,14 @@ test("snapshot test", () => {
dimensionsMap,
statistic: MetricStatistic.SUM,
},
{
searchQuery: "DummyMetric5-",
namespace,
dimensionsMap,
statistic: MetricStatistic.SUM,
account: "01234567890",
region: "us-west-2",
},
],
},
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 839d06f

Please sign in to comment.