[pbs-devel] [PATCH proxmox-backup v8 1/7] pbs-api-types: add metrics api types
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Jun 9 14:35:50 CEST 2022
Just minor notes.
On Wed, Jun 08, 2022 at 02:22:32PM +0200, Dominik Csapak wrote:
> InfluxDbUdp and InfluxDbHttp for now
>
> introduces schemas for host:port and https urls
>
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> pbs-api-types/src/lib.rs | 17 +++++
> pbs-api-types/src/metrics.rs | 138 +++++++++++++++++++++++++++++++++++
> 2 files changed, 155 insertions(+)
> create mode 100644 pbs-api-types/src/metrics.rs
>
> diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs
> index d9c8cee1..70c9ec45 100644
> --- a/pbs-api-types/src/lib.rs
> +++ b/pbs-api-types/src/lib.rs
> @@ -120,6 +120,9 @@ pub use traffic_control::*;
> mod zfs;
> pub use zfs::*;
>
> +mod metrics;
> +pub use metrics::*;
> +
> #[rustfmt::skip]
> #[macro_use]
> mod local_macros {
> @@ -131,6 +134,7 @@ mod local_macros {
> macro_rules! DNS_ALIAS_NAME {
> () => (concat!(r"(?:(?:", DNS_ALIAS_LABEL!() , r"\.)*", DNS_ALIAS_LABEL!(), ")"))
> }
> + macro_rules! PORT_REGEX_STR { () => (r"(?:[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])") }
> }
>
> const_regex! {
> @@ -144,6 +148,8 @@ const_regex! {
> pub DNS_NAME_REGEX = concat!(r"^", DNS_NAME!(), r"$");
> pub DNS_ALIAS_REGEX = concat!(r"^", DNS_ALIAS_NAME!(), r"$");
> pub DNS_NAME_OR_IP_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE!(), r")$");
> + pub HOST_PORT_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE_BRACKET!(), "):", PORT_REGEX_STR!() ,"$");
> + pub HTTP_URL_REGEX = concat!(r"^https?://(?:(?:(?:", DNS_NAME!(), "|", IPRE_BRACKET!(), ")(?::", PORT_REGEX_STR!() ,")?)|", IPV6RE!(),")(?:/[^\x00-\x1F\x7F]*)?$");
🥴
This is fine, but...
Okay so, a lot of our types make use of regexes for the sake of being
documented at least badly.
But I do believe that http urls are known well-enough that we could just
as well use a verify-function here instead (which, yes, will not show
up at all in any of our generated documentation, but hey... it's a URL)
But then again that's probably true for a few more types.
Anyway, I don't mind keeping this, I just don't like the sight of it.
No need to actually change this in a v2.
(...)
> diff --git a/pbs-api-types/src/metrics.rs b/pbs-api-types/src/metrics.rs
> new file mode 100644
> index 00000000..239d6c80
> --- /dev/null
> +++ b/pbs-api-types/src/metrics.rs
> @@ -0,0 +1,138 @@
> +use serde::{Deserialize, Serialize};
> +
> +use crate::{
> + HOST_PORT_SCHEMA, HTTP_URL_SCHEMA, PROXMOX_SAFE_ID_FORMAT, SINGLE_LINE_COMMENT_SCHEMA,
> +};
> +use proxmox_schema::{api, Schema, StringSchema, Updater};
> +
> +pub const METRIC_SERVER_ID_SCHEMA: Schema = StringSchema::new("Metrics Server ID.")
> + .format(&PROXMOX_SAFE_ID_FORMAT)
> + .min_length(3)
> + .max_length(32)
> + .schema();
> +
> +pub const INFLUXDB_BUCKET_SCHEMA: Schema = StringSchema::new("InfluxDB Bucket.")
> + .format(&PROXMOX_SAFE_ID_FORMAT)
> + .min_length(3)
> + .max_length(32)
> + .default("proxmox")
> + .schema();
> +
> +pub const INFLUXDB_ORGANIZATION_SCHEMA: Schema = StringSchema::new("InfluxDB Organization.")
> + .format(&PROXMOX_SAFE_ID_FORMAT)
> + .min_length(3)
> + .max_length(32)
> + .default("proxmox")
> + .schema();
> +
> +#[api(
> + properties: {
> + name: {
> + schema: METRIC_SERVER_ID_SCHEMA,
> + },
> + enable: {
> + type: bool,
> + optional: true,
> + default: true,
> + },
> + host: {
> + schema: HOST_PORT_SCHEMA,
> + },
> + mtu: {
> + type: u16,
> + optional: true,
> + default: 1500,
> + },
> + comment: {
> + optional: true,
> + schema: SINGLE_LINE_COMMENT_SCHEMA,
> + },
> + },
> +)]
> +#[derive(Serialize, Deserialize, Updater)]
> +#[serde(rename_all = "kebab-case")]
> +/// InfluxDB Server (UDP)
> +pub struct InfluxDbUdp {
> + #[updater(skip)]
> + pub name: String,
> + #[serde(skip_serializing_if = "Option::is_none")]
> + /// Enables or disables the metrics server
> + pub enable: Option<bool>,
Since the last api-macro update you could also skip the `Option` part
here by using a `skip_serializing_if = "is_true"` and replacing the
Updater's serde attribute via
`#[updater(serde(skip_serializing_if = "Option::is_none"))]`
(see `PruneJobConfig.disable`)
That way we have `enable: 0` to disable it, and "no enable attribute
present" for it to be enabled.
More information about the pbs-devel
mailing list