"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiMethodLatencyMetric = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
class ApiMethodLatencyMetric extends aws_cdk_lib_1.aws_cloudwatch.MathExpression {
    /**
     * Creates a search expression that finds all methods for a given API stage and returns the
     * Latency for each of the methods at the given percentile.
     */
    constructor(props) {
        var _a;
        const { apiName, stage, percentile } = props;
        const period = (_a = props.period) !== null && _a !== void 0 ? _a : aws_cdk_lib_1.Duration.minutes(5);
        const expression = `SEARCH('{AWS/ApiGateway,ApiName,Method,Resource,Stage} (\"Latency\") ApiName=${apiName} Stage=${stage}',`
            + ` 'p${percentile}', ${period.toSeconds()})`;
        super({
            expression,
            label: ' ', // blank out the label so it displays the found function name
            usingMetrics: {},
        });
    }
}
exports.ApiMethodLatencyMetric = ApiMethodLatencyMetric;
