"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LatencyWidget = void 0;
const aws_cdk_lib_1 = require("aws-cdk-lib");
const types_1 = require("./types");
/**
 * Creates a latency widget that adjusts the percentile based on slo window. The smaller the window,
 * the lower the percentile, in effect highlighting more severe issues in the smaller frames.
 * This is not as accurate as using error rates and burn rates, and is especially bad for services
 * that have non-normal distribution in latencies, but it works out of the box with AWS metrics
 * only, so it can serve as a good enough start.
 */
class LatencyWidget extends aws_cdk_lib_1.aws_cloudwatch.GraphWidget {
    constructor(props) {
        const leftYAxis = {
            // By default, scale the left axis to the SLO threshold
            min: 0,
            max: props.latencyThreshold * 1.4,
        };
        const leftAnnotations = [{ label: 'SLO', value: props.latencyThreshold, fill: aws_cdk_lib_1.aws_cloudwatch.Shading.ABOVE, color: types_1.Colors.red }];
        let title = props.title;
        if (props.addPeriodToTitle === true) {
            title = `${props.title} - ${props.sloWindow.alertWindow.toHumanString()}`;
        }
        const myProps = {
            title,
            left: [props.latency],
            leftAnnotations,
            leftYAxis,
        };
        super({ ...props, ...myProps });
    }
}
exports.LatencyWidget = LatencyWidget;
