Skip to content

Commit

Permalink
CA-395174: Try to unarchive VM's metrics when they aren't running
Browse files Browse the repository at this point in the history
Backport 71c3960

Non-running VMs' metrics are stored in the coordinator. When the coordinator is
asked about the metrics try to unarchive them instead of failing while trying
to fetch the coordinator's IP address.

This needs to force the HTTP method of the query to be POST

Also returns a Service Unavailable when the host is marked as Broken.

Signed-off-by: Pau Ruiz Safont <[email protected]>
Signed-off-by: Christian Lindig <[email protected]>
  • Loading branch information
psafont authored and Christian Lindig committed Aug 13, 2024
1 parent 7e01f00 commit c014291
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions ocaml/xapi/rrdd_proxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ let get_vm_rrd_forwarder (req : Http.Request.t) (s : Unix.file_descr) _ =
Http_svr.headers s (Http.http_302_redirect url)
in
let unarchive () =
let req = {req with uri= Constants.rrd_unarchive_uri} in
let req = {req with m= Post; uri= Constants.rrd_unarchive_uri} in
ignore
(Xapi_services.hand_over_connection req s
!Rrd_interface.forwarded_path
)
in
let unavailable () =
Http_svr.headers s (Http.http_503_service_unavailable ())
in
(* List of conditions involved. *)
let is_unarchive_request =
List.mem_assoc Constants.rrd_unarchive query
in
let is_master = Pool_role.is_master () in
let is_owner_online owner = Db.is_valid_ref __context owner in
let is_xapi_initialising = List.mem_assoc "dbsync" query in
(* The logic. *)
Expand All @@ -99,15 +101,25 @@ let get_vm_rrd_forwarder (req : Http.Request.t) (s : Unix.file_descr) _ =
let owner = Db.VM.get_resident_on ~__context ~self:vm_ref in
let owner_uuid = Ref.string_of owner in
let is_owner_localhost = owner_uuid = localhost_uuid in
if is_owner_localhost then
if is_master then
let owner_is_available =
is_owner_online owner && not is_xapi_initialising
in
match
(Pool_role.get_role (), is_owner_localhost, owner_is_available)
with
| (Master | Slave _), false, true ->
(* VM is running elsewhere *)
read_at_owner owner
| Master, true, _ | Master, false, false ->
(* VM running on node, or not running at all. *)
unarchive ()
else
| Slave _, true, _ | Slave _, _, false ->
(* Coordinator knows best *)
unarchive_at_master ()
else if is_owner_online owner && not is_xapi_initialising then
read_at_owner owner
else
unarchive_at_master ()
| Broken, _, _ ->
info "%s: host is broken, VM's metrics are not available"
__FUNCTION__ ;
unavailable ()
)

(* Forward the request for host RRD data to the RRDD HTTP handler. If the host
Expand Down

0 comments on commit c014291

Please sign in to comment.