Skip to content

Commit

Permalink
Merge pull request #58 from psafont/get-out-of-my
Browse files Browse the repository at this point in the history
lib: remove Failure "hd" exceptions
  • Loading branch information
psafont authored Nov 16, 2023
2 parents c1e97c5 + 03a3588 commit 61d362a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v1.11.0 (16-Nov-2023)
* lib: remove Failure "hd" exceptions

## v1.10.0 (02-Aug-2023)
* rrd_updates: use yojson instead of ad-hoc json serialization

Expand Down
6 changes: 5 additions & 1 deletion lib/rrd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ let query_named_ds rrd now ds_name cf =
raise (Invalid_data_source ds_name)
else
let rras = find_best_rras rrd 0 (Some cf) (Int64.of_float now) in
Fring.peek (List.hd rras).rra_data.(n) 0
match rras with
| [] ->
raise No_RRA_Available
| rra :: _ ->
Fring.peek rra.rra_data.(n) 0

(******************************************************************************)
(* Marshalling/Unmarshalling functions *)
Expand Down
20 changes: 11 additions & 9 deletions lib/rrd_updates.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,19 @@ let json_of_t t =
'xport' format. *)

let create_multi prefixandrrds start interval cfopt =
let first_rrd = snd (List.hd prefixandrrds) in
let timestep, last_updated =
match prefixandrrds with
| (_, r) :: _ ->
(r.timestep, r.last_updated)
| [] ->
raise No_RRA_Available
in

let pdp_interval = Int64.to_int (Int64.div interval first_rrd.timestep) in
let pdp_interval = Int64.to_int (Int64.div interval timestep) in

(* Sanity - make sure the RRDs are homogeneous *)
let prefixandrrds =
List.filter
(fun (_prefix, rrd) -> rrd.timestep = first_rrd.timestep)
prefixandrrds
List.filter (fun (_prefix, rrd) -> rrd.timestep = timestep) prefixandrrds
in

(* Treat -ve start values as relative to the latest update. *)
Expand Down Expand Up @@ -282,12 +286,10 @@ let create_multi prefixandrrds start interval cfopt =
let rras = List.flatten rras in

(* The following timestep is that of the archive *)
let rra_timestep =
Int64.mul first_rrd.timestep (Int64.of_int first_rra.rra_pdp_cnt)
in
let rra_timestep = Int64.mul timestep (Int64.of_int first_rra.rra_pdp_cnt) in

(* Get the last and first times of the CDPs to be returned *)
let last_cdp_time, _age = get_times first_rrd.last_updated rra_timestep in
let last_cdp_time, _age = get_times last_updated rra_timestep in
let first_cdp_time_minus_one, _age =
get_times (Int64.to_float start) rra_timestep
in
Expand Down
2 changes: 1 addition & 1 deletion lib_test/unit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ let suite_create_multi =
)
in
let test_no_rrds () =
Alcotest.check_raises "should raise error" (Failure "hd") (fun () ->
Alcotest.check_raises "should raise error" (No_RRA_Available) (fun () ->
let _ = RU.create_multi [] 0L 1L None in
()
)
Expand Down

0 comments on commit 61d362a

Please sign in to comment.