From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id E32FD1FF165 for ; Thu, 14 Aug 2025 15:30:58 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DF68913690; Thu, 14 Aug 2025 15:32:34 +0200 (CEST) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Thu, 14 Aug 2025 15:31:40 +0200 Message-ID: <20250814133142.386650-22-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250814133142.386650-1-l.wagner@proxmox.com> References: <20250814133142.386650-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755178277912 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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: [pdm-devel] [PATCH proxmox-datacenter-manager v5 21/23] metric collection: factor out handle_tick and handle_control_message fns X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" No functional changes, just moving some code into seperate methods for better readability. Suggested-by: Wolfgang Bumiller Signed-off-by: Lukas Wagner Reviewed-by: Maximiliano Sandoval --- Notes: New in v2. .../src/metric_collection/collection_task.rs | 93 +++++++++++-------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/server/src/metric_collection/collection_task.rs b/server/src/metric_collection/collection_task.rs index b960efff..db65af24 100644 --- a/server/src/metric_collection/collection_task.rs +++ b/server/src/metric_collection/collection_task.rs @@ -88,47 +88,11 @@ impl MetricCollectionTask { loop { tokio::select! { _ = timer.tick() => { - log::debug!("starting metric collection from all remotes - triggered by timer"); - - if let Some(remotes) = Self::load_remote_config() { - self.cleanup_removed_remotes_from_state(&remotes); - - let now = Instant::now(); - let to_fetch = remotes.iter().map(|(name, _)| name.into()).collect::>(); - self.fetch_remotes(&remotes, &to_fetch).await; - let elapsed = now.elapsed(); - - if let Err(err) = self.metric_data_tx.send( - RrdStoreRequest::CollectionStats { - timestamp: proxmox_time::epoch_i64(), - stats: CollectionStats { - // TODO: use as_millis_f64 once stabilized - total_time: elapsed.as_secs_f64() * 1000. - } - }).await { - log::error!("could not send collection stats to rrd task: {err}"); - } - } + self.handle_tick().await; } - val = self.control_message_rx.recv() => { - // Reload settings in case they have changed in the meanwhile - match val { - Some(ControlMsg::CollectSingleRemote(remote)) => { - if let Some(remotes) = Self::load_remote_config() { - log::debug!("starting metric collection for remote '{remote}'- triggered by control message"); - self.fetch_remotes(&remotes, &[remote]).await; - } - } - Some(ControlMsg::CollectAllRemotes) => { - if let Some(remotes) = Self::load_remote_config() { - log::debug!("starting metric collection from all remotes - triggered by control message"); - let to_fetch = remotes.iter().map(|(name, _)| name.into()).collect::>(); - self.fetch_remotes(&remotes, &to_fetch).await; - } - } - _ => {}, - } + Some(message) = self.control_message_rx.recv() => { + self.handle_control_message(message).await; } } @@ -138,6 +102,57 @@ impl MetricCollectionTask { } } + /// Handle a timer tick. + async fn handle_tick(&mut self) { + log::debug!("starting metric collection from all remotes - triggered by timer"); + + if let Some(remotes) = Self::load_remote_config() { + self.cleanup_removed_remotes_from_state(&remotes); + + let now = Instant::now(); + let to_fetch = remotes + .iter() + .map(|(name, _)| name.into()) + .collect::>(); + self.fetch_remotes(&remotes, &to_fetch).await; + let elapsed = now.elapsed(); + + if let Err(err) = self + .metric_data_tx + .send(RrdStoreRequest::CollectionStats { + timestamp: proxmox_time::epoch_i64(), + stats: CollectionStats { + // TODO: use as_millis_f64 once stabilized + total_time: elapsed.as_secs_f64() * 1000., + }, + }) + .await + { + log::error!("could not send collection stats to rrd task: {err}"); + } + } + } + + /// Handle a control message for force-triggered collection. + async fn handle_control_message(&mut self, message: ControlMsg) { + if let Some(remotes) = Self::load_remote_config() { + match message { + ControlMsg::CollectSingleRemote(remote) => { + log::debug!("starting metric collection for remote '{remote}'- triggered by control message"); + self.fetch_remotes(&remotes, &[remote]).await; + } + ControlMsg::CollectAllRemotes => { + log::debug!("starting metric collection from all remotes - triggered by control message"); + let to_fetch = remotes + .iter() + .map(|(name, _)| name.into()) + .collect::>(); + self.fetch_remotes(&remotes, &to_fetch).await; + } + } + } + } + fn cleanup_removed_remotes_from_state(&mut self, remotes: &SectionConfigData) { self.state.retain(|remote| remotes.get(remote).is_some()); } -- 2.47.2 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel