cdklabs / cdk-monitoring-constructs

Easy-to-use CDK constructs for monitoring your AWS infrastructure
https://constructs.dev/packages/cdk-monitoring-constructs
Apache License 2.0
468 stars 61 forks source link

[billing] MonitorBilling - addTotalCostAnomalyAlarm Fails to Deploy Stack #332

Open zqumei0 opened 1 year ago

zqumei0 commented 1 year ago

Version

6.2.4

Steps and/or minimal code example to reproduce

Create a monitoring facade and then execute monitorBilling() with addTotalCostAnomalyAlarm

export interface MonitoringStackProps {
  readonly stackName: string
}

export class MonitoringStack extends Stack {
  readonly monitoringFacade: MonitoringFacade
  readonly props: MonitoringStackProps

  constructor(scope: App, id: string, props: MonitoringStackProps) {
    super(scope, id, props)
    this.props = props

    this.monitoringFacade = this.createMonitoringFacade()
  }

  private createMonitoringFacade() : MonitoringFacade {
    return new MonitoringFacade(this, `CdkMonitoringTestApp-MonitoringFacade`, {
      alarmFactoryDefaults: {
        actionsEnabled: false,
        alarmNamePrefix: `CdkMonitoringTestAppAlarm`
      },
      dashboardFactory: new DefaultDashboardFactory(this, `CdkMonitoringTestApp-DashboardFactory`, {
        createAlarmDashboard: true,
        createDashboard: true,
        createSummaryDashboard: true,
        dashboardNamePrefix: `CdkMonitoringTestApp-DashboardFactory`
      })
    })
  }

  public monitorAccountBilling() : void {
    this.monitoringFacade.monitorBilling({
      addToAlarmDashboard: true,
      addToDetailDashboard: true,
      addToSummaryDashboard: true,
      addTotalCostAnomalyAlarm: {
        Warning: {
          alarmWhenAboveTheBand: true,
          alarmWhenBelowTheBand: true,
          standardDeviationForAlarm: 0.5,
        }
      }
    })
  }

Expected behavior

This should create a dashboard on billing and an alarm to detect anomaly on total cost

Actual behavior

A runtime error during a cdk deploy that leads to the error below:

8:54:06 PM | CREATE_FAILED        | AWS::CloudWatch::Alarm     | CdkMonitoringTestA...alyWarning970F670F
ComparisonOperators for ranges require ThresholdMetricId to be set (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError; Request ID: 678402c0-da06-4c56-a222-295dbe54bf74; Proxy: null)

Stack Deployments Failed: Error: The stack named CdkMonitoringTestApp-MonitoringStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: ComparisonOperators for ranges require ThresholdMetricId to be set (Service: AmazonCloudWatch; Status Code: 400; Error Code: ValidationError; Request ID: 678402c0-da06-4c56-a222-295dbe54bf74; Proxy: null)

Other details

This may be related to this issue: https://github.com/aws/aws-cdk/issues/10540