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

Issue while creating alarm rule from alarms having space in their name #13953

Closed
somanshusingla opened this issue Apr 2, 2021 · 4 comments
Closed

Comments

@somanshusingla
Copy link
Contributor

❓ General Issue

The Question

I was creating composite alarm using alarm rule AlarmRule.anyOf(...alarms) where why alarms had space in their alarm name and got a issue like this:

    13:01:24 | CREATE_FAILED        | AWS::CloudWatch::CompositeAlarm | composite-1
    Error in AlarmRule [Unsupported token 'Oldest' at char 67, must be: ')'] (Service: AmazonCloudWatch; Status Code: 400
    ; Error Code: ValidationError; Request ID: 8d5ac86f-3017-4802-bf61-0113bb093c25; Proxy: null)
     
     
    const oldestAgeAlarm = new Alarm(this, 'oldest-age', {
          metric: oldestAgeMetric,
          evaluationPeriods: 5,
          threshold: 608000,
          alarmName: "SampleQueue Oldest Age Alarm",
          alarmDescription: "SampleQueue Oldest Age more than 608000",
          comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
          datapointsToAlarm: 3,
          actionsEnabled: false
        })
     
        const visibleMessageAlarm = new Alarm(this, 'visible-message', {
            metric: messagesVisibleMetric,
            evaluationPeriods: 5,
            threshold: 2000000,
            alarmName: "SampleQueue Visible Messages Alarm",
            alarmDescription: "SampleQueue Visible Messages more than 2000000",
            comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
            datapointsToAlarm: 3,
            actionsEnabled: false
        })
     
        new CompositeAlarm(this, 'composite-1', {
            compositeAlarmName: 'This is sample composite alarm',
            alarmRule: AlarmRule.anyOf(...[oldestAgeAlarm, visibleMessageAlarm]),
            
        })

Looks like this can be solved by introducing double quotes her: https://github.com/aws/aws-cdk/blob/v1.95.1/packages/@aws-cdk/aws-cloudwatch/lib/alarm-base.ts#L54

I had to write my own alarm rule to solve this like:

export class AlarmRuleOR implements IAlarmRule {
  readonly alarmRule: string;

  constructor(alarms: IAlarm[]) {
    this.alarmRule = alarms
      .map((alarm) => `ALARM("${alarm.alarmName}")`)
      .join(" OR ");
  }

  renderAlarmRule(): string {
    return this.alarmRule;
  }
}

Using double quotes in share code reference like this will solve the issue.

@somanshusingla
Copy link
Contributor Author

Creating a pull request for this.

@somanshusingla
Copy link
Contributor Author

somanshusingla commented Apr 2, 2021

Pull Request: #13963

mergify bot pushed a commit that referenced this issue Apr 29, 2021
#13963)

Issue: #13953

This change is to allow creation of composite alarms from alarms having spaces in their alarm name. 
Ref https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create_Composite_Alarm.html

For more details please check above mentioned issue.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
john-tipper pushed a commit to john-tipper/aws-cdk that referenced this issue May 10, 2021
aws#13963)

Issue: aws#13953

This change is to allow creation of composite alarms from alarms having spaces in their alarm name. 
Ref https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create_Composite_Alarm.html

For more details please check above mentioned issue.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@peterwoodworth
Copy link
Contributor

Thank you for contributing @S-T-O-C-H-A-S-T-I-C ! 😄

@github-actions
Copy link

⚠️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.

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
aws#13963)

Issue: aws#13953

This change is to allow creation of composite alarms from alarms having spaces in their alarm name. 
Ref https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Create_Composite_Alarm.html

For more details please check above mentioned issue.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants