fix(logging): enforce single-writer sinks and bound tracing (#4765)

* fix(obs): prevent rolling log stdout aliasing

* fix(ecstore): bound hot-path tracing payloads

* test(logging): guard service and disk log invariants

* fix(obs): silence useless_conversion on st_dev for Linux clippy

rustix's Stat.st_dev is u64 on Linux/glibc, making u64::try_from a no-op
that trips clippy::useless_conversion under -D warnings. The conversion is
still needed on macOS/BSD where st_dev is a signed dev_t, so suppress the
lint on that line rather than dropping the portable fallible conversion.

* fix(logging): keep stdout sink validation portable (#4769)

* fix(obs): keep stdout device conversion portable

* docs(logging): update single-writer plan status

---------

Co-authored-by: overtrue <anzhengchao@gmail.com>
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
cxymds
2026-07-12 16:03:01 +08:00
committed by GitHub
parent 2ddafb4ed9
commit d8e69a3adf
14 changed files with 539 additions and 153 deletions
+69 -69
View File
@@ -68,7 +68,7 @@ use tokio::{
};
use tokio_util::sync::CancellationToken;
use tonic::{Code, Request, service::interceptor::InterceptedService, transport::Channel};
use tracing::{debug, warn};
use tracing::{debug, trace, warn};
use uuid::Uuid;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -1151,40 +1151,40 @@ fn decode_batch_read_version_response_items(
#[async_trait::async_trait]
impl DiskAPI for RemoteDisk {
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn to_string(&self) -> String {
self.endpoint.to_string()
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn is_online(&self) -> bool {
// If disk is marked as faulty, consider it offline
!self.health.is_faulty()
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn is_local(&self) -> bool {
false
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn host_name(&self) -> String {
self.endpoint.host_port()
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn endpoint(&self) -> Endpoint {
self.endpoint.clone()
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn close(&self) -> Result<()> {
self.cancel_token.cancel();
Ok(())
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn get_disk_id(&self) -> Result<Option<Uuid>> {
Ok(*self.id.lock().await)
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn set_disk_id(&self, id: Option<Uuid>) -> Result<()> {
let mut lock = self.id.lock().await;
*lock = id;
@@ -1192,12 +1192,12 @@ impl DiskAPI for RemoteDisk {
Ok(())
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn path(&self) -> PathBuf {
PathBuf::from(self.endpoint.get_file_path())
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn get_disk_location(&self) -> DiskLocation {
DiskLocation {
pool_idx: {
@@ -1224,9 +1224,9 @@ impl DiskAPI for RemoteDisk {
}
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn make_volume(&self, volume: &str) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1261,9 +1261,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn make_volumes(&self, volumes: Vec<&str>) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1298,9 +1298,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn list_volumes(&self) -> Result<Vec<VolumeInfo>> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1339,9 +1339,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn stat_volume(&self, volume: &str) -> Result<VolumeInfo> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1378,9 +1378,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn delete_volume(&self, volume: &str, force_delete: bool) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1416,7 +1416,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn delete_version(
&self,
volume: &str,
@@ -1425,7 +1425,7 @@ impl DiskAPI for RemoteDisk {
force_del_marker: bool,
opts: DeleteOptions,
) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1476,9 +1476,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn delete_versions(&self, volume: &str, versions: Vec<FileInfoVersions>, opts: DeleteOptions) -> Vec<Option<Error>> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1606,9 +1606,9 @@ impl DiskAPI for RemoteDisk {
.collect()
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn delete_paths(&self, volume: &str, paths: &[String]) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1646,9 +1646,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn write_metadata(&self, _org_volume: &str, volume: &str, path: &str, fi: FileInfo) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1722,9 +1722,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn update_metadata(&self, volume: &str, path: &str, fi: FileInfo, opts: &UpdateMetadataOpts) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1771,7 +1771,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_version(
&self,
_org_volume: &str,
@@ -1780,7 +1780,7 @@ impl DiskAPI for RemoteDisk {
version_id: &str,
opts: &ReadOptions,
) -> Result<FileInfo> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1833,7 +1833,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self, req))]
#[tracing::instrument(level = "trace", skip_all)]
async fn batch_read_version(&self, req: BatchReadVersionReq) -> Result<Vec<BatchReadVersionResp>> {
validate_batch_read_version_item_count(req.items.len())?;
@@ -1844,7 +1844,7 @@ impl DiskAPI for RemoteDisk {
}
record_batch_read_version_gate_decision(mode, BATCH_READ_VERSION_GATE_ATTEMPT);
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1926,9 +1926,9 @@ impl DiskAPI for RemoteDisk {
}
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_xl(&self, volume: &str, path: &str, read_data: bool) -> Result<RawFileInfo> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -1971,7 +1971,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn rename_data(
&self,
src_volume: &str,
@@ -1980,7 +1980,7 @@ impl DiskAPI for RemoteDisk {
dst_volume: &str,
dst_path: &str,
) -> Result<RenameDataResp> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2032,9 +2032,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn list_dir(&self, _origvolume: &str, volume: &str, dir_path: &str, count: i32) -> Result<Vec<String>> {
debug!("list_dir {}/{}", volume, dir_path);
trace!(volume, dir_path, "Remote disk list_dir RPC started");
self.execute_with_timeout(
|| async {
@@ -2064,9 +2064,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self, wr))]
#[tracing::instrument(level = "trace", skip_all)]
async fn walk_dir<W: AsyncWrite + Unpin + Send>(&self, opts: WalkDirOptions, wr: &mut W) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2142,12 +2142,12 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_file(&self, volume: &str, path: &str) -> Result<FileReader> {
self.read_file_stream(volume, path, 0, 0).await
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_file_stream(&self, volume: &str, path: &str, offset: usize, length: usize) -> Result<FileReader> {
// warn!(
// "disk remote read_file_stream {}/{}/{} offset={} length={}",
@@ -2177,7 +2177,7 @@ impl DiskAPI for RemoteDisk {
/// Buffered read for remote disks.
/// The transport stream is collected into owned Bytes for caller sharing.
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_file_mmap_copy(&self, volume: &str, path: &str, offset: usize, length: usize) -> Result<Bytes> {
// For remote disks, use the regular reader and read into Bytes
let reader = self.read_file_stream(volume, path, offset, length).await?;
@@ -2192,9 +2192,9 @@ impl DiskAPI for RemoteDisk {
Ok(Bytes::from(buffer))
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn append_file(&self, volume: &str, path: &str) -> Result<FileWriter> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2221,7 +2221,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn create_file(&self, _origvolume: &str, volume: &str, path: &str, file_size: i64) -> Result<FileWriter> {
// warn!(
// "disk remote create_file {}/{}/{} file_size={}",
@@ -2246,9 +2246,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(level = "debug", skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn rename_file(&self, src_volume: &str, src_path: &str, dst_volume: &str, dst_path: &str) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2289,9 +2289,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn rename_part(&self, src_volume: &str, src_path: &str, dst_volume: &str, dst_path: &str, meta: Bytes) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2333,9 +2333,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn delete(&self, volume: &str, path: &str, opt: DeleteOptions) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2376,9 +2376,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn verify_file(&self, volume: &str, path: &str, fi: &FileInfo) -> Result<CheckPartsResp> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2419,9 +2419,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_parts(&self, bucket: &str, paths: &[String]) -> Result<Vec<ObjectPartInfo>> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2458,9 +2458,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn check_parts(&self, volume: &str, path: &str, fi: &FileInfo) -> Result<CheckPartsResp> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2501,9 +2501,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_multiple(&self, req: ReadMultipleReq) -> Result<Vec<ReadMultipleResp>> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2549,9 +2549,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn write_all(&self, volume: &str, path: &str, data: Bytes) -> Result<()> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2602,9 +2602,9 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes> {
debug!(
trace!(
event = EVENT_REMOTE_DISK_RPC,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REMOTE_DISK,
@@ -2655,7 +2655,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
async fn disk_info(&self, opts: &DiskInfoOptions) -> Result<DiskInfo> {
// disk_info is idempotent/read-only, so it is eligible for the P3-3 bounded retry.
self.execute_read_with_retry(
@@ -2686,7 +2686,7 @@ impl DiskAPI for RemoteDisk {
.await
}
#[tracing::instrument(skip(self))]
#[tracing::instrument(level = "trace", skip_all)]
fn start_scan(&self) -> ScanGuard {
self.scanning.fetch_add(1, Ordering::Relaxed);
ScanGuard(Arc::clone(&self.scanning))