From 97b48c23f86bbb138595c4d0e0981110c92d0f74 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Fri, 12 Jan 2024 22:24:22 +0400 Subject: [PATCH] Compact some compute_ctl logs (#6346) Print postgres roles in a single line and add some info. --- compute_tools/src/bin/compute_ctl.rs | 2 +- compute_tools/src/compute.rs | 2 +- compute_tools/src/pg_helpers.rs | 2 +- compute_tools/src/spec.rs | 31 ++++++++++++++++++---------- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/compute_tools/src/bin/compute_ctl.rs b/compute_tools/src/bin/compute_ctl.rs index f064928c17..47a00277dd 100644 --- a/compute_tools/src/bin/compute_ctl.rs +++ b/compute_tools/src/bin/compute_ctl.rs @@ -293,7 +293,7 @@ fn main() -> Result<()> { let pg = match compute.start_compute(extension_server_port) { Ok(pg) => Some(pg), Err(err) => { - error!("could not start the compute node: {:?}", err); + error!("could not start the compute node: {:#}", err); let mut state = compute.state.lock().unwrap(); state.error = Some(format!("{:?}", err)); state.status = ComputeStatus::Failed; diff --git a/compute_tools/src/compute.rs b/compute_tools/src/compute.rs index e701a60d77..deea2375c2 100644 --- a/compute_tools/src/compute.rs +++ b/compute_tools/src/compute.rs @@ -280,7 +280,7 @@ fn create_neon_superuser(spec: &ComputeSpec, client: &mut Client) -> Result<()> $$;"#, roles_decl, database_decl, ); - info!("Neon superuser created:\n{}", inlinify(&query)); + info!("Neon superuser created: {}", inlinify(&query)); client .simple_query(&query) .map_err(|e| anyhow::anyhow!(e).context(query))?; diff --git a/compute_tools/src/pg_helpers.rs b/compute_tools/src/pg_helpers.rs index bde1ba0a88..b53ac3f02c 100644 --- a/compute_tools/src/pg_helpers.rs +++ b/compute_tools/src/pg_helpers.rs @@ -456,7 +456,7 @@ pub fn handle_postgres_logs(stderr: std::process::ChildStderr) -> JoinHandle<()> /// - no new lines were written for the last second async fn handle_postgres_logs_async(stderr: tokio::process::ChildStderr) -> Result<()> { let mut lines = tokio::io::BufReader::new(stderr).lines(); - let timeout_duration = Duration::from_secs(1); + let timeout_duration = Duration::from_millis(100); let ts_regex = regex::Regex::new(r"^\d+-\d{2}-\d{2} \d{2}:\d{2}:\d{2}").expect("regex is valid"); diff --git a/compute_tools/src/spec.rs b/compute_tools/src/spec.rs index 1789df7b79..ef5f55622d 100644 --- a/compute_tools/src/spec.rs +++ b/compute_tools/src/spec.rs @@ -190,18 +190,20 @@ pub fn handle_roles(spec: &ComputeSpec, client: &mut Client) -> Result<()> { // Print a list of existing Postgres roles (only in debug mode) if span_enabled!(Level::INFO) { - info!("postgres roles:"); + let mut vec = Vec::new(); for r in &existing_roles { - info!( - " - {}:{}", + vec.push(format!( + "{}:{}", r.name, if r.encrypted_password.is_some() { "[FILTERED]" } else { "(null)" } - ); + )); } + + info!("postgres roles (total {}): {:?}", vec.len(), vec); } // Process delta operations first @@ -239,7 +241,10 @@ pub fn handle_roles(spec: &ComputeSpec, client: &mut Client) -> Result<()> { // Refresh Postgres roles info to handle possible roles renaming let existing_roles: Vec = get_existing_roles(&mut xact)?; - info!("cluster spec roles:"); + info!( + "handling cluster spec roles (total {})", + spec.cluster.roles.len() + ); for role in &spec.cluster.roles { let name = &role.name; // XXX: with a limited number of roles it is fine, but consider making it a HashMap @@ -302,7 +307,7 @@ pub fn handle_roles(spec: &ComputeSpec, client: &mut Client) -> Result<()> { "CREATE ROLE {} INHERIT CREATEROLE CREATEDB BYPASSRLS REPLICATION IN ROLE neon_superuser", name.pg_quote() ); - info!("role create query: '{}'", &query); + info!("running role create query: '{}'", &query); query.push_str(&role.to_pg_options()); xact.execute(query.as_str(), &[])?; } @@ -319,7 +324,7 @@ pub fn handle_roles(spec: &ComputeSpec, client: &mut Client) -> Result<()> { RoleAction::Create => " -> create", RoleAction::Update => " -> update", }; - info!(" - {}:{}{}", name, pwd, action_str); + info!(" - {}:{}{}", name, pwd, action_str); } } @@ -428,10 +433,11 @@ pub fn handle_databases(spec: &ComputeSpec, client: &mut Client) -> Result<()> { // Print a list of existing Postgres databases (only in debug mode) if span_enabled!(Level::INFO) { - info!("postgres databases:"); + let mut vec = Vec::new(); for (dbname, db) in &existing_dbs { - info!(" {}:{}", dbname, db.owner); + vec.push(format!("{}:{}", dbname, db.owner)); } + info!("postgres databases (total {}): {:?}", vec.len(), vec); } // Process delta operations first @@ -503,7 +509,10 @@ pub fn handle_databases(spec: &ComputeSpec, client: &mut Client) -> Result<()> { // Refresh Postgres databases info to handle possible renames let existing_dbs = get_existing_dbs(client)?; - info!("cluster spec databases:"); + info!( + "handling cluster spec databases (total {})", + spec.cluster.databases.len() + ); for db in &spec.cluster.databases { let name = &db.name; let pg_db = existing_dbs.get(name); @@ -562,7 +571,7 @@ pub fn handle_databases(spec: &ComputeSpec, client: &mut Client) -> Result<()> { DatabaseAction::Create => " -> create", DatabaseAction::Update => " -> update", }; - info!(" - {}:{}{}", db.name, db.owner, action_str); + info!(" - {}:{}{}", db.name, db.owner, action_str); } }