Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cloudwatch): Allow cross-region alarms #16351

Closed
Kyle-Thompson opened this issue Sep 2, 2021 · 2 comments
Closed

(cloudwatch): Allow cross-region alarms #16351

Kyle-Thompson opened this issue Sep 2, 2021 · 2 comments
Assignees
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.

Comments

@Kyle-Thompson
Copy link

I would like to be able to define alarms in one monitoring account to trigger based off of metrics from other accounts. It seems currently possible to create graphs from metrics from different accounts but not alarms.

Consider the following, functional piece of code:

        let avgMetrics = new Map();
        Object.keys(offsetDashboardNames).map((offset:string) => {
            avgMetrics.set(offset, new cloudwatch.MathExpression({
                expression: 'AVG([m1,m2,m3,m4,m5,m6,m7])',
                period: cdk.Duration.days(1),
                usingMetrics: {
                    "m1": offsetMetrics.get(offset)!.get(Regions[0])!,
                    "m2": offsetMetrics.get(offset)!.get(Regions[1])!,
                    "m3": offsetMetrics.get(offset)!.get(Regions[2])!,
                    "m4": offsetMetrics.get(offset)!.get(Regions[3])!,
                    "m5": offsetMetrics.get(offset)!.get(Regions[4])!,
                    "m6": offsetMetrics.get(offset)!.get(Regions[5])!,
                    "m7": offsetMetrics.get(offset)!.get(Regions[6])!,
                },
                color: '#000000',
                label: 'Aggregate'
            }))
        })

where Regions[i] represents an account id. This works but not when I try to add an alarm to trigger on any of these metrics falling below a threshold as shown here:

        let secondDay = offsetMetrics.get("-2")!;
        let alarm = new cloudwatch.MathExpression({
            expression: 'MIN([m1,m2,m3,m4,m5,m6,m7])',
            period: cdk.Duration.days(1),
            usingMetrics: {
                "m1": secondDay.get(Regions[0])!,
                "m2": secondDay.get(Regions[1])!,
                "m3": secondDay.get(Regions[2])!,
                "m4": secondDay.get(Regions[3])!,
                "m5": secondDay.get(Regions[4])!,
                "m6": secondDay.get(Regions[5])!,
                "m7": secondDay.get(Regions[6])!
            },
            color: '#000000',
            label: 'Aggregate'
        }).createAlarm(this, "DataAvailabilityAlarm", {
            evaluationPeriods: 1,
            threshold: 0.75,
            alarmDescription: "Do we have data from 2 days ago?",
            alarmName: "SufficientDataIngested",
            comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
            datapointsToAlarm: 1,
            treatMissingData: cloudwatch.TreatMissingData.MISSING
        })

I end up getting this error:

Using cdk out from cdk.json: /local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/build/cdk.out
/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:263
            throw new Error(`Cannot create an Alarm in region '${stack.region}' based on metric '${metric}' in '${stat.region}'`);
            ^

Error: Cannot create an Alarm in region 'us-east-1' based on metric 'AvailabilityRate' in 'ap-northeast-1'
    at Alarm.validateMetricStat (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:263:19)
    at Object.withStat (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:221:34)
    at Object.dispatchMetric (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/private/metric-util.js:115:20)
    at /local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:218:70
    at Array.map (<anonymous>)
    at Object.withExpression (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:218:43)
    at Object.dispatchMetric (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/private/metric-util.js:118:20)
    at Alarm.renderMetric (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:174:30)
    at new Alarm (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/alarm.js:63:34)
    at MathExpression.createAlarm (/local/home/thoakyl/workplace/fix_alarm/src/AwsApiMetricsWorkerDashboardsCDK/node_modules/monocdk/lib/aws-cloudwatch/lib/metric.js:371:16)

It seems odd that I'd be able to create graphs with metrics from other accounts but not alarms based on them.

Proposed Solution

At the moment I'm not aware of how this functionality could be implemented but I'm happy to get a workaround in the meantime.

@Kyle-Thompson Kyle-Thompson added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 2, 2021
@kaizencc kaizencc changed the title (CWL Dashboards): Allow cross-region alarms (cloudwatch): Allow cross-region alarms Sep 3, 2021
@github-actions github-actions bot added the @aws-cdk/aws-cloudwatch Related to Amazon CloudWatch label Sep 3, 2021
@kaizencc kaizencc assigned kaizencc and unassigned madeline-k Sep 3, 2021
@kaizencc
Copy link
Contributor

kaizencc commented Sep 3, 2021

Hi! According to the cloudwatch docs, you can create cross-account alarms but not cross-region ones. Cross-region seems to be only supported by graphs and dashboards at the moment.

With the CDK, you can create an alarm that monitors metrics in different accounts but the same region. Hope that helps!

@kaizencc kaizencc closed this as completed Sep 3, 2021
@github-actions
Copy link

github-actions bot commented Sep 3, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudwatch Related to Amazon CloudWatch feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants