"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloudfrontAvailabilityMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
/**
 * Creates a metric that can be used as an SLI for Cloudfront Distribution
 * Availability SLOs
 */
class CloudfrontAvailabilityMetric extends aws_cdk_lib_1.aws_cloudwatch.MathExpression {
    constructor(props) {
        const errorRate = new aws_cdk_lib_1.aws_cloudwatch.Metric({
            namespace: 'AWS/CloudFront',
            metricName: '5xxErrorRate',
            dimensionsMap: {
                Region: 'Global',
                DistributionId: props.distributionId,
            },
            statistic: 'Average',
            label: 'Error rate',
        });
        const myProps = {
            label: 'Availability',
            expression: '1-(errorRate/100)',
            usingMetrics: { errorRate },
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.CloudfrontAvailabilityMetric = CloudfrontAvailabilityMetric;
