From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pdm-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 159F11FF164 for <inbox@lore.proxmox.com>; Fri, 14 Feb 2025 14:07:15 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ED38C19AE7; Fri, 14 Feb 2025 14:07:12 +0100 (CET) From: Lukas Wagner <l.wagner@proxmox.com> To: pdm-devel@lists.proxmox.com Date: Fri, 14 Feb 2025 14:06:29 +0100 Message-Id: <20250214130653.283012-5-l.wagner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250214130653.283012-1-l.wagner@proxmox.com> References: <20250214130653.283012-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.008 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Subject: [pdm-devel] [PATCH proxmox-datacenter-manager v2 04/28] pdm-config: add functions for reading/writing metric collection settings X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion <pdm-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/> List-Post: <mailto:pdm-devel@lists.proxmox.com> List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox Datacenter Manager development discussion <pdm-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com> This commit adds support for reading and writing a new configuration file at /etc/proxmox-datacenter-manager/metric-collection.cfg. It is a regular SectionConfig file holding CollectionSettings entries for now. For starters, there will be only a single entry with the key 'default', e.g. collection-settings: default max-concurrency 10 ... It might seem a bit odd to use a section config file for something like this, but this gives us the ability to expand it more easily in the future, e.g. different settings for different groups of remotes, other section types for logical structuring, etc. Signed-off-by: Lukas Wagner <l.wagner@proxmox.com> --- lib/pdm-config/src/lib.rs | 1 + lib/pdm-config/src/metric_collection.rs | 69 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 lib/pdm-config/src/metric_collection.rs diff --git a/lib/pdm-config/src/lib.rs b/lib/pdm-config/src/lib.rs index ac398cab..d80ee402 100644 --- a/lib/pdm-config/src/lib.rs +++ b/lib/pdm-config/src/lib.rs @@ -5,6 +5,7 @@ pub use pdm_buildcfg::{BACKUP_GROUP_NAME, BACKUP_USER_NAME}; pub mod certificate_config; pub mod domains; +pub mod metric_collection; pub mod node; pub mod remotes; pub mod setup; diff --git a/lib/pdm-config/src/metric_collection.rs b/lib/pdm-config/src/metric_collection.rs new file mode 100644 index 00000000..1c402700 --- /dev/null +++ b/lib/pdm-config/src/metric_collection.rs @@ -0,0 +1,69 @@ +//! Read/write metric collection configuration + +use std::sync::OnceLock; + +use anyhow::Error; + +use proxmox_config_digest::ConfigDigest; +use proxmox_product_config::{open_api_lockfile, replace_config, ApiLockGuard}; + +use pdm_api_types::{CollectionSettings, PROXMOX_SAFE_ID_FORMAT}; + +use pdm_buildcfg::configdir; +use proxmox_schema::{ApiType, ObjectSchema, Schema, StringSchema}; +use proxmox_section_config::{SectionConfig, SectionConfigData, SectionConfigPlugin}; + +const METRIC_COLLECTION_CFG_FILENAME: &str = configdir!("/metric-collection.cfg"); +const METRIC_COLLECTION_CFG_LOCKFILE: &str = configdir!("/.metric-collection.lock"); + +/// The section-config type name for metric collection settings. +pub const COLLECTION_SETTINGS_TYPE: &str = "collection-settings"; + +/// Section config schema for the public config file. +fn config_parser() -> &'static SectionConfig { + static CONFIG: OnceLock<SectionConfig> = OnceLock::new(); + CONFIG.get_or_init(config_init) +} + +const ENTITY_NAME_SCHEMA: Schema = StringSchema::new("collection-settings key.") + .format(&PROXMOX_SAFE_ID_FORMAT) + .min_length(2) + .max_length(32) + .schema(); + +fn config_init() -> SectionConfig { + let mut config = SectionConfig::new(&ENTITY_NAME_SCHEMA); + + const MATCHER_SCHEMA: &ObjectSchema = CollectionSettings::API_SCHEMA.unwrap_object_schema(); + config.register_plugin(SectionConfigPlugin::new( + COLLECTION_SETTINGS_TYPE.into(), + Some(String::from("id")), + MATCHER_SCHEMA, + )); + + config +} + +/// Lock the metric-collection config +pub fn lock_config() -> Result<ApiLockGuard, Error> { + open_api_lockfile(METRIC_COLLECTION_CFG_LOCKFILE, None, true) +} + +/// Return contents of the metric-collection config +pub fn config() -> Result<(SectionConfigData, ConfigDigest), Error> { + let content = proxmox_sys::fs::file_read_optional_string(METRIC_COLLECTION_CFG_FILENAME)? + .unwrap_or_default(); + + let digest = openssl::sha::sha256(content.as_bytes()); + let data = config_parser().parse(METRIC_COLLECTION_CFG_FILENAME, &content)?; + + Ok((data, digest.into())) +} + +/// Replace the currently persisted metric-collection config +pub fn save_config(config: &SectionConfigData) -> Result<(), Error> { + let content = config_parser().write(METRIC_COLLECTION_CFG_FILENAME, config)?; + replace_config(METRIC_COLLECTION_CFG_FILENAME, content.as_bytes())?; + + Ok(()) +} -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel