LCOV - code coverage report
Current view: top level - libs/utils/src - postgres_client.rs (source / functions) Coverage Total Hit
Test: 8ac049b474321fdc72ddcb56d7165153a1a900e8.info Lines: 100.0 % 15 15
Test Date: 2023-09-06 10:18:01 Functions: 100.0 % 2 2

            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      1366041 :     let (host, port) =
      22      1366041 :         parse_host_port(listen_pg_addr_str).context("Unable to parse listen_pg_addr_str")?;
      23      1366041 :     let port = port.unwrap_or(5432);
      24      1366041 :     let mut connstr = PgConnectionConfig::new_host_port(host, port)
      25      1366041 :         .extend_options([
      26      1366041 :             "-c".to_owned(),
      27      1366041 :             format!("timeline_id={}", timeline_id),
      28      1366041 :             format!("tenant_id={}", tenant_id),
      29      1366041 :         ])
      30      1366041 :         .set_password(auth_token.map(|s| s.to_owned()));
      31              : 
      32      1366041 :     if let Some(availability_zone) = availability_zone {
      33          809 :         connstr = connstr.extend_options([format!("availability_zone={}", availability_zone)]);
      34      1365231 :     }
      35              : 
      36      1366040 :     Ok(connstr)
      37      1366040 : }
        

Generated by: LCOV version 2.1-beta