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

fix(cloudwatch): move SNS Alarm Action to aws-cloudwatch-actions #2688

Merged
merged 9 commits into from
Jun 5, 2019
11 changes: 3 additions & 8 deletions packages/@aws-cdk/app-delivery/package-lock.json

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

8 changes: 2 additions & 6 deletions packages/@aws-cdk/assert/package-lock.json

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

22 changes: 6 additions & 16 deletions packages/@aws-cdk/assets-docker/package-lock.json

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

50 changes: 14 additions & 36 deletions packages/@aws-cdk/assets/package-lock.json

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

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cloudwatch = require('@aws-cdk/aws-cloudwatch');
import cdk = require('@aws-cdk/cdk');
import { CfnScalingPolicy } from './applicationautoscaling.generated';
import { IScalableTarget } from './scalable-target';
Expand Down Expand Up @@ -67,17 +66,12 @@ export interface StepScalingActionProps {
*
* This Action must be used as the target of a CloudWatch alarm to take effect.
*/
export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlarmAction {
export class StepScalingAction extends cdk.Construct {
/**
* ARN of the scaling policy
*/
public readonly scalingPolicyArn: string;

/**
* ARN when this scaling policy is used as an Alarm action
*/
public readonly alarmActionArn: string;

private readonly adjustments = new Array<CfnScalingPolicy.StepAdjustmentProperty>();

constructor(scope: cdk.Construct, id: string, props: StepScalingActionProps) {
Expand All @@ -100,7 +94,6 @@ export class StepScalingAction extends cdk.Construct implements cloudwatch.IAlar
});

this.scalingPolicyArn = resource.scalingPolicyArn;
this.alarmActionArn = this.scalingPolicyArn;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.lowerAlarm.addAlarmAction(this.lowerAction);
this.lowerAlarm.addAlarmAction(new StepScalingAlarmAction(this.lowerAction));
}

if (alarms.upperAlarmIntervalIndex !== undefined) {
Expand Down Expand Up @@ -138,7 +138,7 @@ export class StepScalingPolicy extends cdk.Construct {
evaluationPeriods: 1,
threshold,
});
this.upperAlarm.addAlarmAction(this.upperAction);
this.upperAlarm.addAlarmAction(new StepScalingAlarmAction(this.upperAction));
}
}
}
Expand Down Expand Up @@ -191,4 +191,22 @@ function aggregationTypeFromMetric(metric: cloudwatch.Metric): MetricAggregation
default:
throw new Error(`Cannot only scale on 'Minimum', 'Maximum', 'Average' metrics, got ${metric.statistic}`);
}
}
}

/**
* Use a StepScalingAction as an Alarm Action
*
* This class is here and not in aws-cloudwatch-actions because this library
* needs to use the class, and otherwise we'd have a circular dependency:
*
* aws-autoscaling -> aws-cloudwatch-actions (for using the Action)
* aws-cloudwatch-actions -> aws-autoscaling (for the definition of IStepScalingAction)
*/
class StepScalingAlarmAction implements cloudwatch.IAlarmAction {
constructor(private readonly stepScalingAction: StepScalingAction) {
}

public bind(_scope: cdk.Construct, _alarm: cloudwatch.IAlarm): cloudwatch.AlarmActionConfig {
return { alarmActionArn: this.stepScalingAction.scalingPolicyArn };
}
}
Loading