"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppSyncLatencyMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
class AppSyncLatencyMetric extends aws_cdk_lib_1.aws_cloudwatch.Metric {
    /**
     * Creates a metric that can be used as an SLI for AppSync API
     * Latency SLOs
     */
    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: 'AWS/AppSync',
            metricName: 'Latency',
            dimensionsMap: {
                GraphQLAPIId: props.apiId,
            },
            statistic,
            label: `Latency ${statistic}`,
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.AppSyncLatencyMetric = AppSyncLatencyMetric;
