Skip to content

Commit 73ca3cc

Browse files
author
Andrii Sultanov
committed
CA-404597: rrd - Pass Gauge and Absolute data source values as-is
Some recent changes related to RRDs likely exposed a long-standing latent issue where the RRD library would process the passed-in values for Gauge and Absolute data sources incorrectly leading to constant values changing from update to update, for example: ``` $ rrd2csv memory_total_kib timestamp, AVERAGE:host:8b533333-91e1-4698-bd17-95b9732ffbb6:memory_total_kib 2025-01-15T08:41:40Z, 33351000 2025-01-15T08:41:45Z, 33350000 2025-01-15T08:41:50Z, 33346000 2025-01-15T08:41:55Z, 33352000 ``` Instead of treating Gauge and Absolute data sources as a variation on the rate-based Derive data source type, expecting time-based calculations to cancel each other out, do not undertake any calculations on non-rate data sources at all. This makes the unit test added in the previous commit pass. Signed-off-by: Andrii Sultanov <[email protected]>
1 parent 0326d27 commit 73ca3cc

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

ocaml/libs/xapi-rrd/lib/rrd.ml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ let rra_update rrd proc_pdp_st elapsed_pdp_st pdps =
341341
Array.iter updatefn rrd.rrd_rras
342342

343343
(* We assume that the data being given is of the form of a rate; that is,
344-
it's dependent on the time interval between updates. To be able to
345-
deal with gauge DSs, we multiply by the interval so that it cancels
346-
the subsequent divide by interval later on *)
344+
it's dependent on the time interval between updates.
345+
Gauge and Absolute data sources are simply kept as is without any
346+
time-based calculations, while Derive data sources will be changed according
347+
to the time passed since the last measurement. (see CA-404597) *)
347348
let process_ds_value ds value interval new_rrd =
348349
if interval > ds.ds_mrhb then
349350
nan
@@ -360,10 +361,8 @@ let process_ds_value ds value interval new_rrd =
360361

361362
let rate =
362363
match (ds.ds_ty, new_rrd) with
363-
| Absolute, _ | Derive, true ->
364+
| Absolute, _ | Derive, true | Gauge, _ ->
364365
value_raw
365-
| Gauge, _ ->
366-
value_raw *. interval
367366
| Derive, false -> (
368367
match (ds.ds_last, value) with
369368
| VT_Int64 x, VT_Int64 y ->
@@ -433,7 +432,14 @@ let ds_update rrd timestamp valuesandtransforms new_rrd =
433432
if Utils.isnan value then
434433
ds.ds_unknown_sec <- pre_int
435434
else
436-
ds.ds_value <- ds.ds_value +. (pre_int *. value /. interval)
435+
(* CA-404597 - Gauge and Absolute values should be passed as-is,
436+
without being involved in time-based calculations at all.
437+
This applies to calculations below as well *)
438+
match ds.ds_ty with
439+
| Gauge | Absolute ->
440+
ds.ds_value <- value
441+
| Derive ->
442+
ds.ds_value <- ds.ds_value +. (pre_int *. value /. interval)
437443
)
438444
v2s ;
439445

@@ -450,7 +456,13 @@ let ds_update rrd timestamp valuesandtransforms new_rrd =
450456
let raw =
451457
let proc_pdp_st = get_float_time last_updated rrd.timestep in
452458
let occu_pdp_st = get_float_time timestamp rrd.timestep in
453-
ds.ds_value /. (occu_pdp_st -. proc_pdp_st -. ds.ds_unknown_sec)
459+
460+
match ds.ds_ty with
461+
| Gauge | Absolute ->
462+
ds.ds_value
463+
| Derive ->
464+
ds.ds_value
465+
/. (occu_pdp_st -. proc_pdp_st -. ds.ds_unknown_sec)
454466
in
455467
(* Apply the transform after the raw value has been calculated *)
456468
let raw = apply_transform_function transform raw in
@@ -473,8 +485,12 @@ let ds_update rrd timestamp valuesandtransforms new_rrd =
473485
ds.ds_value <- 0.0 ;
474486
ds.ds_unknown_sec <- post_int
475487
) else (
476-
ds.ds_value <- post_int *. value /. interval ;
477-
ds.ds_unknown_sec <- 0.0
488+
ds.ds_unknown_sec <- 0.0 ;
489+
match ds.ds_ty with
490+
| Gauge | Absolute ->
491+
ds.ds_value <- value
492+
| Derive ->
493+
ds.ds_value <- post_int *. value /. interval
478494
)
479495
)
480496
v2s

0 commit comments

Comments
 (0)