From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id C456B1FF0B7 for ; Mon, 30 Nov 2026 21:09:52 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id EAD3E20324; Mon, 30 Nov 2026 21:09:51 +0100 (CET) Message-ID: Date: Mon, 30 Nov 2026 21:09:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests To: Jakob Klocker , pdm-devel@lists.proxmox.com References: <20261127140358.205440-1-j.klocker@proxmox.com> <20261127140358.205440-3-j.klocker@proxmox.com> Content-Language: en-US From: Thomas Lamprecht Autocrypt: addr=t.lamprecht@proxmox.com; keydata= xsFNBFsLjcYBEACsaQP6uTtw/xHTUCKF4VD4/Wfg7gGn47+OfCKJQAD+Oyb3HSBkjclopC5J uXsB1vVOfqVYE6PO8FlD2L5nxgT3SWkc6Ka634G/yGDU3ZC3C/7NcDVKhSBI5E0ww4Qj8s9w OQRloemb5LOBkJNEUshkWRTHHOmk6QqFB/qBPW2COpAx6oyxVUvBCgm/1S0dAZ9gfkvpqFSD 90B5j3bL6i9FIv3YGUCgz6Ue3f7u+HsEAew6TMtlt90XV3vT4M2IOuECG/pXwTy7NtmHaBQ7 UJBcwSOpDEweNob50+9B4KbnVn1ydx+K6UnEcGDvUWBkREccvuExvupYYYQ5dIhRFf3fkS4+ wMlyAFh8PQUgauod+vqs45FJaSgTqIALSBsEHKEs6IoTXtnnpbhu3p6XBin4hunwoBFiyYt6 YHLAM1yLfCyX510DFzX/Ze2hLqatqzY5Wa7NIXqYYelz7tXiuCLHP84+sV6JtEkeSUCuOiUY virj6nT/nJK8m0BzdR6FgGtNxp7RVXFRz/+mwijJVLpFsyG1i0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JUXjTNEDxEYbF55SdGBHHOAcZtA kEQKub86e+GHA+Z8oXQSGeSGOkqHi7zfgW1UexddTvaRwE6AyZ6FxTApm8wq8NT2cryWPWTF BDSGB3ujWHMM8ERRYJPcBSjTvt0GcEqnd+OSGgxTkGOdufn51oz82zfpVo1t+J/FNz6MRMcg 8nEC+uKvgzH1nujxJ5pRCBOquFZaGn/p71Yr0oVitkttLKblFsqwa+10Lt6HBxm+2+VLp4Ja 0WZNncZciz3V3cuArpan/ZhhyiWYV5FD0pOXPCJIx7WS9PTtxiv0AOS4ScWEUmBxyhFeOpYa DrEx In-Reply-To: <20261127140358.205440-3-j.klocker@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796069385393 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.149 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: AZEFKQRKCZSCF6WDVISJVHIW6ZZLOFCH X-Message-ID-Hash: AZEFKQRKCZSCF6WDVISJVHIW6ZZLOFCH X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Am 27.11.26 um 15:04 schrieb Jakob Klocker: > Exporting the full metric history of a large PVE cluster can take > minutes: on a 25-node cluster with about 2800 guests, the export took > 2m43s. The client's request timeout of 60 seconds cut such requests > off, and the request was repeated on every other endpoint of the remote > until all of its nodes were marked unreachable, so no metrics were ever > collected for such a cluster. > > Use a client with a 5 minute timeout for fetching the metrics of PVE > remotes. All other requests keep the shorter timeout, so they still > fail over quickly to the next endpoint when a node does not answer. > > Signed-off-by: Jakob Klocker > --- > server/src/metric_collection/remote_collection_task.rs | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/server/src/metric_collection/remote_collection_task.rs b/server/src/metric_collection/remote_collection_task.rs > index 1e0011cb..b5d102fa 100644 > --- a/server/src/metric_collection/remote_collection_task.rs > +++ b/server/src/metric_collection/remote_collection_task.rs > @@ -36,6 +36,9 @@ const METRIC_COLLECTION_STATE_FILE: &str = concat!( > > pub const MAX_CONCURRENT_CONNECTIONS: usize = 20; > > +/// Timeout for fetching the metrics of a PVE remote. > +const PVE_METRICS_REQUEST_TIMEOUT: Duration = Duration::from_secs(5 * 60); > + > /// Default metric collection interval. > pub const DEFAULT_COLLECTION_INTERVAL: u64 = 600; > /// Minimum metric collection interval. > @@ -315,7 +318,9 @@ impl RemoteMetricCollectionTask { > let res: Result = async { > match remote.ty { > RemoteType::Pve => { > - let client = app.client_factory().make_pve_client(&remote)?; > + let client = app > + .client_factory() > + .make_pve_client_with_timeout(&remote, PVE_METRICS_REQUEST_TIMEOUT)?; > let metrics = client > .cluster_metrics_export( > Some(true), As per my reply to the [v1] this should not be required, but if I'd also add a general timeout to avoid that retrying all other nodes on a remote adds up to a huge total timeout (12 nodes one hour), i.e. something like bellow the scissors. [v1]: https://lore.proxmox.com/pdm-devel/3278ee5b-95a3-4477-90de-e863359340ef@proxmox.com/ ----8<---- >>From 6563186dfe3f3ae2b58c278143e02361a0ff5ca2 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 30 Nov 2026 17:41:25 +0100 Subject: [PATCH datacenter-manager] metric collection: bound the whole PVE metric export by its timeout The 5 minute timeout of the metric client applies to each node it tries. A request that times out is repeated on the other nodes of the remote, which are each marked unreachable. As the collection task waits for all remotes before it handles anything else, an export that never finishes in time could stall the metric collection of all remotes, and manually triggered collections, for 5 minutes per node, and leave all nodes of the remote marked unreachable for other requests. Apply the 5 minutes to the whole export instead, including a backfill of lagging nodes, and give each node a bit longer, so that a stalled export ends after 5 minutes without trying the other nodes or marking the node unreachable. A node that refuses the connection is still skipped right away. A backfill cut off by the deadline counts as failed, so the data of its nodes is kept back for the next collection. Signed-off-by: Thomas Lamprecht --- .../remote_collection_task.rs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/server/src/metric_collection/remote_collection_task.rs b/server/src/metric_collection/remote_collection_task.rs index bf693dd32..bc3c8481b 100644 --- a/server/src/metric_collection/remote_collection_task.rs +++ b/server/src/metric_collection/remote_collection_task.rs @@ -4,7 +4,7 @@ use std::{ time::{Duration, Instant}, }; -use anyhow::Error; +use anyhow::{Error, format_err}; use tokio::{ sync::{ OwnedSemaphorePermit, Semaphore, @@ -51,8 +51,11 @@ const METRIC_COLLECTION_STATE_FILE: &str = concat!( pub const MAX_CONCURRENT_CONNECTIONS: usize = 20; -/// Timeout for fetching the metrics of a PVE remote. +/// Timeout for the whole metric export of a PVE remote, including a backfill of lagging nodes. const PVE_METRICS_REQUEST_TIMEOUT: Duration = Duration::from_secs(5 * 60); +/// Each node gets a bit longer than the whole export, so that a stalled export ends by the overall +/// deadline instead of marking the node unreachable. +const PVE_METRICS_NODE_TIMEOUT: Duration = Duration::from_secs(5 * 60 + 30); /// Minimum time between two collections from a remote. pub const MIN_COLLECTION_INTERVAL: u64 = 10; @@ -379,7 +382,7 @@ impl RemoteMetricCollectionTask { RemoteType::Pve => { let client = app .client_factory() - .make_pve_client_with_timeout(&remote, PVE_METRICS_REQUEST_TIMEOUT)?; + .make_pve_client_with_timeout(&remote, PVE_METRICS_NODE_TIMEOUT)?; let (metrics, store_request_at, duration) = collect_pve_metrics( &remote.id, &status, @@ -459,13 +462,21 @@ async fn collect_pve_metrics( epoch_now: impl Fn() -> i64, ) -> Result<(ClusterMetrics, i64, Duration), Error> { let mut duration = Duration::ZERO; + // Without an overall deadline, an export that never finishes in time would be repeated on + // every other node, while no other remote gets collected. + let deadline = tokio::time::Instant::now() + PVE_METRICS_REQUEST_TIMEOUT; let mut export = async |nodes, start_time| { let start = tokio::time::Instant::now(); - let response = client - .cluster_metrics_export(Some(true), Some(false), nodes, Some(start_time)) - .await; + let request = + client.cluster_metrics_export(Some(true), Some(false), nodes, Some(start_time)); + let response = tokio::time::timeout_at(deadline, request).await; duration += start.elapsed(); - let mut metrics = response?; + let mut metrics = response.map_err(|_| { + format_err!( + "metric export did not finish within {} seconds", + PVE_METRICS_REQUEST_TIMEOUT.as_secs() + ) + })??; let received_at = epoch_now(); let cutoff = received_at + FUTURE_DATAPOINT_TOLERANCE; let count = metrics.data.len(); -- 2.47.3