Skip to content

Commit

Permalink
Xapi thread classification - part 2 (xapi-project#6154)
Browse files Browse the repository at this point in the history
Adds more granurality in the xapi thread classification. Now, an
individual thread can be mapped to the following:

- {xapi_cgroup}/internal/SM;
- {xapi_cgroup}/internal/cli;
- {xapi_cgroup}/external/intrapool;
- {xapi_cgroup}/external/unauthenticated;
- {xapi_cgroup}/external/authenticated/{identity};

where {identity} is a {auth_user_sid}/{user_agent}.
Both {auth_user_sid} and {user_agent} strings are sanitized when
making the identity through `Identity.make`, by allowing only
alphanumeric characters and a maximum length of 16 characters each.

This should allow for proper thread classification in xapi. 

Note: Threads calling back into xapi from xenopsd are yet to be
classified.

e.g. Cgroup hierarchy based on the new classification 

![image](https://github.com/user-attachments/assets/29774a5c-0581-405f-965c-4c7c823c6492)

BVT: 208947 & BST: 208972
  • Loading branch information
mg12 authored Jan 8, 2025
2 parents 8a427b9 + 63391ba commit 6589d9a
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 70 deletions.
9 changes: 8 additions & 1 deletion ocaml/libs/tgroup/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
(library
(name tgroup)
(modules tgroup)
(public_name tgroup)
(libraries xapi-log xapi-stdext-unix))
(libraries xapi-log xapi-stdext-unix xapi-stdext-std))

(test
(name test_tgroup)
(modules test_tgroup)
(package tgroup)
(libraries tgroup alcotest xapi-log))
83 changes: 83 additions & 0 deletions ocaml/libs/tgroup/test_tgroup.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module D = Debug.Make (struct let name = __MODULE__ end)

let test_identity () =
let specs =
[
((Some "XenCenter2024", "u1000"), "u1000/XenCenter2024")
; ((None, "u1001"), "u1001")
; ((None, "Special!@#"), "Special")
; ((Some "With-Hyphen", "123"), "123/WithHyphen")
; ((Some "", ""), "root")
; ((Some " Xen Center 2024 ", ", u 1000 "), "u1000/XenCenter2024")
; ((Some "Xen Center ,/@.~# 2024", "root"), "root/XenCenter2024")
; ((Some "XenCenter 2024.3.18", ""), "root/XenCenter2024318")
; ((Some "", "S-R-X-Y1-Y2-Yn-1-Yn"), "SRXY1Y2Yn1Yn")
; ( (Some "XenCenter2024", "S-R-X-Y1-Y2-Yn-1-Yn")
, "SRXY1Y2Yn1Yn/XenCenter2024"
)
]
in

let test_make ((user_agent, subject_sid), expected_identity) =
let actual_identity =
Tgroup.Group.Identity.(make ?user_agent subject_sid |> to_string)
in
Alcotest.(check string)
"Check expected identity" expected_identity actual_identity
in
List.iter test_make specs

let test_of_creator () =
let dummy_identity =
Tgroup.Group.Identity.make ~user_agent:"XenCenter2024" "root"
in
let specs =
[
((None, None, None, None), "external/unauthenticated")
; ((Some true, None, None, None), "external/intrapool")
; ( ( Some true
, Some Tgroup.Group.Endpoint.External
, Some dummy_identity
, Some "sm"
)
, "external/intrapool"
)
; ( ( Some true
, Some Tgroup.Group.Endpoint.Internal
, Some dummy_identity
, Some "sm"
)
, "external/intrapool"
)
; ( ( None
, Some Tgroup.Group.Endpoint.Internal
, Some dummy_identity
, Some "cli"
)
, "internal/cli"
)
; ( (None, None, Some dummy_identity, Some "sm")
, "external/authenticated/root/XenCenter2024"
)
]
in
let test_make ((intrapool, endpoint, identity, originator), expected_group) =
let originator = Option.map Tgroup.Group.Originator.of_string originator in
let actual_group =
Tgroup.Group.(
Creator.make ?intrapool ?endpoint ?identity ?originator ()
|> of_creator
|> to_string
)
in
Alcotest.(check string) "Check expected group" expected_group actual_group
in
List.iter test_make specs

let tests =
[
("identity make", `Quick, test_identity)
; ("group of creator", `Quick, test_of_creator)
]

let () = Alcotest.run "Tgroup library" [("Thread classification", tests)]
Empty file.
Loading

0 comments on commit 6589d9a

Please sign in to comment.