"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomLatencyMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
/**
 * Creates a metric that can be used as an SLI for API Gateway
 * Latency SLOs
 */
class CustomLatencyMetric extends aws_cdk_lib_1.aws_cloudwatch.Metric {
    constructor(props) {
        const sloBudget = 100 - props.sloThreshold * 100;
        let alarmThreshold = 100 - props.sloWindow.burnRateThreshold * sloBudget;
        alarmThreshold = Math.max(0, Math.min(alarmThreshold, 100));
        const statistic = `p${alarmThreshold.toFixed(2)}`;
        const myProps = {
            namespace: props.namespace,
            metricName: props.latencyMetricName,
            statistic,
            label: `Latency ${statistic}`,
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.CustomLatencyMetric = CustomLatencyMetric;
