Compact some compute_ctl logs (#6346)

Print postgres roles in a single line and add some info.
This commit is contained in:
Arthur Petukhovsky
2024-01-12 22:24:22 +04:00
committed by GitHub
parent cd48ea784f
commit 97b48c23f8
4 changed files with 23 additions and 14 deletions

View File

@@ -293,7 +293,7 @@ fn main() -> Result<()> {
let pg = match compute.start_compute(extension_server_port) { let pg = match compute.start_compute(extension_server_port) {
Ok(pg) => Some(pg), Ok(pg) => Some(pg),
Err(err) => { 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(); let mut state = compute.state.lock().unwrap();
state.error = Some(format!("{:?}", err)); state.error = Some(format!("{:?}", err));
state.status = ComputeStatus::Failed; state.status = ComputeStatus::Failed;

View File

@@ -280,7 +280,7 @@ fn create_neon_superuser(spec: &ComputeSpec, client: &mut Client) -> Result<()>
$$;"#, $$;"#,
roles_decl, database_decl, roles_decl, database_decl,
); );
info!("Neon superuser created:\n{}", inlinify(&query)); info!("Neon superuser created: {}", inlinify(&query));
client client
.simple_query(&query) .simple_query(&query)
.map_err(|e| anyhow::anyhow!(e).context(query))?; .map_err(|e| anyhow::anyhow!(e).context(query))?;

View File

@@ -456,7 +456,7 @@ pub fn handle_postgres_logs(stderr: std::process::ChildStderr) -> JoinHandle<()>
/// - no new lines were written for the last second /// - no new lines were written for the last second
async fn handle_postgres_logs_async(stderr: tokio::process::ChildStderr) -> Result<()> { async fn handle_postgres_logs_async(stderr: tokio::process::ChildStderr) -> Result<()> {
let mut lines = tokio::io::BufReader::new(stderr).lines(); 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 = let ts_regex =
regex::Regex::new(r"^\d+-\d{2}-\d{2} \d{2}:\d{2}:\d{2}").expect("regex is valid"); regex::Regex::new(r"^\d+-\d{2}-\d{2} \d{2}:\d{2}:\d{2}").expect("regex is valid");

View File

@@ -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) // Print a list of existing Postgres roles (only in debug mode)
if span_enabled!(Level::INFO) { if span_enabled!(Level::INFO) {
info!("postgres roles:"); let mut vec = Vec::new();
for r in &existing_roles { for r in &existing_roles {
info!( vec.push(format!(
" - {}:{}", "{}:{}",
r.name, r.name,
if r.encrypted_password.is_some() { if r.encrypted_password.is_some() {
"[FILTERED]" "[FILTERED]"
} else { } else {
"(null)" "(null)"
} }
); ));
} }
info!("postgres roles (total {}): {:?}", vec.len(), vec);
} }
// Process delta operations first // 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 // Refresh Postgres roles info to handle possible roles renaming
let existing_roles: Vec<Role> = get_existing_roles(&mut xact)?; let existing_roles: Vec<Role> = 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 { for role in &spec.cluster.roles {
let name = &role.name; let name = &role.name;
// XXX: with a limited number of roles it is fine, but consider making it a HashMap // 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", "CREATE ROLE {} INHERIT CREATEROLE CREATEDB BYPASSRLS REPLICATION IN ROLE neon_superuser",
name.pg_quote() name.pg_quote()
); );
info!("role create query: '{}'", &query); info!("running role create query: '{}'", &query);
query.push_str(&role.to_pg_options()); query.push_str(&role.to_pg_options());
xact.execute(query.as_str(), &[])?; xact.execute(query.as_str(), &[])?;
} }
@@ -319,7 +324,7 @@ pub fn handle_roles(spec: &ComputeSpec, client: &mut Client) -> Result<()> {
RoleAction::Create => " -> create", RoleAction::Create => " -> create",
RoleAction::Update => " -> update", 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) // Print a list of existing Postgres databases (only in debug mode)
if span_enabled!(Level::INFO) { if span_enabled!(Level::INFO) {
info!("postgres databases:"); let mut vec = Vec::new();
for (dbname, db) in &existing_dbs { 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 // 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 // Refresh Postgres databases info to handle possible renames
let existing_dbs = get_existing_dbs(client)?; 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 { for db in &spec.cluster.databases {
let name = &db.name; let name = &db.name;
let pg_db = existing_dbs.get(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::Create => " -> create",
DatabaseAction::Update => " -> update", DatabaseAction::Update => " -> update",
}; };
info!(" - {}:{}{}", db.name, db.owner, action_str); info!(" - {}:{}{}", db.name, db.owner, action_str);
} }
} }