LCOV - differential code coverage report
Current view: top level - libs/utils/src - postgres_client.rs (source / functions) Coverage Total Hit CBC
Current: f6946e90941b557c917ac98cd5a7e9506d180f3e.info Lines: 100.0 % 15 15 15
Current Date: 2023-10-19 02:04:12 Functions: 100.0 % 2 2 2
Baseline: c8637f37369098875162f194f92736355783b050.info
Baseline Date: 2023-10-18 20:25:20

           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                 : pub fn wal_stream_connection_config(
      13                 :     TenantTimelineId {
      14                 :         tenant_id,
      15                 :         timeline_id,
      16                 :     }: TenantTimelineId,
      17                 :     listen_pg_addr_str: &str,
      18                 :     auth_token: Option<&str>,
      19                 :     availability_zone: Option<&str>,
      20                 : ) -> anyhow::Result<PgConnectionConfig> {
      21 CBC     1533968 :     let (host, port) =
      22         1533968 :         parse_host_port(listen_pg_addr_str).context("Unable to parse listen_pg_addr_str")?;
      23         1533968 :     let port = port.unwrap_or(5432);
      24         1533968 :     let mut connstr = PgConnectionConfig::new_host_port(host, port)
      25         1533968 :         .extend_options([
      26         1533968 :             "-c".to_owned(),
      27         1533968 :             format!("timeline_id={}", timeline_id),
      28         1533968 :             format!("tenant_id={}", tenant_id),
      29         1533968 :         ])
      30         1533968 :         .set_password(auth_token.map(|s| s.to_owned()));
      31                 : 
      32         1533968 :     if let Some(availability_zone) = availability_zone {
      33             814 :         connstr = connstr.extend_options([format!("availability_zone={}", availability_zone)]);
      34         1533154 :     }
      35                 : 
      36         1533968 :     Ok(connstr)
      37         1533968 : }
        

Generated by: LCOV version 2.1-beta