"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiAvailabilityMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
/**
 * Creates a metric that can be used as an SLI for API Gateway
 * Availability SLOs
 */
class ApiAvailabilityMetric extends aws_cdk_lib_1.aws_cloudwatch.MathExpression {
    constructor(props) {
        const gatewayErrors = new aws_cdk_lib_1.aws_cloudwatch.Metric({
            namespace: 'AWS/ApiGateway',
            metricName: '5XXError',
            dimensionsMap: {
                ApiName: props.apiName,
            },
            statistic: 'Sum',
            label: 'Error rate',
        });
        const gatewayRequests = new aws_cdk_lib_1.aws_cloudwatch.Metric({
            namespace: 'AWS/ApiGateway',
            metricName: 'Count',
            dimensionsMap: {
                ApiName: props.apiName,
            },
            statistic: 'Sum',
            label: 'Requests',
        });
        const myProps = {
            label: 'Availability',
            expression: '(gatewayRequests - gatewayErrors)/gatewayRequests',
            usingMetrics: { gatewayRequests, gatewayErrors },
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.ApiAvailabilityMetric = ApiAvailabilityMetric;
