group download failures by error

This commit is contained in:
Hannes Mehnert 2024-11-04 18:43:50 +01:00
parent 9c50538877
commit 8ba4cfae00

View file

@ -192,6 +192,36 @@ module Make
remove_active url; remove_active url;
failed_downloads := SM.add url (ts, reason) !failed_downloads failed_downloads := SM.add url (ts, reason) !failed_downloads
let pp_failed ppf = function
| `Write_error e ->
Fmt.pf ppf "write error: %a" KV.pp_write_error e
| `Swap e ->
Fmt.pf ppf "swap error: %a" Swap.pp_error e
| `Bad_checksum (hash, computed, expected) ->
Fmt.pf ppf "%s checksum: computed %s expected %s"
(hash_to_string hash)
(Ohex.encode computed)
(Ohex.encode expected)
| `Bad_response (status, reason) ->
Fmt.pf ppf "bad response: %a %s" H2.Status.pp_hum status reason
| `Mimic me ->
Fmt.pf ppf "mimic: %a" Mimic.pp_error me
let compare_failed a b = match a, b with
| `Write_error _, `Write_error _ -> 0
| `Write_error _, _ -> 1
| _, `Write_error _ -> -1
| `Swap _, `Swap _ -> 0
| `Swap _, _ -> 1
| _, `Swap _ -> -1
| `Bad_checksum _, `Bad_checksum _ -> 0
| `Bad_checksum _, _ -> 1
| _, `Bad_checksum _ -> -1
| `Bad_response _, `Bad_response _ -> 0
| `Bad_response _, _ -> 1
| _, `Bad_response _ -> -1
| `Mimic _, `Mimic _ -> 0
module Disk = struct module Disk = struct
type t = { type t = {
mutable md5s : string SM.t ; mutable md5s : string SM.t ;
@ -346,14 +376,12 @@ module Make
| `Swap e -> Swap.pp_error ppf e | `Swap e -> Swap.pp_error ppf e
in in
Logs.err (fun m -> m "Write failure for %s: %a" url pp_error e); Logs.err (fun m -> m "Write failure for %s: %a" url pp_error e);
add_failed url (Ptime.v (Pclock.now_d_ps ())) match e with
(Fmt.str "Write failure for %s: %a" url pp_error e) | `Write_error e -> add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Write_error e)
| `Swap e -> add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Swap e)
else begin else begin
add_failed url (Ptime.v (Pclock.now_d_ps ())) add_failed url (Ptime.v (Pclock.now_d_ps ()))
(Fmt.str "Bad checksum %s:%s: computed %s expected %s" url (`Bad_checksum (hash, Archive_checksum.get digests hash, csum));
(hash_to_string hash)
(Ohex.encode (Archive_checksum.get digests hash))
(Ohex.encode csum));
Logs.err (fun m -> m "Bad checksum %s:%s: computed %s expected %s" url Logs.err (fun m -> m "Bad checksum %s:%s: computed %s expected %s" url
(hash_to_string hash) (hash_to_string hash)
(Ohex.encode (Archive_checksum.get digests hash)) (Ohex.encode (Archive_checksum.get digests hash))
@ -674,9 +702,13 @@ stamp: %S
let header = "<h2>Failed downloads</h2><ul>" in let header = "<h2>Failed downloads</h2><ul>" in
let content = let content =
SM.bindings !failed_downloads |> SM.bindings !failed_downloads |>
List.sort (fun (_, (a, _)) (_, (b, _)) -> sort_by_ts a b) |> List.sort (fun (_, (a, reasona)) (_, (b, reasonb)) ->
match compare_failed reasona reasonb with
| 0 -> sort_by_ts a b
| n -> n) |>
List.map (fun (url, (ts, reason)) -> List.map (fun (url, (ts, reason)) ->
"<li>" ^ Ptime.to_rfc3339 ?tz_offset_s:None ts ^ ": " ^ url ^ " " ^ reason ^ "</li>") Fmt.str "<li>%s: %s error %a"
(Ptime.to_rfc3339 ?tz_offset_s:None ts) url pp_failed reason)
in in
header ^ String.concat "" content ^ "</ul>" header ^ String.concat "" content ^ "</ul>"
and parse_errors = and parse_errors =
@ -867,28 +899,25 @@ stamp: %S
Logs.warn (fun m -> m "%s: %a (reason %s)" Logs.warn (fun m -> m "%s: %a (reason %s)"
url H2.Status.pp_hum resp.status resp.reason); url H2.Status.pp_hum resp.status resp.reason);
add_failed url (Ptime.v (Pclock.now_d_ps ())) add_failed url (Ptime.v (Pclock.now_d_ps ()))
(Fmt.str "%a %s" H2.Status.pp_hum resp.status resp.reason); (`Bad_response (resp.status, resp.reason));
Lwt.return_unit Lwt.return_unit
| Error `Write_error e -> | Error `Write_error e ->
Logs.err (fun m -> m "%s: write error %a" Logs.err (fun m -> m "%s: write error %a"
url url
KV.pp_write_error e); KV.pp_write_error e);
add_failed url (Ptime.v (Pclock.now_d_ps ())) add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Write_error e);
(Fmt.str "write error: %a" KV.pp_write_error e);
Lwt.return_unit Lwt.return_unit
| Error `Swap e -> | Error `Swap e ->
Logs.err (fun m -> m "%s: swap error %a" Logs.err (fun m -> m "%s: swap error %a"
url url
Swap.pp_error e); Swap.pp_error e);
add_failed url (Ptime.v (Pclock.now_d_ps ())) add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Swap e);
(Fmt.str "swap error: %a" Swap.pp_error e);
Lwt.return_unit Lwt.return_unit
| Ok (digests, body) -> | Ok (digests, body) ->
Disk.finalize_write disk quux ~url body csums digests Disk.finalize_write disk quux ~url body csums digests
end end
| Error me -> | Error me ->
add_failed url (Ptime.v (Pclock.now_d_ps ())) add_failed url (Ptime.v (Pclock.now_d_ps ())) (`Mimic me);
(Fmt.str "mimic error: %a" Mimic.pp_error me);
Lwt.return_unit) Lwt.return_unit)
(SM.bindings urls) >>= fun () -> (SM.bindings urls) >>= fun () ->
Disk.update_caches disk >|= fun () -> Disk.update_caches disk >|= fun () ->