LCOV - code coverage report
Current view: top level - libs/compute_api/src - responses.rs (source / functions) Coverage Total Hit
Test: 32f4a56327bc9da697706839ed4836b2a00a408f.info Lines: 73.3 % 15 11
Test Date: 2024-02-07 07:37:29 Functions: 17.5 % 103 18

            Line data    Source code
       1              : //! Structs representing the JSON formats used in the compute_ctl's HTTP API.
       2              : 
       3              : use chrono::{DateTime, Utc};
       4              : use serde::{Deserialize, Serialize, Serializer};
       5              : 
       6              : use crate::spec::ComputeSpec;
       7              : 
       8            0 : #[derive(Serialize, Debug, Deserialize)]
       9              : pub struct GenericAPIError {
      10              :     pub error: String,
      11              : }
      12              : 
      13              : /// Response of the /status API
      14         2218 : #[derive(Serialize, Debug, Deserialize)]
      15              : #[serde(rename_all = "snake_case")]
      16              : pub struct ComputeStatusResponse {
      17              :     pub start_time: DateTime<Utc>,
      18              :     pub tenant: Option<String>,
      19              :     pub timeline: Option<String>,
      20              :     pub status: ComputeStatus,
      21              :     #[serde(serialize_with = "rfc3339_serialize")]
      22              :     pub last_active: Option<DateTime<Utc>>,
      23              :     pub error: Option<String>,
      24              : }
      25              : 
      26        34710 : #[derive(Deserialize, Serialize)]
      27              : #[serde(rename_all = "snake_case")]
      28              : pub struct ComputeState {
      29              :     pub status: ComputeStatus,
      30              :     /// Timestamp of the last Postgres activity
      31              :     #[serde(serialize_with = "rfc3339_serialize")]
      32              :     pub last_active: Option<DateTime<Utc>>,
      33              :     pub error: Option<String>,
      34              : }
      35              : 
      36         6942 : #[derive(Serialize, Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
      37              : #[serde(rename_all = "snake_case")]
      38              : pub enum ComputeStatus {
      39              :     // Spec wasn't provided at start, waiting for it to be
      40              :     // provided by control-plane.
      41              :     Empty,
      42              :     // Compute configuration was requested.
      43              :     ConfigurationPending,
      44              :     // Compute node has spec and initial startup and
      45              :     // configuration is in progress.
      46              :     Init,
      47              :     // Compute is configured and running.
      48              :     Running,
      49              :     // New spec is being applied.
      50              :     Configuration,
      51              :     // Either startup or configuration failed,
      52              :     // compute will exit soon or is waiting for
      53              :     // control-plane to terminate it.
      54              :     Failed,
      55              : }
      56              : 
      57         2218 : fn rfc3339_serialize<S>(x: &Option<DateTime<Utc>>, s: S) -> Result<S::Ok, S::Error>
      58         2218 : where
      59         2218 :     S: Serializer,
      60         2218 : {
      61         2218 :     if let Some(x) = x {
      62            0 :         x.to_rfc3339().serialize(s)
      63              :     } else {
      64         2218 :         s.serialize_none()
      65              :     }
      66         2218 : }
      67              : 
      68              : /// Response of the /metrics.json API
      69         1946 : #[derive(Clone, Debug, Default, Serialize)]
      70              : pub struct ComputeMetrics {
      71              :     /// Time spent waiting in pool
      72              :     pub wait_for_spec_ms: u64,
      73              : 
      74              :     /// Time spent checking if safekeepers are synced
      75              :     pub sync_sk_check_ms: u64,
      76              : 
      77              :     /// Time spent syncing safekeepers (walproposer.c).
      78              :     /// In most cases this should be zero.
      79              :     pub sync_safekeepers_ms: u64,
      80              : 
      81              :     /// Time it took to establish a pg connection to the pageserver.
      82              :     /// This is two roundtrips, so it's a good proxy for compute-pageserver
      83              :     /// latency. The latency is usually 0.2ms, but it's not safe to assume
      84              :     /// that.
      85              :     pub pageserver_connect_micros: u64,
      86              : 
      87              :     /// Time to get basebackup from pageserver and write it to disk.
      88              :     pub basebackup_ms: u64,
      89              : 
      90              :     /// Compressed size of basebackup received.
      91              :     pub basebackup_bytes: u64,
      92              : 
      93              :     /// Time spent starting potgres. This includes initialization of shared
      94              :     /// buffers, preloading extensions, and other pg operations.
      95              :     pub start_postgres_ms: u64,
      96              : 
      97              :     /// Time spent applying pg catalog updates that were made in the console
      98              :     /// UI. This should be 0 when startup time matters, since cplane tries
      99              :     /// to do these updates eagerly, and passes the skip_pg_catalog_updates
     100              :     /// when it's safe to skip this step.
     101              :     pub config_ms: u64,
     102              : 
     103              :     /// Total time, from when we receive the spec to when we're ready to take
     104              :     /// pg connections.
     105              :     pub total_startup_ms: u64,
     106              :     pub load_ext_ms: u64,
     107              :     pub num_ext_downloaded: u64,
     108              :     pub largest_ext_size: u64, // these are measured in bytes
     109              :     pub total_ext_download_size: u64,
     110              : }
     111              : 
     112              : /// Response of the `/computes/{compute_id}/spec` control-plane API.
     113              : /// This is not actually a compute API response, so consider moving
     114              : /// to a different place.
     115            0 : #[derive(Deserialize, Debug)]
     116              : pub struct ControlPlaneSpecResponse {
     117              :     pub spec: Option<ComputeSpec>,
     118              :     pub status: ControlPlaneComputeStatus,
     119              : }
     120              : 
     121            0 : #[derive(Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
     122              : #[serde(rename_all = "snake_case")]
     123              : pub enum ControlPlaneComputeStatus {
     124              :     // Compute is known to control-plane, but it's not
     125              :     // yet attached to any timeline / endpoint.
     126              :     Empty,
     127              :     // Compute is attached to some timeline / endpoint and
     128              :     // should be able to start with provided spec.
     129              :     Attached,
     130              : }
        

Generated by: LCOV version 2.1-beta