LCOV - differential code coverage report
Current view: top level - libs/compute_api/src - responses.rs (source / functions) Coverage Total Hit UBC CBC
Current: f6946e90941b557c917ac98cd5a7e9506d180f3e.info Lines: 63.6 % 11 7 4 7
Current Date: 2023-10-19 02:04:12 Functions: 16.5 % 103 17 86 17
Baseline: c8637f37369098875162f194f92736355783b050.info
Baseline Date: 2023-10-18 20:25:20

           TLA  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 UBC           0 : #[derive(Serialize, Debug, Deserialize)]
       9                 : pub struct GenericAPIError {
      10                 :     pub error: String,
      11                 : }
      12                 : 
      13                 : /// Response of the /status API
      14 CBC        1436 : #[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           14360 : #[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            2872 : #[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                 : fn rfc3339_serialize<S>(x: &Option<DateTime<Utc>>, s: S) -> Result<S::Ok, S::Error>
      58                 : where
      59                 :     S: Serializer,
      60                 : {
      61            1436 :     if let Some(x) = x {
      62 UBC           0 :         x.to_rfc3339().serialize(s)
      63                 :     } else {
      64 CBC        1436 :         s.serialize_none()
      65                 :     }
      66            1436 : }
      67                 : 
      68                 : /// Response of the /metrics.json API
      69            1914 : #[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 UBC           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