Skip to content

Commit 6589d9a

Browse files
authored
Xapi thread classification - part 2 (#6154)
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
2 parents 8a427b9 + 63391ba commit 6589d9a

File tree

9 files changed

+356
-70
lines changed

9 files changed

+356
-70
lines changed

ocaml/libs/tgroup/dune

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
(library
22
(name tgroup)
3+
(modules tgroup)
34
(public_name tgroup)
4-
(libraries xapi-log xapi-stdext-unix))
5+
(libraries xapi-log xapi-stdext-unix xapi-stdext-std))
6+
7+
(test
8+
(name test_tgroup)
9+
(modules test_tgroup)
10+
(package tgroup)
11+
(libraries tgroup alcotest xapi-log))

ocaml/libs/tgroup/test_tgroup.ml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
module D = Debug.Make (struct let name = __MODULE__ end)
2+
3+
let test_identity () =
4+
let specs =
5+
[
6+
((Some "XenCenter2024", "u1000"), "u1000/XenCenter2024")
7+
; ((None, "u1001"), "u1001")
8+
; ((None, "Special!@#"), "Special")
9+
; ((Some "With-Hyphen", "123"), "123/WithHyphen")
10+
; ((Some "", ""), "root")
11+
; ((Some " Xen Center 2024 ", ", u 1000 "), "u1000/XenCenter2024")
12+
; ((Some "Xen Center ,/@.~# 2024", "root"), "root/XenCenter2024")
13+
; ((Some "XenCenter 2024.3.18", ""), "root/XenCenter2024318")
14+
; ((Some "", "S-R-X-Y1-Y2-Yn-1-Yn"), "SRXY1Y2Yn1Yn")
15+
; ( (Some "XenCenter2024", "S-R-X-Y1-Y2-Yn-1-Yn")
16+
, "SRXY1Y2Yn1Yn/XenCenter2024"
17+
)
18+
]
19+
in
20+
21+
let test_make ((user_agent, subject_sid), expected_identity) =
22+
let actual_identity =
23+
Tgroup.Group.Identity.(make ?user_agent subject_sid |> to_string)
24+
in
25+
Alcotest.(check string)
26+
"Check expected identity" expected_identity actual_identity
27+
in
28+
List.iter test_make specs
29+
30+
let test_of_creator () =
31+
let dummy_identity =
32+
Tgroup.Group.Identity.make ~user_agent:"XenCenter2024" "root"
33+
in
34+
let specs =
35+
[
36+
((None, None, None, None), "external/unauthenticated")
37+
; ((Some true, None, None, None), "external/intrapool")
38+
; ( ( Some true
39+
, Some Tgroup.Group.Endpoint.External
40+
, Some dummy_identity
41+
, Some "sm"
42+
)
43+
, "external/intrapool"
44+
)
45+
; ( ( Some true
46+
, Some Tgroup.Group.Endpoint.Internal
47+
, Some dummy_identity
48+
, Some "sm"
49+
)
50+
, "external/intrapool"
51+
)
52+
; ( ( None
53+
, Some Tgroup.Group.Endpoint.Internal
54+
, Some dummy_identity
55+
, Some "cli"
56+
)
57+
, "internal/cli"
58+
)
59+
; ( (None, None, Some dummy_identity, Some "sm")
60+
, "external/authenticated/root/XenCenter2024"
61+
)
62+
]
63+
in
64+
let test_make ((intrapool, endpoint, identity, originator), expected_group) =
65+
let originator = Option.map Tgroup.Group.Originator.of_string originator in
66+
let actual_group =
67+
Tgroup.Group.(
68+
Creator.make ?intrapool ?endpoint ?identity ?originator ()
69+
|> of_creator
70+
|> to_string
71+
)
72+
in
73+
Alcotest.(check string) "Check expected group" expected_group actual_group
74+
in
75+
List.iter test_make specs
76+
77+
let tests =
78+
[
79+
("identity make", `Quick, test_identity)
80+
; ("group of creator", `Quick, test_of_creator)
81+
]
82+
83+
let () = Alcotest.run "Tgroup library" [("Thread classification", tests)]

ocaml/libs/tgroup/test_tgroup.mli

Whitespace-only changes.

0 commit comments

Comments
 (0)