From 06a2ca33fbbdb486cc5c662be5cdd759013131aa Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Tue, 4 Feb 2025 13:47:53 +0100 Subject: [PATCH] Better tracing during the migration --- crates/cli/src/commands/syn2mas.rs | 1 + crates/syn2mas/src/mas_writer/checks.rs | 8 ++++++-- crates/syn2mas/src/mas_writer/constraint_pausing.rs | 2 ++ crates/syn2mas/src/mas_writer/mod.rs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/commands/syn2mas.rs b/crates/cli/src/commands/syn2mas.rs index 5b377d232..3cde31623 100644 --- a/crates/cli/src/commands/syn2mas.rs +++ b/crates/cli/src/commands/syn2mas.rs @@ -80,6 +80,7 @@ enum Subcommand { const NUM_WRITER_CONNECTIONS: usize = 8; impl Options { + #[tracing::instrument("cli.syn2mas.run", skip_all)] #[allow(clippy::too_many_lines)] pub async fn run(self, figment: &Figment) -> anyhow::Result { warn!( diff --git a/crates/syn2mas/src/mas_writer/checks.rs b/crates/syn2mas/src/mas_writer/checks.rs index 64c140bde..d5b51b510 100644 --- a/crates/syn2mas/src/mas_writer/checks.rs +++ b/crates/syn2mas/src/mas_writer/checks.rs @@ -10,6 +10,7 @@ use thiserror::Error; use thiserror_ext::ContextInto; +use tracing::Instrument as _; use super::{MAS_TABLES_AFFECTED_BY_MIGRATION, is_syn2mas_in_progress, locking::LockedMasDatabase}; @@ -46,7 +47,7 @@ pub enum Error { /// - If any MAS tables involved in the migration are not empty. /// - If we can't check whether syn2mas is already in progress on this database /// or not. -#[tracing::instrument(skip_all)] +#[tracing::instrument(name = "syn2mas.mas_pre_migration_checks", skip_all)] pub async fn mas_pre_migration_checks(mas_connection: &mut LockedMasDatabase) -> Result<(), Error> { if is_syn2mas_in_progress(mas_connection.as_mut()) .await @@ -60,8 +61,11 @@ pub async fn mas_pre_migration_checks(mas_connection: &mut LockedMasDatabase) -> // empty database. for &table in MAS_TABLES_AFFECTED_BY_MIGRATION { - let row_present = sqlx::query(&format!("SELECT 1 AS dummy FROM {table} LIMIT 1")) + let query = format!("SELECT 1 AS dummy FROM {table} LIMIT 1"); + let span = tracing::info_span!("db.query", db.query.text = query); + let row_present = sqlx::query(&query) .fetch_optional(mas_connection.as_mut()) + .instrument(span) .await .into_maybe_not_mas(table)? .is_some(); diff --git a/crates/syn2mas/src/mas_writer/constraint_pausing.rs b/crates/syn2mas/src/mas_writer/constraint_pausing.rs index ae79e70ab..36783215f 100644 --- a/crates/syn2mas/src/mas_writer/constraint_pausing.rs +++ b/crates/syn2mas/src/mas_writer/constraint_pausing.rs @@ -123,6 +123,8 @@ pub async fn restore_constraint( table_name, definition, } = &constraint; + info!("rebuilding constraint {name}"); + sqlx::query(&format!( "ALTER TABLE {table_name} ADD CONSTRAINT {name} {definition};" )) diff --git a/crates/syn2mas/src/mas_writer/mod.rs b/crates/syn2mas/src/mas_writer/mod.rs index 6fd9e5df4..a56e69980 100644 --- a/crates/syn2mas/src/mas_writer/mod.rs +++ b/crates/syn2mas/src/mas_writer/mod.rs @@ -389,7 +389,7 @@ impl MasWriter { /// /// - If the database connection experiences an error. #[allow(clippy::missing_panics_doc)] // not real - #[tracing::instrument(skip_all)] + #[tracing::instrument(name = "syn2mas.mas_writer.new", skip_all)] pub async fn new( mut conn: LockedMasDatabase, mut writer_connections: Vec,