[pdm-devel] [PATCH proxmox-datacenter-manager 19/25] api: add endpoint for updating metric collection settings
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Feb 13 13:09:18 CET 2025
On Tue, Feb 11, 2025 at 01:05:35PM +0100, Lukas Wagner wrote:
> This one lives under /config/metric-collection.
> At the moment, we do not offer full CRUD, but only offer a hard-coded
> collection settings instance at /config/metric-collection/default, which
> can be retrieved via GET and updated via PUT.
>
> Later, we might update this to full CRUD, e.g. to have different
> settings for different 'poll-groups' consisting of a sub-set of remotes.
>
> Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
> ---
> server/src/api/config/metric_collection.rs | 166 +++++++++++++++++++++
> server/src/api/config/mod.rs | 2 +
> 2 files changed, 168 insertions(+)
> create mode 100644 server/src/api/config/metric_collection.rs
>
> diff --git a/server/src/api/config/metric_collection.rs b/server/src/api/config/metric_collection.rs
> new file mode 100644
> index 0000000..1146101
> --- /dev/null
> +++ b/server/src/api/config/metric_collection.rs
> @@ -0,0 +1,166 @@
> +use anyhow::{bail, Error};
> +
> +use proxmox_config_digest::ConfigDigest;
> +use proxmox_router::{list_subdirs_api_method, Router, RpcEnvironment, SubdirMap};
> +use proxmox_schema::api;
> +use proxmox_sortable_macro::sortable;
> +
> +use pdm_api_types::{
> + CollectionSettings, CollectionSettingsUpdater, DeletableCollectionSettingsProperty,
> +};
> +use pdm_config::metric_collection::COLLECTION_SETTINGS_TYPE;
> +
> +#[sortable]
> +const SUBDIRS: SubdirMap = &sorted!([("default", &DEFAULT_ROUTER),]);
> +
> +pub const ROUTER: Router = Router::new()
> + .get(&list_subdirs_api_method!(SUBDIRS))
> + .subdirs(SUBDIRS);
> +
> +const DEFAULT_ROUTER: Router = Router::new()
> + .get(&API_METHOD_GET_SETTINGS)
> + .put(&API_METHOD_UPDATE_SETTINGS);
> +
> +#[api(
> + protected: false,
> +)]
> +/// Get metric collection settings.
> +pub fn get_settings(rpcenv: &mut dyn RpcEnvironment) -> Result<CollectionSettings, Error> {
> + let (config, digest) = pdm_config::metric_collection::config()?;
> + rpcenv["digest"] = digest.to_hex().into();
> +
> + if config.sections.contains_key("default") {
> + let a = config.lookup(COLLECTION_SETTINGS_TYPE, "default")?;
> + Ok(a)
tiny nit: Clippy would warn here, and 'a' is a weird name anyway ;-)
(drop the let binding)
> + } else {
> + Ok(CollectionSettings {
> + id: "default".into(),
> + ..Default::default()
> + })
> + }
> +}
More information about the pdm-devel
mailing list