* [PATCH proxmox-datacenter-manager v2 0/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests @ 2026-11-27 14:03 Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 1/2] connection: allow creating PVE clients with a custom request timeout Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker 0 siblings, 2 replies; 5+ messages in thread From: Jakob Klocker @ 2026-11-27 14:03 UTC (permalink / raw) To: pdm-devel Exporting the full metric history of a large PVE cluster takes minutes (2m43s on the reporter's 25-node cluster [0][1]), but PDM gives up on a request to a remote after 60 seconds and repeats it on every other endpoint, until all of them are marked unreachable. No metrics are ever collected for such a cluster. This series uses a separate client with a 5 minute request timeout for fetching PVE metrics. All other requests keep the regular 60 seconds, so they still fail over quickly when a node does not answer. v1 assumed that pveproxy cuts such requests off after 30 seconds, which isn't the case: pveproxy does not limit this request, the timeout is PDM's own. With the export handler delayed by 90 seconds on a test cluster, PDM gave up after 60 seconds with the message from the bug report, while pveproxy still answered the request in full after 90 seconds. Testing: with the export handler delayed by 180 seconds, both manual and regular, timer-driven metric collections now succeed after ~180s. Changes since v1: - Drop fetching large clusters node by node, use a longer request timeout for the metric collection instead. This fixes the reported issue for now. As a follow-up, the export endpoint in PVE will fetch the metrics of the other cluster nodes concurrently, which should shorten such requests. The longer timeout may still be needed for the initial import of a large cluster's full metric history. [0] https://bugzilla.proxmox.com/show_bug.cgi?id=7731 [1] https://forum.proxmox.com/threads/getting-client-timeouts-in-pdm-system-log.184344/#post-858021 proxmox-datacenter-manager: Jakob Klocker (2): connection: allow creating PVE clients with a custom request timeout fix #7731: metric collection: allow 5 minutes for PVE metric requests server/src/connection.rs | 49 ++++++++++++++++--- .../remote_collection_task.rs | 7 ++- 2 files changed, 47 insertions(+), 9 deletions(-) Summary over all repositories: 2 files changed, 47 insertions(+), 9 deletions(-) -- Generated by murpp 0.12.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH proxmox-datacenter-manager v2 1/2] connection: allow creating PVE clients with a custom request timeout 2026-11-27 14:03 [PATCH proxmox-datacenter-manager v2 0/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker @ 2026-11-27 14:03 ` Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker 1 sibling, 0 replies; 5+ messages in thread From: Jakob Klocker @ 2026-11-27 14:03 UTC (permalink / raw) To: pdm-devel Some requests to remotes can legitimately take longer than the regular request timeout of 60 seconds, for example exporting the full metric history of a large cluster. Allow creating PVE clients with a different request timeout. Such clients are created separately instead of being taken from the connection cache, so all other requests to the remote keep using the shared cached client with the regular timeout. Signed-off-by: Jakob Klocker <j.klocker@proxmox.com> --- server/src/connection.rs | 49 +++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/server/src/connection.rs b/server/src/connection.rs index 24aab041..4189fc1b 100644 --- a/server/src/connection.rs +++ b/server/src/connection.rs @@ -261,6 +261,19 @@ pub trait ClientFactory { self.make_pve_client(remote) } + /// Create a new API client for PVE remotes whose requests may take up to `timeout`. + /// + /// The default implementation ignores the `timeout` parameter and forwards to + /// `make_pve_client()`. + fn make_pve_client_with_timeout( + &self, + remote: &Remote, + timeout: Duration, + ) -> Result<Arc<PveClient>, Error> { + let _ = timeout; + self.make_pve_client(remote) + } + /// Create a new API client for PVE remotes. /// /// In case the remote has a user configured (instead of an API token), it will connect and get @@ -414,6 +427,17 @@ impl ClientFactory for DefaultClientFactory { } } + fn make_pve_client_with_timeout( + &self, + remote: &Remote, + timeout: Duration, + ) -> Result<Arc<PveClient>, Error> { + // Not taken from the connection cache: the cached client is shared with all other + // requests to this remote, which keep the default timeout. + let client = crate::connection::multi_connect(remote)?.with_timeout(timeout); + Ok(Arc::new(PveClientImpl(client))) + } + async fn make_pve_client_and_login(&self, remote: &Remote) -> Result<Arc<PveClient>, Error> { let client = connect_or_login(remote, None).await?; Ok(Arc::new(PveClientImpl(client))) @@ -634,11 +658,12 @@ struct MultiClientEntry { /// problems: if we cannot reach a node of a cluster, this will attempt to retry a request on /// another node. /// -/// The 60-second request timeout applies to each endpoint attempt separately. Until failed -/// endpoints enter their back-off, one request can take up to one timeout per endpoint, plus one -/// more when the first endpoint is retried after a connection error. For streamed responses, the -/// timeout limits each wait for body data rather than the whole transfer. Body errors are returned -/// to the consumer without failover or retries. +/// The request timeout applies to each endpoint attempt separately. Until failed endpoints enter +/// their back-off, one request can take up to one timeout per endpoint, plus one more when the +/// first endpoint is retried after a connection error. For streamed responses, the timeout limits +/// each wait for body data rather than the whole transfer. Body errors are returned to the +/// consumer without failover or retries. The timeout defaults to 60 seconds and can be changed +/// with `MultiClient::with_timeout`. /// /// # Possible improvements /// @@ -646,6 +671,7 @@ struct MultiClientEntry { pub struct MultiClient { state: StdMutex<MultiClientState>, remote: String, + timeout: Duration, } impl MultiClient { @@ -653,9 +679,15 @@ impl MultiClient { Self { state: StdMutex::new(MultiClientState::new(remote.clone(), entries)), remote, + timeout: REQUEST_TIMEOUT, } } + fn with_timeout(mut self, timeout: Duration) -> Self { + self.timeout = timeout; + self + } + fn for_each_client<F>(&self, func: F) where F: Fn(&Arc<Client>), @@ -936,7 +968,7 @@ macro_rules! try_request { } let request = client.$how($method.clone(), $path_and_query, params.as_ref()); - match tokio::time::timeout(REQUEST_TIMEOUT, request).await { + match tokio::time::timeout($self.timeout, request).await { // Connection error: the request never reached the server, so failing over to // another node is safe for any method. Remember the first endpoint for retry. Ok(Err(err @ proxmox_client::Error::Connect(_))) => { @@ -1014,7 +1046,7 @@ macro_rules! try_request { let path = $path_and_query; log::warn!("all endpoints failed, retrying {hostname:?} once - {path}"); let request = client.$how($method.clone(), $path_and_query, params.as_ref()); - if let Ok(result) = tokio::time::timeout(REQUEST_TIMEOUT, request).await { + if let Ok(result) = tokio::time::timeout($self.timeout, request).await { if result.is_ok() { if let Ok(mut cache) = crate::remote_cache::RemoteMappingCache::write() { cache.mark_host_reachable( @@ -1082,11 +1114,12 @@ impl HttpApiClient for MultiClient { where T: Serialize + 'a, { + let timeout = self.timeout; let request = try_request! { self, method, path_and_query, params, streaming_request }; Box::pin(async move { request .await - .map(|response| with_body_idle_timeout(response, REQUEST_TIMEOUT)) + .map(|response| with_body_idle_timeout(response, timeout)) }) } } -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests 2026-11-27 14:03 [PATCH proxmox-datacenter-manager v2 0/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 1/2] connection: allow creating PVE clients with a custom request timeout Jakob Klocker @ 2026-11-27 14:03 ` Jakob Klocker 2026-11-30 20:09 ` Thomas Lamprecht 1 sibling, 1 reply; 5+ messages in thread From: Jakob Klocker @ 2026-11-27 14:03 UTC (permalink / raw) To: pdm-devel 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 <j.klocker@proxmox.com> --- 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<RrdStoreResult, Error> = 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), -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker @ 2026-11-30 20:09 ` Thomas Lamprecht 2026-12-01 8:17 ` Jakob Klocker 0 siblings, 1 reply; 5+ messages in thread From: Thomas Lamprecht @ 2026-11-30 20:09 UTC (permalink / raw) To: Jakob Klocker, pdm-devel 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 <j.klocker@proxmox.com> > --- > 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<RrdStoreResult, Error> = 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 <t.lamprecht@proxmox.com> 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 <t.lamprecht@proxmox.com> --- .../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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests 2026-11-30 20:09 ` Thomas Lamprecht @ 2026-12-01 8:17 ` Jakob Klocker 0 siblings, 0 replies; 5+ messages in thread From: Jakob Klocker @ 2026-12-01 8:17 UTC (permalink / raw) To: Thomas Lamprecht, pdm-devel On Mon Nov 30, 2026 at 9:09 PM CET, Thomas Lamprecht wrote: > 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 <j.klocker@proxmox.com> >> --- >> 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<RrdStoreResult, Error> = 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/ > Thanks for the feedback! I'll drop this for now and come back to it if users still run into the timeout once the export endpoint fetches asynchronously. If it turns out to be necessary, I'll make sure to include your patch. I'll also make sure to test your async export series and report back there. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 8:17 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-27 14:03 [PATCH proxmox-datacenter-manager v2 0/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 1/2] connection: allow creating PVE clients with a custom request timeout Jakob Klocker 2026-11-27 14:03 ` [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests Jakob Klocker 2026-11-30 20:09 ` Thomas Lamprecht 2026-12-01 8:17 ` Jakob Klocker
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox