LCOV - differential code coverage report
Current view: top level - libs/utils/src - postgres_client.rs (source / functions) Coverage Total Hit CBC
Current: cd44433dd675caa99df17a61b18949c8387e2242.info Lines: 100.0 % 24 24 24
Current Date: 2024-01-09 02:06:09 Functions: 100.0 % 2 2 2
Baseline: 66c52a629a0f4a503e193045e0df4c77139e344b.info
Baseline Date: 2024-01-08 15:34:46

           TLA  Line data    Source code
       1                 : //! Postgres client connection code common to other crates (safekeeper and
       2                 : //! pageserver) which depends on tenant/timeline ids and thus not fitting into
       3                 : //! postgres_connection crate.
       4                 : 
       5                 : use anyhow::Context;
       6                 : use postgres_connection::{parse_host_port, PgConnectionConfig};
       7                 : 
       8                 : use crate::id::TenantTimelineId;
       9                 : 
      10                 : /// Create client config for fetching WAL from safekeeper on particular timeline.
      11                 : /// listen_pg_addr_str is in form host:\[port\].
      12 CBC      845550 : pub fn wal_stream_connection_config(
      13          845550 :     TenantTimelineId {
      14          845550 :         tenant_id,
      15          845550 :         timeline_id,
      16          845550 :     }: TenantTimelineId,
      17          845550 :     listen_pg_addr_str: &str,
      18          845550 :     auth_token: Option<&str>,
      19          845550 :     availability_zone: Option<&str>,
      20          845550 : ) -> anyhow::Result<PgConnectionConfig> {
      21          845550 :     let (host, port) =
      22          845550 :         parse_host_port(listen_pg_addr_str).context("Unable to parse listen_pg_addr_str")?;
      23          845550 :     let port = port.unwrap_or(5432);
      24          845550 :     let mut connstr = PgConnectionConfig::new_host_port(host, port)
      25          845550 :         .extend_options([
      26          845550 :             "-c".to_owned(),
      27          845550 :             format!("timeline_id={}", timeline_id),
      28          845550 :             format!("tenant_id={}", tenant_id),
      29          845550 :         ])
      30          845550 :         .set_password(auth_token.map(|s| s.to_owned()));
      31                 : 
      32          845550 :     if let Some(availability_zone) = availability_zone {
      33             890 :         connstr = connstr.extend_options([format!("availability_zone={}", availability_zone)]);
      34          844660 :     }
      35                 : 
      36          845550 :     Ok(connstr)
      37          845550 : }
        

Generated by: LCOV version 2.1-beta