From b5fa07084b193d0945aa06b04661f7856e65173e Mon Sep 17 00:00:00 2001 From: Nikhil Sinha Date: Mon, 29 Apr 2024 11:17:52 +0530 Subject: [PATCH] fix for staging size metrics - to subtract the size of the arrow file removed from staging fix for GET /cache - to return error in case global cache is not set --- server/src/handlers/http/logstream.rs | 10 ++++++++++ server/src/storage/staging.rs | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/server/src/handlers/http/logstream.rs b/server/src/handlers/http/logstream.rs index f7974220c..433ec3651 100644 --- a/server/src/handlers/http/logstream.rs +++ b/server/src/handlers/http/logstream.rs @@ -338,6 +338,16 @@ pub async fn put_retention( pub async fn get_cache_enabled(req: HttpRequest) -> Result { let stream_name: String = req.match_info().get("logstream").unwrap().parse().unwrap(); + + match CONFIG.parseable.mode { + Mode::Ingest | Mode::All => { + if CONFIG.parseable.local_cache_path.is_none() { + return Err(StreamError::CacheNotEnabled(stream_name)); + } + } + _ => {} + } + let cache_enabled = STREAM_INFO.cache_enabled(&stream_name)?; Ok((web::Json(cache_enabled), StatusCode::OK)) } diff --git a/server/src/storage/staging.rs b/server/src/storage/staging.rs index 512a9c4c0..fa689f0b8 100644 --- a/server/src/storage/staging.rs +++ b/server/src/storage/staging.rs @@ -247,10 +247,16 @@ pub fn convert_disk_files_to_parquet( writer.close()?; for file in files { - if fs::remove_file(file).is_err() { + let file_size = file.metadata().unwrap().len(); + let file_type = file.extension().unwrap().to_str().unwrap(); + + if fs::remove_file(file.clone()).is_err() { log::error!("Failed to delete file. Unstable state"); process::abort() } + metrics::STORAGE_SIZE + .with_label_values(&["staging", stream, file_type]) + .sub(file_size as i64); } }