Skip to content

Commit

Permalink
Handle inability to contact metrics server on forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeee committed Jan 8, 2024
1 parent 29585f7 commit 03861b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/lib/mina_metrics/prometheus_metrics/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
base.base_internalhash_types
uri
async_unix
base.caml
;; local libraries
logger
o1trace
)
(preprocessor_deps ../../../config.mlh)
(instrumentation (backend bisect_ppx))
(preprocess (pps ppx_mina ppx_let ppx_version ppx_pipebang ppx_custom_printf ppx_optcomp))
(preprocess (pps ppx_mina ppx_let ppx_version ppx_pipebang ppx_custom_printf ppx_optcomp ppx_here))
(implements mina_metrics))
41 changes: 27 additions & 14 deletions src/lib/mina_metrics/prometheus_metrics/mina_metrics.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1665,20 +1665,33 @@ let generic_server ?forward_uri ~port ~logger ~registry () =
| `GET, "/metrics" ->
let%bind other_data =
match forward_uri with
| Some uri ->
let%bind resp, body = Client.get uri in
let status = Response.status resp in
if Code.is_success (Code.code_of_status status) then
let%map body = Body.to_string body in
Some body
else (
[%log error] "Could not forward request to $url, got: $status"
~metadata:
[ ("url", `String (Uri.to_string uri))
; ("status_code", `Int (Code.code_of_status status))
; ("status", `String (Code.string_of_status status))
] ;
return None )
| Some uri -> (
Monitor.try_with ~here:[%here] (fun () ->
let%bind resp, body = Client.get uri in
let status = Response.status resp in
if Code.is_success (Code.code_of_status status) then
let%map body = Body.to_string body in
Some body
else (
[%log error]
"Could not forward request to $url, got: $status"
~metadata:
[ ("url", `String (Uri.to_string uri))
; ("status_code", `Int (Code.code_of_status status))
; ("status", `String (Code.string_of_status status))
] ;
return None ) )
>>| function
| Ok a ->
a
| Error e ->
[%log error]
"Could not forward request to $url, got error: $error"
~metadata:
[ ("url", `String (Uri.to_string uri))
; ("error", `String (Exn.to_string_mach e))
] ;
None )
| None ->
return None
in
Expand Down

0 comments on commit 03861b5

Please sign in to comment.