-
Notifications
You must be signed in to change notification settings - Fork 4k
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
@aws-cdk/cloudwatch: bugfixes, small changes changes and workaround #194
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Arn, Construct, Token } from '@aws-cdk/core'; | ||
import { cloudwatch } from '@aws-cdk/resources'; | ||
import { HorizontalAnnotation } from './graph'; | ||
import { Metric } from './metric'; | ||
import { Dimension, Metric, parseStatistic, Statistic, Unit } from './metric'; | ||
|
||
/** | ||
* Properties for Alarms | ||
|
@@ -158,7 +158,7 @@ export class Alarm extends Construct { | |
okActions: new Token(() => this.okActions), | ||
|
||
// Metric | ||
...props.metric.toAlarmJson() | ||
...metricJson(props.metric) | ||
}); | ||
|
||
this.alarmArn = alarm.alarmArn; | ||
|
@@ -175,38 +175,38 @@ export class Alarm extends Construct { | |
* | ||
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy. | ||
*/ | ||
public onAlarm(action: IAlarmAction) { | ||
public onAlarm(...actions: IAlarmAction[]) { | ||
if (this.alarmActions === undefined) { | ||
this.alarmActions = []; | ||
} | ||
|
||
this.alarmActions.push(action.alarmActionArn); | ||
this.alarmActions.push(...actions.map(a => a.alarmActionArn)); | ||
} | ||
|
||
/** | ||
* Trigger this action if there is insufficient data to evaluate the alarm | ||
* | ||
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy. | ||
*/ | ||
public onInsufficientData(action: IAlarmAction) { | ||
public onInsufficientData(...actions: IAlarmAction[]) { | ||
if (this.insufficientDataActions === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
this.insufficientDataActions = []; | ||
} | ||
|
||
this.insufficientDataActions.push(action.alarmActionArn); | ||
this.insufficientDataActions.push(...actions.map(a => a.alarmActionArn)); | ||
} | ||
|
||
/** | ||
* Trigger this action if the alarm returns from breaching state into ok state | ||
* | ||
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy. | ||
*/ | ||
public onOk(action: IAlarmAction) { | ||
public onOk(...actions: IAlarmAction[]) { | ||
if (this.okActions === undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also here |
||
this.okActions = []; | ||
} | ||
|
||
this.okActions.push(action.alarmActionArn); | ||
this.okActions.push(...actions.map(a => a.alarmActionArn)); | ||
} | ||
|
||
/** | ||
|
@@ -256,4 +256,63 @@ export interface IAlarmAction { | |
* Return the ARN that should be used for a CloudWatch Alarm action | ||
*/ | ||
readonly alarmActionArn: Arn; | ||
} | ||
} | ||
|
||
/** | ||
* Return the JSON structure which represents the given metric in an alarm. | ||
*/ | ||
function metricJson(metric: Metric): AlarmMetricJson { | ||
const stat = parseStatistic(metric.statistic); | ||
|
||
const dims = metric.dimensionsAsList(); | ||
|
||
return { | ||
dimensions: dims.length > 0 ? dims : undefined, | ||
namespace: metric.namespace, | ||
metricName: metric.metricName, | ||
period: metric.periodSec, | ||
statistic: stat.type === 'simple' ? stat.statistic : undefined, | ||
extendedStatistic: stat.type === 'percentile' ? 'p' + stat.percentile : undefined, | ||
unit: metric.unit | ||
}; | ||
} | ||
|
||
/** | ||
* Properties used to construct the Metric identifying part of an Alarm | ||
*/ | ||
export interface AlarmMetricJson { | ||
/** | ||
* The dimensions to apply to the alarm | ||
*/ | ||
dimensions?: Dimension[]; | ||
|
||
/** | ||
* Namespace of the metric | ||
*/ | ||
namespace: string; | ||
|
||
/** | ||
* Name of the metric | ||
*/ | ||
metricName: string; | ||
|
||
/** | ||
* How many seconds to aggregate over | ||
*/ | ||
period: number; | ||
|
||
/** | ||
* Simple aggregation function to use | ||
*/ | ||
statistic?: Statistic; | ||
|
||
/** | ||
* Percentile aggregation function to use | ||
*/ | ||
extendedStatistic?: string; | ||
|
||
/** | ||
* The unit of the alarm | ||
*/ | ||
unit?: Unit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this can happen, since it's a variadic method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're thinking of the parameter. This is about the instance member.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh 🤦🏻♂️