LCOV - code coverage report
Current view: top level - compute_tools/src - metrics.rs (source / functions) Coverage Total Hit
Test: 07bee600374ccd486c69370d0972d9035964fe68.info Lines: 0.0 % 46 0
Test Date: 2025-02-20 13:11:02 Functions: 0.0 % 6 0

            Line data    Source code
       1              : use metrics::core::Collector;
       2              : use metrics::proto::MetricFamily;
       3              : use metrics::{register_int_counter_vec, register_uint_gauge_vec, IntCounterVec, UIntGaugeVec};
       4              : use once_cell::sync::Lazy;
       5              : 
       6            0 : pub(crate) static INSTALLED_EXTENSIONS: Lazy<UIntGaugeVec> = Lazy::new(|| {
       7            0 :     register_uint_gauge_vec!(
       8            0 :         "compute_installed_extensions",
       9            0 :         "Number of databases where the version of extension is installed",
      10            0 :         &["extension_name", "version", "owned_by_superuser"]
      11            0 :     )
      12            0 :     .expect("failed to define a metric")
      13            0 : });
      14              : 
      15              : // Normally, any HTTP API request is described by METHOD (e.g. GET, POST, etc.) + PATH,
      16              : // but for all our APIs we defined a 'slug'/method/operationId in the OpenAPI spec.
      17              : // And it's fair to call it a 'RPC' (Remote Procedure Call).
      18              : pub enum CPlaneRequestRPC {
      19              :     GetSpec,
      20              : }
      21              : 
      22              : impl CPlaneRequestRPC {
      23            0 :     pub fn as_str(&self) -> &str {
      24            0 :         match self {
      25            0 :             CPlaneRequestRPC::GetSpec => "GetSpec",
      26            0 :         }
      27            0 :     }
      28              : }
      29              : 
      30              : pub const UNKNOWN_HTTP_STATUS: &str = "unknown";
      31              : 
      32            0 : pub(crate) static CPLANE_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
      33            0 :     register_int_counter_vec!(
      34            0 :         "compute_ctl_cplane_requests_total",
      35            0 :         "Total number of control plane requests made by compute_ctl by status",
      36            0 :         &["rpc", "http_status"]
      37            0 :     )
      38            0 :     .expect("failed to define a metric")
      39            0 : });
      40              : 
      41              : /// Total number of failed database migrations. Per-compute, this is actually a boolean metric,
      42              : /// either empty or with a single value (1, migration_id) because we stop at the first failure.
      43              : /// Yet, the sum over the fleet will provide the total number of failures.
      44            0 : pub(crate) static DB_MIGRATION_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
      45            0 :     register_int_counter_vec!(
      46            0 :         "compute_ctl_db_migration_failed_total",
      47            0 :         "Total number of failed database migrations",
      48            0 :         &["migration_id"]
      49            0 :     )
      50            0 :     .expect("failed to define a metric")
      51            0 : });
      52              : 
      53            0 : pub(crate) static REMOTE_EXT_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
      54            0 :     register_int_counter_vec!(
      55            0 :         "compute_ctl_remote_ext_requests_total",
      56            0 :         "Total number of requests made by compute_ctl to download extensions from S3 proxy by status",
      57            0 :         // Do not use any labels like extension name yet.
      58            0 :         // We can add them later if needed.
      59            0 :         &["http_status"]
      60            0 :     )
      61            0 :     .expect("failed to define a metric")
      62            0 : });
      63              : 
      64            0 : pub fn collect() -> Vec<MetricFamily> {
      65            0 :     let mut metrics = INSTALLED_EXTENSIONS.collect();
      66            0 :     metrics.extend(CPLANE_REQUESTS_TOTAL.collect());
      67            0 :     metrics.extend(REMOTE_EXT_REQUESTS_TOTAL.collect());
      68            0 :     metrics.extend(DB_MIGRATION_FAILED.collect());
      69            0 :     metrics
      70            0 : }
        

Generated by: LCOV version 2.1-beta