LCOV - code coverage report
Current view: top level - libs/utils/src - postgres_client.rs (source / functions) Coverage Total Hit
Test: d0feeceb9d5ee9c8e73bee7d4ffcced539793178.info Lines: 100.0 % 24 24
Test Date: 2024-06-26 15:19:01 Functions: 50.0 % 2 1

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

Generated by: LCOV version 2.1-beta