diff --git a/ocaml/libs/xapi-rrd/lib_test/crowbar_tests.ml b/ocaml/libs/xapi-rrd/lib_test/crowbar_tests.ml index 6ff917eccfc..243b4d6a4e4 100644 --- a/ocaml/libs/xapi-rrd/lib_test/crowbar_tests.ml +++ b/ocaml/libs/xapi-rrd/lib_test/crowbar_tests.ml @@ -74,14 +74,13 @@ let ds = let rrd = Cb.(map [list1 int64; rra; ds]) (fun values rra ds -> let open Rrd in - let init_time = 0. in - - let rrd = rrd_create [|ds|] [|rra|] 5L init_time in + let rrd = rrd_create [|ds|] [|rra|] 5L 0. in List.iteri (fun i v -> - let t = 5. *. (init_time +. float_of_int i) in - ds_update rrd t [|VT_Int64 v|] [|Identity|] (i = 0) + let timestamp = 5. *. float_of_int i in + let arr = [|(0, {value= VT_Int64 v; transform= Identity})|] in + ds_update rrd timestamp arr (i = 0) ) values ; rrd diff --git a/ocaml/libs/xapi-rrd/lib_test/test_data/flip_flop.xml b/ocaml/libs/xapi-rrd/lib_test/test_data/flip_flop.xml index 8e368ed41b7..77e42106881 100644 --- a/ocaml/libs/xapi-rrd/lib_test/test_data/flip_flop.xml +++ b/ocaml/libs/xapi-rrd/lib_test/test_data/flip_flop.xml @@ -1,2 +1,2 @@ -00035100flip_flopDERIVEInfinity0Infinity00.00AVERAGE10.50000.00.00.00NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.0000-3.00003.0000-5.00005.0000-7.00007.0000-9.00009.0000-11.000011.0000-13.000013.0000-15.000015.0000-17.000017.0000-19.000019.0000MIN10.50000.00.019.00000NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.0000-3.0000-3.0000-5.0000-5.0000-7.0000-7.0000-9.0000-9.0000-11.0000-11.0000-13.0000-13.0000-15.0000-15.0000-17.0000-17.0000-19.0000-19.0000MAX10.50000.00.019.00000NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.00001.00003.00003.00005.00005.00007.00007.00009.00009.000011.000011.000013.000013.000015.000015.000017.000017.000019.0000 +00035100flip_flopDERIVEInfinity0Infinity00.000.0AVERAGE10.50000.00.00.00NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.0000-3.00003.0000-5.00005.0000-7.00007.0000-9.00009.0000-11.000011.0000-13.000013.0000-15.000015.0000-17.000017.0000-19.000019.0000MIN10.50000.00.019.00000NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.0000-3.0000-3.0000-5.0000-5.0000-7.0000-7.0000-9.0000-9.0000-11.0000-11.0000-13.0000-13.0000-15.0000-15.0000-17.0000-17.0000-19.0000-19.0000MAX10.50000.00.019.00000NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN0.01.00001.00003.00003.00005.00005.00007.00007.00009.00009.000011.000011.000013.000013.000015.000015.000017.000017.000019.0000 diff --git a/ocaml/libs/xapi-rrd/lib_test/unit_tests.ml b/ocaml/libs/xapi-rrd/lib_test/unit_tests.ml index 089d8047468..f9cb5765b9f 100644 --- a/ocaml/libs/xapi-rrd/lib_test/unit_tests.ml +++ b/ocaml/libs/xapi-rrd/lib_test/unit_tests.ml @@ -15,10 +15,7 @@ let assert_ds_equal d1 d2 = compare_float __LOC__ d1.ds_value d2.ds_value ; compare_float __LOC__ d1.ds_unknown_sec d2.ds_unknown_sec -let assert_dss_equal d1s d2s = - let d1s = Array.to_list d1s in - let d2s = Array.to_list d2s in - List.iter2 assert_ds_equal d1s d2s +let assert_dss_equal d1s d2s = Array.iter2 assert_ds_equal d1s d2s let assert_cdp_prep_equal c1 c2 = compare_float __LOC__ c1.cdp_value c2.cdp_value ; @@ -37,15 +34,10 @@ let assert_rra_equal a1 a2 = Alcotest.(check int) __LOC__ a1.rra_row_cnt a2.rra_row_cnt ; Alcotest.(check int) __LOC__ a1.rra_pdp_cnt a2.rra_pdp_cnt ; compare_float __LOC__ a1.rra_xff a2.rra_xff ; - List.iter2 assert_cdp_prep_equal - (Array.to_list a1.rra_cdps) - (Array.to_list a2.rra_cdps) ; - List.iter2 assert_fring_equal - (Array.to_list a1.rra_data) - (Array.to_list a2.rra_data) + Array.iter2 assert_cdp_prep_equal a1.rra_cdps a2.rra_cdps ; + Array.iter2 assert_fring_equal a1.rra_data a2.rra_data -let assert_rras_equal a1s a2s = - List.iter2 assert_rra_equal (Array.to_list a1s) (Array.to_list a2s) +let assert_rras_equal a1s a2s = Array.iter2 assert_rra_equal a1s a2s let assert_rrds_equal r1 r2 = compare_float __LOC__ r1.last_updated r2.last_updated ; @@ -74,9 +66,7 @@ let test_ranges rrd () = let in_range_fring ds fring = in_range ds.ds_min ds.ds_max (fring_to_list fring) in - let in_range_rra dss rra = - List.iter2 in_range_fring dss (Array.to_list rra.rra_data) - in + let in_range_rra dss rra = Array.iter2 in_range_fring dss rra.rra_data in let range_is_not_empty ds = Alcotest.(check bool) (Printf.sprintf "min (%f) < max (%f); " ds.ds_min ds.ds_max) @@ -84,9 +74,7 @@ let test_ranges rrd () = in Array.iter range_is_not_empty rrd.rrd_dss ; - List.iter - (in_range_rra @@ Array.to_list rrd.rrd_dss) - (Array.to_list rrd.rrd_rras) + Array.iter (in_range_rra @@ rrd.rrd_dss) rrd.rrd_rras let test_marshall rrd ~json () = ignore @@ -94,13 +82,13 @@ let test_marshall rrd ~json () = Rrd.json_to_string rrd else let out = Buffer.create 2048 in - Rrd.xml_to_output rrd (Xmlm.make_output (`Buffer out)) ; + Rrd.xml_to_output true rrd (Xmlm.make_output (`Buffer out)) ; Buffer.contents out ) let test_marshall_unmarshall rrd () = let out = Buffer.create 2048 in - Rrd.xml_to_output rrd (Xmlm.make_output (`Buffer out)) ; + Rrd.xml_to_output true rrd (Xmlm.make_output (`Buffer out)) ; let contents = Buffer.contents out in let xml = Xmlm.make_input (`String (0, contents)) in let rrd' = Rrd.from_xml xml in @@ -124,21 +112,28 @@ let gauge_rrd = let rra2 = rra_create CF_Average 100 10 0.5 in let rra3 = rra_create CF_Average 100 100 0.5 in let rra4 = rra_create CF_Average 100 1000 0.5 in + let ts = 1000000000.0 in let ds = ds_create "foo" Gauge ~mrhb:10.0 (VT_Float 0.0) in let ds2 = ds_create "bar" Gauge ~mrhb:10.0 (VT_Float 0.0) in let ds3 = ds_create "baz" Gauge ~mrhb:10.0 (VT_Float 0.0) in let ds4 = ds_create "boo" Gauge ~mrhb:10.0 (VT_Float 0.0) in - let rrd = - rrd_create [|ds; ds2; ds3; ds4|] [|rra; rra2; rra3; rra4|] 1L 1000000000.0 - in + let rrd = rrd_create [|ds; ds2; ds3; ds4|] [|rra; rra2; rra3; rra4|] 1L ts in let id = Identity in for i = 1 to 100000 do - let t = 1000000000.0 +. (0.7 *. float_of_int i) in - let v1 = VT_Float (0.5 +. (0.5 *. sin (t /. 10.0))) in - let v2 = VT_Float (1.5 +. (0.5 *. cos (t /. 80.0))) in - let v3 = VT_Float (3.5 +. (0.5 *. sin (t /. 700.0))) in - let v4 = VT_Float (6.5 +. (0.5 *. cos (t /. 5000.0))) in - ds_update rrd t [|v1; v2; v3; v4|] [|id; id; id; id|] false + let t = 1000000.0 +. (0.7 *. float_of_int i) in + let v1 = + (0, {value= VT_Float (0.5 +. (0.5 *. sin (t /. 10.0))); transform= id}) + in + let v2 = + (1, {value= VT_Float (1.5 +. (0.5 *. cos (t /. 80.0))); transform= id}) + in + let v3 = + (2, {value= VT_Float (3.5 +. (0.5 *. sin (t /. 700.0))); transform= id}) + in + let v4 = + (3, {value= VT_Float (6.5 +. (0.5 *. cos (t /. 5000.0))); transform= id}) + in + ds_update rrd t [|v1; v2; v3; v4|] false done ; rrd @@ -150,66 +145,60 @@ let of_file filename = (* Used to generate flip_flop.xml for test_ca_325844, then gets edited manually to set min to 0 *) let _deserialize_verify_rrd = - let init_time = 0. in - let rra1 = rra_create CF_Average 100 1 0.5 in let rra2 = rra_create CF_Min 100 1 0.5 in let rra3 = rra_create CF_Max 100 1 0.5 in let ds = ds_create "flip_flop" Derive (VT_Int64 0L) in - let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L init_time in + let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L 0. in let id = Identity in for i = 1 to 100 do - let t = init_time +. float_of_int i in + let t = float_of_int i in let t64 = Int64.of_float t in - let v = VT_Int64 Int64.(mul t64 (mul (-1L) (rem t64 2L))) in - ds_update rrd t [|v|] [|id|] false + let value = VT_Int64 Int64.(mul t64 (mul (-1L) (rem t64 2L))) in + ds_update rrd t [|(0, {value; transform= id})|] false done ; rrd let ca_322008_rrd = - let init_time = 0. in - let rra1 = rra_create CF_Average 100 1 0.5 in let rra2 = rra_create CF_Min 100 1 0.5 in let rra3 = rra_create CF_Max 100 1 0.5 in let ds = ds_create "even or zero" Derive ~min:0. (VT_Int64 0L) in - let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L init_time in + let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L 0. in let id = Identity in for i = 1 to 100000 do - let t = init_time +. float_of_int i in + let t = float_of_int i in let t64 = Int64.of_float t in - let v = VT_Int64 (Int64.mul t64 (Int64.rem t64 2L)) in - ds_update rrd t [|v|] [|id|] false + let value = VT_Int64 (Int64.mul t64 (Int64.rem t64 2L)) in + ds_update rrd t [|(0, {value; transform= id})|] false done ; rrd let ca_329043_rrd_1 = - let init_time = 0. in - let rra1 = rra_create CF_Average 3 1 0.5 in let rra2 = rra_create CF_Min 3 1 0.5 in let rra3 = rra_create CF_Max 3 1 0.5 in let ds = ds_create "derive_with_min" ~min:0. ~max:1. Derive VT_Unknown in - let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L init_time in + let rrd = rrd_create [|ds|] [|rra1; rra2; rra3|] 5L 0. in let id = Identity in let time_value_of_i i = - let t = 5. *. (init_time +. float_of_int i) in + let t = 5. *. float_of_int i in if i = 1 then (t, VT_Int64 0L) else (t, VT_Int64 Int64.(of_float t)) in for i = 0 to 4 do - let t, v = time_value_of_i i in - ds_update rrd t [|v|] [|id|] (i = 0) + let t, value = time_value_of_i i in + ds_update rrd t [|(0, {value; transform= id})|] (i = 0) done ; rrd @@ -233,7 +222,7 @@ let create_rrd ?(rows = 2) values min max = List.iteri (fun i v -> let t = 5. *. (init_time +. float_of_int i) in - ds_update rrd t [|VT_Int64 v|] [|id; id; id; id|] (i = 0) + ds_update rrd t [|(0, {value= VT_Int64 v; transform= id})|] (i = 0) ) values ; rrd @@ -258,11 +247,8 @@ let test_ca_322008 () = let in_range_fring ds fring = in_range ds.ds_min rrd.last_updated (fring_to_list fring) in - let in_range_rra dss rra = - List.iter2 in_range_fring dss (Array.to_list rra.rra_data) - in - List.iter (in_range_rra @@ Array.to_list rrd.rrd_dss) - @@ Array.to_list rrd.rrd_rras + let in_range_rra dss rra = Array.iter2 in_range_fring dss rra.rra_data in + Array.iter (in_range_rra @@ rrd.rrd_dss) @@ rrd.rrd_rras let test_ca_325844 () = let rrd = of_file (Filename.concat "test_data" "flip_flop.xml") in diff --git a/ocaml/xcp-rrdd/test/rrdd/test_rrdd_monitor.ml b/ocaml/xcp-rrdd/test/rrdd/test_rrdd_monitor.ml index 27d64870fe4..bb0f726b5eb 100644 --- a/ocaml/xcp-rrdd/test/rrdd/test_rrdd_monitor.ml +++ b/ocaml/xcp-rrdd/test/rrdd/test_rrdd_monitor.ml @@ -36,7 +36,18 @@ let check_datasources kind rdds expected_dss = | None -> () | Some actual_rdds -> - let actual_dss = dss_of_rrds actual_rdds in + let actual_dss = + dss_of_rrds actual_rdds + |> List.map (fun (name, dss) -> + ( name + , Rrd.StringMap.( + map (fun (_timestamp, ds) -> ds) dss + |> bindings + |> List.map snd + ) + ) + ) + in let expected_dss = List.fast_sort Stdlib.compare expected_dss in Alcotest.(check @@ list @@ pair string (list ds)) (Printf.sprintf "%s rrds are not expected" kind) @@ -45,15 +56,16 @@ let check_datasources kind rdds expected_dss = let host_rrds rrd_info = Option.bind rrd_info @@ fun rrd_info -> let h = Hashtbl.create 1 in - if rrd_info.Rrdd_shared.dss <> [] then + if rrd_info.Rrdd_shared.dss <> Rrd.StringMap.empty then Hashtbl.add h "host" rrd_info ; Some h -let update_rrds_test ~dss ~uuid_domids ~paused_vms ~expected_vm_rrds +let update_rrds_test ~timestamp ~dss ~uuid_domids ~paused_vms ~expected_vm_rrds ~expected_sr_rrds ~expected_host_dss = let test () = reset_rrdd_shared_state () ; - Rrdd_monitor.update_rrds 12345.0 (List.to_seq dss) uuid_domids paused_vms ; + Rrdd_monitor.update_rrds uuid_domids paused_vms + (List.to_seq [("update_rrds_test", timestamp, List.to_seq dss)]) ; check_datasources "VM" (Some Rrdd_shared.vm_rrds) expected_vm_rrds ; check_datasources "SR" (Some Rrdd_shared.sr_rrds) expected_sr_rrds ; check_datasources "Host" (host_rrds !Rrdd_shared.host_rrd) expected_host_dss @@ -64,35 +76,35 @@ let update_rrds = let open Rrd in [ ( "Null update" - , update_rrds_test ~dss:[] ~uuid_domids:[] ~paused_vms:[] + , update_rrds_test ~timestamp:0. ~dss:[] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Single host update" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(Host, ds_a)] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[] ~expected_host_dss:[("host", [ds_a])] ) ; ( "Multiple host updates" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(Host, ds_a); (Host, ds_b)] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[] ~expected_host_dss:[("host", [ds_a; ds_b])] ) ; ( "Single non-resident VM update" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(VM "a", ds_a)] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Multiple non-resident VM updates" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(VM "a", ds_a); (VM "b", ds_a)] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Single resident VM update" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(VM "a", ds_a)] ~uuid_domids:[("a", 1)] ~paused_vms:[] @@ -100,7 +112,7 @@ let update_rrds = ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Multiple resident VM updates" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(VM "a", ds_a); (VM "b", ds_a); (VM "b", ds_b)] ~uuid_domids:[("a", 1); ("b", 1)] ~paused_vms:[] @@ -108,7 +120,7 @@ let update_rrds = ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Multiple resident and non-resident VM updates" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(VM "a", ds_a); (VM "b", ds_a); (VM "c", ds_a)] ~uuid_domids:[("a", 1); ("b", 1)] ~paused_vms:[] @@ -116,7 +128,7 @@ let update_rrds = ~expected_sr_rrds:[] ~expected_host_dss:[] ) ; ( "Multiple SR updates" - , update_rrds_test + , update_rrds_test ~timestamp:0. ~dss:[(SR "a", ds_a); (SR "b", ds_a); (SR "b", ds_b)] ~uuid_domids:[] ~paused_vms:[] ~expected_vm_rrds:[] ~expected_sr_rrds:[("a", [ds_a]); ("b", [ds_a; ds_b])]