// Copyright 2024 PingCAP, Inc.

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

lazy_static! {
    pub static ref NATIVE_BR_BACKUP_SUCCESS: IntCounter =
        register_int_counter!("native_br_backup_success", "Number of success backup").unwrap();
    pub static ref NATIVE_BR_BACKUP_ERROR: IntCounter =
        register_int_counter!("native_br_backup_error", "Number of errors during backup").unwrap();
    pub static ref NATIVE_BR_ARCHIVE_CANDIDATE_SKIPPED_TOTAL: IntCounterVec =
        register_int_counter_vec!(
            "native_br_archive_candidate_skipped_total",
            "Number of backup candidates skipped during archive reconstruction",
            &["reason"],
        )
        .unwrap();
    pub static ref NATIVE_BR_BACKUP_MISSING_COMMIT_RECORD: IntCounter = register_int_counter!(
        "native_br_backup_missing_commit_record",
        "Number of backup missing commit record"
    )
    .unwrap();
    pub static ref NATIVE_BR_RESTORE_ERROR: IntCounterVec = register_int_counter_vec!(
        "native_br_restore_error",
        "Number of errors during restoration",
        &["type"],
    )
    .unwrap();
    pub static ref NATIVE_BR_RFENGINE_WAL_EPOCH_OVERWRITTEN_ERROR: IntCounter =
        register_int_counter!(
            "native_br_restore_rfengine_wal_epoch_overwritten_error",
            "Number of errors that epoch of rfengine WAL is overwritten"
        )
        .unwrap();
    pub static ref NATIVE_BR_BACKUP_BATCH_SIZE: Histogram = register_histogram!(
        "native_br_backup_batch_size",
        "Histogram of backup batch size",
        exponential_buckets(1.0, 2.0, 16).unwrap()
    )
    .unwrap();
    pub static ref NATIVE_BR_RESTORE_PENDING_DATA_SIZE: IntGauge = register_int_gauge!(
        "native_br_restore_pending_data_size",
        "Restore pending data size",
    )
    .unwrap();
    pub static ref NATIVE_BR_RESTORED_DATA_SIZE: IntCounter =
        register_int_counter!("native_br_restored_data_size", "Restored data size",).unwrap();
    pub static ref NATIVE_BR_RESTORED_KV_SIZE: IntCounter =
        register_int_counter!("native_br_restored_kv_size", "Restored kv size",).unwrap();
    pub static ref NATIVE_BR_RESTORED_SNAPSHOT_KV_BYTES: IntCounter = register_int_counter!(
        "native_br_restored_snapshot_bytes",
        "Total bytes of restored snapshot"
    )
    .unwrap();
    pub static ref NATIVE_BR_RESTORE_SNAPSHOT_REQUEST_SECS: Histogram = register_histogram!(
        "native_br_restore_snapshot_request_secs",
        "Duration of snapshot restore requests in seconds",
        exponential_buckets(0.01, 2.0, 16).unwrap()
    )
    .unwrap();
    pub static ref NATIVE_BR_RATE_LIMITER_WAIT_DURATION_SECS: HistogramVec =
        register_histogram_vec!(
            "native_br_rate_limiter_wait_duration_secs",
            "Duration of rate limiter wait in seconds",
            &["source"],
            exponential_buckets(0.001, 2.0, 20).unwrap()
        )
        .unwrap();
    pub static ref NATIVE_BR_RATE_LIMITER_BYTES_TOTAL: IntCounterVec = register_int_counter_vec!(
        "native_br_rate_limiter_bytes_total",
        "Total bytes consumed through rate limiter",
        &["source"],
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_CACHE_STATE: IntGaugeVec = register_int_gauge_vec!(
        "tikv_worker_native_br_pd_meta_cache_state",
        "Current state of the native BR PD metadata watch cache",
        &["state"],
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_CACHE_KVS: IntGauge = register_int_gauge!(
        "tikv_worker_native_br_pd_meta_cache_kvs",
        "Number of key-value pairs in the native BR PD metadata watch cache",
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_CACHE_REVISION: IntGauge = register_int_gauge!(
        "tikv_worker_native_br_pd_meta_cache_revision",
        "Applied etcd revision of the native BR PD metadata watch cache",
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_WATCH_EVENTS_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_worker_native_br_pd_meta_watch_events_total",
        "Number of PD metadata watch events handled by native BR",
        &["type"],
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_WATCH_KEYS_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_worker_native_br_pd_meta_watch_keys_total",
        "Number of PD metadata watch keys seen by native BR",
        &["result"],
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_WATCH_RESYNC_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_worker_native_br_pd_meta_watch_resync_total",
        "Number of native BR PD metadata watch cache resyncs",
        &["reason"],
    )
    .unwrap();
    pub static ref NATIVE_BR_PD_META_BACKUP_SNAPSHOT_TOTAL: IntCounterVec =
        register_int_counter_vec!(
            "tikv_worker_native_br_pd_meta_backup_snapshot_total",
            "Number of PD metadata snapshots used by native BR backup",
            &["source"],
        )
        .unwrap();
    pub static ref NATIVE_BR_PD_META_FALLBACK_TOTAL: IntCounterVec = register_int_counter_vec!(
        "tikv_worker_native_br_pd_meta_fallback_total",
        "Number of native BR PD metadata backup fallbacks",
        &["reason"],
    )
    .unwrap();
}
