// Copyright 2023 PingCAP, Inc.

use lazy_static::lazy_static;
use prometheus::*;

lazy_static! {
    pub static ref STATUS_REQUEST_DURATION: HistogramVec = register_histogram_vec!(
        "tikv_status_server_request_duration_seconds",
        "Bucketed histogram of TiKV status server request duration",
        &["method", "path"],
        exponential_buckets(0.0001, 2.0, 24).unwrap() // 0.1ms ~ 1677.7s
    )
    .unwrap();
    pub static ref DFS_FILE_READ_ACTIVE: IntGauge = register_int_gauge!(
        "tikv_status_server_dfs_file_read_active",
        "Number of active DFS file read responses"
    )
    .unwrap();
    pub static ref DFS_FILE_READ_IN_FLIGHT_BYTES: IntGauge = register_int_gauge!(
        "tikv_status_server_dfs_file_read_in_flight_bytes",
        "Source bytes retained by active DFS file read responses"
    )
    .unwrap();
    pub static ref DFS_FILE_READ_REQUESTED_BYTES: Histogram = register_histogram!(
        "tikv_status_server_dfs_file_read_requested_bytes",
        "Requested DFS file read response size in bytes",
        exponential_buckets(1024.0, 2.0, 24).unwrap() // 1KiB ~ 8GiB
    )
    .unwrap();
    pub static ref DFS_FILE_READ_UNSUCCESSFUL_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_status_server_dfs_file_read_unsuccessful_total",
        "Total number of unsuccessful DFS file read requests",
        &["reason"],
    )
    .unwrap();
    pub static ref DFS_FILE_READ_RESPONSE_BODY_DURATION: Histogram = register_histogram!(
        "tikv_status_server_dfs_file_read_response_body_duration_seconds",
        "Lifetime of DFS file read response bodies",
        exponential_buckets(0.001, 2.0, 24).unwrap() // 1ms ~ 8388s
    )
    .unwrap();
    pub static ref SNAPSHOT_CACHE_VALIDATION_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_status_server_kvengine_snapshot_cache_validation_total",
        "Total number of kvengine snapshot cache validation outcomes",
        &["result"],
    )
    .unwrap();
    pub static ref SNAPSHOT_LOCK_CHECK_DURATION: HistogramVec = register_histogram_vec!(
        "tikv_status_server_kvengine_snapshot_lock_check_duration_seconds",
        "Duration of kvengine snapshot lock checking",
        &["result"],
        exponential_buckets(1e-6, 4.0, 12).unwrap() // 1us ~ 4.2s
    )
    .unwrap();
    pub static ref SNAPSHOT_BUILD_DURATION: Histogram = register_histogram!(
        "tikv_status_server_kvengine_snapshot_build_duration_seconds",
        "Duration of kvengine snapshot payload building",
        exponential_buckets(1e-6, 4.0, 12).unwrap() // 1us ~ 4.2s
    )
    .unwrap();
    pub static ref SNAPSHOT_PAYLOAD_BYTES: HistogramVec = register_histogram_vec!(
        "tikv_status_server_kvengine_snapshot_payload_bytes",
        "Payload bytes of kvengine snapshot responses",
        &["part"],
        exponential_buckets(256.0, 2.0, 22).unwrap() // 256B ~ 512MiB
    )
    .unwrap();
}
