"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppSyncAvailabilityMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
class AppSyncAvailabilityMetric extends aws_cdk_lib_1.aws_cloudwatch.MathExpression {
    /**
     * Creates a metric that can be used as an SLI for AppSync API
     * Availability SLOs
     */
    constructor(props) {
        const errors = new aws_cdk_lib_1.aws_cloudwatch.Metric({
            namespace: 'AWS/AppSync',
            metricName: '5XXError',
            dimensionsMap: {
                GraphQLAPIId: props.apiId,
            },
            statistic: 'Sum',
            label: 'Error rate',
        });
        // There is no direct request count metric. Have to get this from the sample
        // count for one of the error metrics.
        // https://docs.aws.amazon.com/appsync/latest/devguide/monitoring.html#cw-metrics
        const requests = new aws_cdk_lib_1.aws_cloudwatch.Metric({
            namespace: 'AWS/AppSync',
            metricName: '5XXError',
            dimensionsMap: {
                GraphQLAPIId: props.apiId,
            },
            statistic: 'SampleCount',
            label: 'Requests',
        });
        const myProps = {
            label: 'Availability',
            expression: '(requests - errors)/requests',
            usingMetrics: { requests, errors },
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.AppSyncAvailabilityMetric = AppSyncAvailabilityMetric;
