"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElasticSearchAvailabilityMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
/**
 * Creates a metric that can be used as an SLI for ElasticSearch
 * Availability SLOs
 */
class ElasticSearchAvailabilityMetric extends aws_cdk_lib_1.aws_cloudwatch.MathExpression {
    constructor(props) {
        const usingMetrics = {
            m2xx: new aws_cdk_lib_1.aws_cloudwatch.Metric({
                namespace: 'AWS/ES',
                metricName: '2xx',
                dimensionsMap: {
                    DomainName: props.domainName,
                    ClientId: props.accountId,
                },
                statistic: 'Sum',
                label: '2xx',
            }),
            m3xx: new aws_cdk_lib_1.aws_cloudwatch.Metric({
                namespace: 'AWS/ES',
                metricName: '3xx',
                dimensionsMap: {
                    DomainName: props.domainName,
                    ClientId: props.accountId,
                },
                statistic: 'Sum',
                label: '3xx',
            }),
            m4xx: new aws_cdk_lib_1.aws_cloudwatch.Metric({
                namespace: 'AWS/ES',
                metricName: '4xx',
                dimensionsMap: {
                    DomainName: props.domainName,
                    ClientId: props.accountId,
                },
                statistic: 'Sum',
                label: '4xx',
            }),
            m5xx: new aws_cdk_lib_1.aws_cloudwatch.Metric({
                namespace: 'AWS/ES',
                metricName: '5xx',
                dimensionsMap: {
                    DomainName: props.domainName,
                    ClientId: props.accountId,
                },
                statistic: 'Sum',
                label: '5xx',
            }),
        };
        const myProps = {
            label: 'Availability',
            expression: '(m2xx + m3xx + m4xx)/(m2xx + m3xx + m4xx + m5xx)',
            usingMetrics,
            period: props.sloWindow.alertWindow,
        };
        super({ ...props, ...myProps });
    }
}
exports.ElasticSearchAvailabilityMetric = ElasticSearchAvailabilityMetric;
