From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id DC1801FF15E for ; Wed, 21 Jan 2026 11:46:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 75823223F2; Wed, 21 Jan 2026 11:46:26 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Wed, 21 Jan 2026 11:45:36 +0100 Message-ID: <20260121104537.495434-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260121104537.495434-1-c.ebner@proxmox.com> References: <20260121104537.495434-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1768992295526 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.048 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox v2 1/1] s3-client: add request statistics gathering capabilities X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Track the per-method request counts and the duration for the last successful request send by a client instance. With the intend to utilize the request statistics in PBS, starting with showing request statistics for garbage collection as a first step. Signed-off-by: Christian Ebner --- changes since version 1: - not present in previous version proxmox-s3-client/src/client.rs | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs index 83176b39..2183fd18 100644 --- a/proxmox-s3-client/src/client.rs +++ b/proxmox-s3-client/src/client.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; use std::str::FromStr; +use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; @@ -135,12 +136,26 @@ impl S3ClientOptions { } } +#[derive(Default)] +/// Request statistics for s3 client instance +struct RequestStats { + /// Number of requests performed by method + delete: AtomicU64, + get: AtomicU64, + head: AtomicU64, + post: AtomicU64, + put: AtomicU64, + /// Duration of the last successfully completed request + last_request_duration: Mutex>, +} + /// S3 client for object stores compatible with the AWS S3 API pub struct S3Client { client: Client, options: S3ClientOptions, authority: Authority, put_rate_limiter: Option>>, + request_stats: Arc, } impl S3Client { @@ -241,6 +256,7 @@ impl S3Client { options, authority, put_rate_limiter, + request_stats: Arc::new(RequestStats::default()), }) } @@ -385,6 +401,16 @@ impl S3Client { tokio::time::sleep(backoff_secs).await; } + match parts.method { + Method::DELETE => self.request_stats.delete.fetch_add(1, Ordering::SeqCst), + Method::GET => self.request_stats.get.fetch_add(1, Ordering::SeqCst), + Method::HEAD => self.request_stats.head.fetch_add(1, Ordering::SeqCst), + Method::POST => self.request_stats.post.fetch_add(1, Ordering::SeqCst), + Method::PUT => self.request_stats.put.fetch_add(1, Ordering::SeqCst), + _ => 0, + }; + + let now = Instant::now(); let response = if let Some(deadline) = deadline { tokio::time::timeout_at(deadline, self.client.request(request)).await } else { @@ -392,7 +418,10 @@ impl S3Client { }; match response { - Ok(Ok(response)) => return Ok(response), + Ok(Ok(response)) => { + *self.request_stats.last_request_duration.lock().unwrap() = Some(now.elapsed()); + return Ok(response); + } Ok(Err(err)) => { if retry >= MAX_S3_HTTP_REQUEST_RETRY - 1 { return Err(err.into()); @@ -409,6 +438,27 @@ impl S3Client { bail!("failed to send request exceeding retries"); } + /// Duration of the last successfully completed request. + pub fn last_request_duration(&self) -> Option { + self.request_stats + .last_request_duration + .lock() + .unwrap() + .clone() + } + + /// Request counts by method for the client since instantiation. + pub fn request_count(&self, method: Method) -> u64 { + match method { + Method::DELETE => self.request_stats.delete.load(Ordering::SeqCst), + Method::GET => self.request_stats.get.load(Ordering::SeqCst), + Method::HEAD => self.request_stats.head.load(Ordering::SeqCst), + Method::POST => self.request_stats.post.load(Ordering::SeqCst), + Method::PUT => self.request_stats.put.load(Ordering::SeqCst), + _ => 0, + } + } + /// Check if bucket exists and got permissions to access it. /// See reference docs: https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html pub async fn head_bucket(&self) -> Result<(), Error> { -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel