From e4e20ad93fcebfcde5f6fb32a471a87661ebb4e1 Mon Sep 17 00:00:00 2001 From: Pau Ruiz Safont Date: Mon, 23 Dec 2024 15:50:23 +0000 Subject: [PATCH] rrdd: add more comments about its datastructures Signed-off-by: Pau Ruiz Safont --- ocaml/libs/xapi-rrd/lib/rrd.ml | 6 +++--- ocaml/xcp-rrdd/bin/rrdd/rrdd_monitor.ml | 10 +++++----- ocaml/xcp-rrdd/bin/rrdd/rrdd_server.ml | 2 +- ocaml/xcp-rrdd/bin/rrdd/rrdd_shared.ml | 9 ++++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ocaml/libs/xapi-rrd/lib/rrd.ml b/ocaml/libs/xapi-rrd/lib/rrd.ml index d68de77909..75610964fc 100644 --- a/ocaml/libs/xapi-rrd/lib/rrd.ml +++ b/ocaml/libs/xapi-rrd/lib/rrd.ml @@ -621,9 +621,9 @@ let rrd_add_ds_unsafe rrd timestamp newds = rrd.rrd_rras } -(** Add in a new DS into a pre-existing RRD. Preserves data of all the other archives - and fills the new one full of NaNs. Note that this doesn't fill in the CDP values - correctly at the moment! +(** Add in a new DS into a pre-existing RRD. Preserves data of all the other + archives and fills the new one full of NaNs. Note that this doesn't fill + in the CDP values correctly at the moment! *) let rrd_add_ds rrd timestamp newds = diff --git a/ocaml/xcp-rrdd/bin/rrdd/rrdd_monitor.ml b/ocaml/xcp-rrdd/bin/rrdd/rrdd_monitor.ml index c46a33d6f9..3decd26067 100644 --- a/ocaml/xcp-rrdd/bin/rrdd/rrdd_monitor.ml +++ b/ocaml/xcp-rrdd/bin/rrdd/rrdd_monitor.ml @@ -51,10 +51,10 @@ let merge_new_dss rrdi dss = !Rrdd_shared.enable_all_dss || ds.ds_default in let default_dss = StringMap.filter should_enable_ds dss in - (* NOTE: It's enough to check if all the default datasources have been added - to the RRD_INFO, because if a non-default one has been enabled at runtime, - it's added to the RRD immediately and we don't need to bother *) - let new_dss = + (* NOTE: Only add enabled dss to the live rrd, ignoring non-default ones. + This is because non-default ones are added to the RRD when they are + enabled. *) + let new_enabled_dss = StringMap.filter (fun ds_name _ -> not (StringMap.mem ds_name rrdi.dss)) default_dss @@ -73,7 +73,7 @@ let merge_new_dss rrdi dss = rrd_add_ds_unsafe rrd timestamp (Rrd.ds_create ds.ds_name ds.Ds.ds_type ~mrhb:300.0 Rrd.VT_Unknown) ) - new_dss rrdi.rrd + new_enabled_dss rrdi.rrd ) module OwnerMap = Map.Make (struct diff --git a/ocaml/xcp-rrdd/bin/rrdd/rrdd_server.ml b/ocaml/xcp-rrdd/bin/rrdd/rrdd_server.ml index f8f3c99bf8..d9d41114e0 100644 --- a/ocaml/xcp-rrdd/bin/rrdd/rrdd_server.ml +++ b/ocaml/xcp-rrdd/bin/rrdd/rrdd_server.ml @@ -347,7 +347,7 @@ let send_host_rrd_to_master master_address = let fail_missing name = raise (Rrdd_error (Datasource_missing name)) (** {add_ds rrdi ds_name} creates a new time series (rrd) in {rrdi} with the - name {ds_name}. The operation fails if rrdi does not contain any live + name {ds_name}. The operation fails if rrdi does not contain any datasource with the name {ds_name} *) let add_ds ~rrdi ~ds_name = match Rrd.StringMap.find_opt ds_name rrdi.dss with diff --git a/ocaml/xcp-rrdd/bin/rrdd/rrdd_shared.ml b/ocaml/xcp-rrdd/bin/rrdd/rrdd_shared.ml index 08807e39b7..883f9844cb 100644 --- a/ocaml/xcp-rrdd/bin/rrdd/rrdd_shared.ml +++ b/ocaml/xcp-rrdd/bin/rrdd/rrdd_shared.ml @@ -77,10 +77,13 @@ let mutex = Mutex.create () type rrd_info = { rrd: Rrd.rrd + (** Contains the live metrics, i.e. The datasources that are enabled + and being collected .*) ; mutable dss: (float * Ds.ds) Rrd.StringMap.t - (* Important: this must contain the entire list of datasources associated - with the RRD, even the ones disabled by default, as rrd_add_ds calls - can enable DSs at runtime *) + (** Important: this must contain the entire list of datasources + associated with the RRD, even the ones disabled by default, because + functions like rrd_add_ds or rrd_remove_ds expect disabled + datasources to be present. e.g. to enable DSs at runtime *) ; mutable domid: int }