Skip to content

Commit

Permalink
Merge pull request #1807 from tursodatabase/audit-log-for-config-change
Browse files Browse the repository at this point in the history
add info log about all config changes
  • Loading branch information
sivukhin authored Nov 7, 2024
2 parents 25c5f8e + 5487d2b commit fa06fc2
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions libsql-server/src/http/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +324,42 @@ async fn handle_post_config<C>(
}
let store = app_state
.namespaces
.config_store(NamespaceName::from_string(namespace)?)
.config_store(NamespaceName::from_string(namespace.clone())?)
.await?;
let mut config = (*store.get()).clone();
config.block_reads = req.block_reads;
config.block_writes = req.block_writes;
config.block_reason = req.block_reason;
config.allow_attach = req.allow_attach;
config.txn_timeout = req.txn_timeout_s.map(Duration::from_secs);
let original = (*store.get()).clone();
let mut updated = original.clone();
updated.block_reads = req.block_reads;
updated.block_writes = req.block_writes;
updated.block_reason = req.block_reason;
updated.allow_attach = req.allow_attach;
updated.txn_timeout = req.txn_timeout_s.map(Duration::from_secs);
if let Some(size) = req.max_db_size {
config.max_db_pages = size.as_u64() / LIBSQL_PAGE_SIZE;
updated.max_db_pages = size.as_u64() / LIBSQL_PAGE_SIZE;
}
if let Some(url) = req.heartbeat_url {
config.heartbeat_url = Some(Url::parse(&url)?);
updated.heartbeat_url = Some(Url::parse(&url)?);
}
config.jwt_key = req.jwt_key;
updated.jwt_key = req.jwt_key;
if let Some(mode) = req.durability_mode {
config.durability_mode = mode;
updated.durability_mode = mode;
}

store.store(config).await?;
store.store(updated.clone()).await?;
// we better to not log jwt token - so let's explicitly log necessary fields
tracing::info!(
message = "updated db config",
namespace = namespace,
block_writes_before = original.block_writes,
block_writes_after = updated.block_writes,
block_reads_before = original.block_reads,
block_reads_after = updated.block_reads,
allow_attach_before = original.allow_attach,
allow_attach_after = updated.allow_attach,
max_db_pages_before = original.max_db_pages,
max_db_pages_after = updated.max_db_pages,
durability_mode_before = original.durability_mode.to_string(),
durability_mode_after = updated.durability_mode.to_string(),
);

Ok(())
}
Expand Down

0 comments on commit fa06fc2

Please sign in to comment.