public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Jakob Klocker <j.klocker@proxmox.com>, pdm-devel@lists.proxmox.com
Subject: Re: [PATCH proxmox-datacenter-manager v2 2/2] fix #7731: metric collection: allow 5 minutes for PVE metric requests
Date: Mon, 30 Nov 2026 21:09:45 +0100	[thread overview]
Message-ID: <d94454dc-c6ad-4a9f-b81b-b7700a0df3e1@proxmox.com> (raw)
In-Reply-To: <20261127140358.205440-3-j.klocker@proxmox.com>

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




  reply	other threads:[~2026-11-30 20:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-01  8:17     ` Jakob Klocker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d94454dc-c6ad-4a9f-b81b-b7700a0df3e1@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=j.klocker@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal