Skip to content

Commit b9b227f

Browse files
authored
Merge pull request #1992 from input-output-hk/djo/1981/enhance_logs_in_signer
Enhance logs in mithril-signer and mithril-persistence
2 parents 03aa794 + ca7789a commit b9b227f

File tree

23 files changed

+797
-253
lines changed

23 files changed

+797
-253
lines changed

Cargo.lock

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-persistence/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-persistence"
3-
version = "0.2.27"
3+
version = "0.2.28"
44
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -29,7 +29,4 @@ tokio = { version = "1.40.0", features = ["sync"] }
2929
[dev-dependencies]
3030
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
3131
mockall = "0.13.0"
32-
slog-async = "2.8.0"
33-
slog-scope = "4.4.0"
34-
slog-term = "2.9.1"
3532
tokio = { version = "1.40.0", features = ["macros", "time"] }

internal/mithril-persistence/src/database/version_checker.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use anyhow::{anyhow, Context};
22
use chrono::Utc;
3-
use mithril_common::StdResult;
43
use slog::{debug, error, info, Logger};
54
use std::{cmp::Ordering, collections::BTreeSet};
65

6+
use mithril_common::logging::LoggerExtensions;
7+
use mithril_common::StdResult;
8+
79
use super::{
810
ApplicationNodeType, DatabaseVersion, DbVersion, GetDatabaseVersionQuery,
911
UpdateDatabaseVersionQuery,
@@ -38,7 +40,7 @@ impl<'conn> DatabaseVersionChecker<'conn> {
3840
Self {
3941
connection,
4042
application_type,
41-
logger,
43+
logger: logger.new_with_component_name::<Self>(),
4244
migrations,
4345
}
4446
}
@@ -203,6 +205,10 @@ mod tests {
203205

204206
use super::*;
205207

208+
fn discard_logger() -> Logger {
209+
Logger::root(slog::Discard, slog::o!())
210+
}
211+
206212
fn check_database_version(connection: &SqliteConnection, db_version: DbVersion) {
207213
let version = connection
208214
.fetch_first(GetDatabaseVersionQuery::get_application_version(
@@ -243,7 +249,7 @@ mod tests {
243249
let (_filepath, connection) =
244250
create_sqlite_file("test_upgrade_with_migration.sqlite3").unwrap();
245251
let mut db_checker = DatabaseVersionChecker::new(
246-
slog_scope::logger(),
252+
discard_logger(),
247253
ApplicationNodeType::Aggregator,
248254
&connection,
249255
);
@@ -302,7 +308,7 @@ mod tests {
302308
fn starting_with_migration() {
303309
let (_filepath, connection) = create_sqlite_file("starting_with_migration").unwrap();
304310
let mut db_checker = DatabaseVersionChecker::new(
305-
slog_scope::logger(),
311+
discard_logger(),
306312
ApplicationNodeType::Aggregator,
307313
&connection,
308314
);
@@ -325,7 +331,7 @@ mod tests {
325331
fn test_failing_migration() {
326332
let (_filepath, connection) = create_sqlite_file("test_failing_migration").unwrap();
327333
let mut db_checker = DatabaseVersionChecker::new(
328-
slog_scope::logger(),
334+
discard_logger(),
329335
ApplicationNodeType::Aggregator,
330336
&connection,
331337
);
@@ -356,7 +362,7 @@ mod tests {
356362
fn test_fail_downgrading() {
357363
let (_filepath, connection) = create_sqlite_file("test_fail_downgrading").unwrap();
358364
let mut db_checker = DatabaseVersionChecker::new(
359-
slog_scope::logger(),
365+
discard_logger(),
360366
ApplicationNodeType::Aggregator,
361367
&connection,
362368
);
@@ -371,7 +377,7 @@ mod tests {
371377

372378
// re instantiate a new checker with no migration registered (version 0).
373379
let db_checker = DatabaseVersionChecker::new(
374-
slog_scope::logger(),
380+
discard_logger(),
375381
ApplicationNodeType::Aggregator,
376382
&connection,
377383
);

internal/mithril-persistence/src/sqlite/cleaner.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use slog::{debug, Logger};
22

3+
use mithril_common::logging::LoggerExtensions;
34
use mithril_common::StdResult;
45

56
use crate::sqlite::SqliteConnection;
@@ -24,9 +25,9 @@ impl SqliteCleaningTask {
2425
/// Get the log message for the task.
2526
pub fn log_message(self: SqliteCleaningTask) -> &'static str {
2627
match self {
27-
SqliteCleaningTask::Vacuum => "SqliteCleaner::Running `vacuum` on the database",
28+
SqliteCleaningTask::Vacuum => "Running `vacuum` on the SQLite database",
2829
SqliteCleaningTask::WalCheckpointTruncate => {
29-
"SqliteCleaner::Running `wal_checkpoint(TRUNCATE)` on the database"
30+
"Running `wal_checkpoint(TRUNCATE)` on the SQLite database"
3031
}
3132
}
3233
}
@@ -52,7 +53,7 @@ impl<'a> SqliteCleaner<'a> {
5253

5354
/// Set the logger to be used by the cleaner.
5455
pub fn with_logger(mut self, logger: Logger) -> Self {
55-
self.logger = logger;
56+
self.logger = logger.new_with_component_name::<Self>();
5657
self
5758
}
5859

internal/mithril-persistence/src/sqlite/connection_builder.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::ops::Not;
22
use std::path::{Path, PathBuf};
33

44
use anyhow::Context;
5-
use slog::Logger;
5+
use slog::{debug, Logger};
66
use sqlite::{Connection, ConnectionThreadSafe};
77

8+
use mithril_common::logging::LoggerExtensions;
89
use mithril_common::StdResult;
910

1011
use crate::database::{ApplicationNodeType, DatabaseVersionChecker, SqlMigration};
@@ -15,7 +16,7 @@ pub struct ConnectionBuilder {
1516
sql_migrations: Vec<SqlMigration>,
1617
options: Vec<ConnectionOptions>,
1718
node_type: ApplicationNodeType,
18-
logger: Logger,
19+
base_logger: Logger,
1920
}
2021

2122
/// Options to apply to the connection
@@ -41,7 +42,7 @@ impl ConnectionBuilder {
4142
sql_migrations: vec![],
4243
options: vec![],
4344
node_type: ApplicationNodeType::Signer,
44-
logger: Logger::root(slog::Discard, slog::o!()),
45+
base_logger: Logger::root(slog::Discard, slog::o!()),
4546
}
4647
}
4748

@@ -66,7 +67,7 @@ impl ConnectionBuilder {
6667

6768
/// Set the logger to log to at build time
6869
pub fn with_logger(mut self, logger: Logger) -> Self {
69-
self.logger = logger;
70+
self.base_logger = logger;
7071
self
7172
}
7273

@@ -78,6 +79,9 @@ impl ConnectionBuilder {
7879

7980
/// Build a connection based on the builder configuration
8081
pub fn build(self) -> StdResult<ConnectionThreadSafe> {
82+
let logger = self.base_logger.new_with_component_name::<Self>();
83+
84+
debug!(logger, "Opening SQLite connection"; "path" => self.connection_path.display());
8185
let connection =
8286
Connection::open_thread_safe(&self.connection_path).with_context(|| {
8387
format!(
@@ -90,21 +94,24 @@ impl ConnectionBuilder {
9094
.options
9195
.contains(&ConnectionOptions::EnableWriteAheadLog)
9296
{
97+
debug!(logger, "Enabling SQLite Write Ahead Log journal mode");
9398
connection
9499
.execute("pragma journal_mode = wal; pragma synchronous = normal;")
95100
.with_context(|| "SQLite initialization: could not enable WAL.")?;
96101
}
97102

98103
if self.options.contains(&ConnectionOptions::EnableForeignKeys) {
104+
debug!(logger, "Enabling SQLite foreign key support");
99105
connection
100106
.execute("pragma foreign_keys=true")
101107
.with_context(|| "SQLite initialization: could not enable FOREIGN KEY support.")?;
102108
}
103109

104110
if self.sql_migrations.is_empty().not() {
105111
// Check database migrations
112+
debug!(logger, "Applying database migrations");
106113
let mut db_checker =
107-
DatabaseVersionChecker::new(self.logger, self.node_type, &connection);
114+
DatabaseVersionChecker::new(self.base_logger, self.node_type, &connection);
108115

109116
for migration in self.sql_migrations {
110117
db_checker.add_migration(migration);
@@ -119,6 +126,7 @@ impl ConnectionBuilder {
119126
.options
120127
.contains(&ConnectionOptions::ForceDisableForeignKeys)
121128
{
129+
debug!(logger, "Force disabling SQLite foreign key support");
122130
connection
123131
.execute("pragma foreign_keys=false")
124132
.with_context(|| "SQLite initialization: could not disable FOREIGN KEY support.")?;

mithril-signer/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-signer"
3-
version = "0.2.195"
3+
version = "0.2.196"
44
description = "A Mithril Signer"
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -38,7 +38,6 @@ slog = { version = "2.7.0", features = [
3838
] }
3939
slog-async = "2.8.0"
4040
slog-bunyan = "2.5.0"
41-
slog-scope = "4.4.0"
4241
sqlite = { version = "0.36.1", features = ["bundled"] }
4342
thiserror = "1.0.63"
4443
tokio = { version = "1.40.0", features = ["full"] }
@@ -48,10 +47,12 @@ tikv-jemallocator = { version = "0.6.0", optional = true }
4847

4948
[dev-dependencies]
5049
criterion = { version = "0.5.1", features = ["html_reports", "async_tokio"] }
50+
http = "1.1.0"
5151
httpmock = "0.7.0"
5252
mithril-common = { path = "../mithril-common" }
5353
mockall = "0.13.0"
5454
prometheus-parse = "0.2.5"
55+
slog-scope = "4.4.0"
5556
slog-term = "2.9.1"
5657

5758
[features]

0 commit comments

Comments
 (0)