Skip to content

Commit d2b9a9d

Browse files
committed
CP-51489: Classify threads based on http requests.
For now, the thread executing `Xapi.server_init` and it's children are classified as External. The only excception are http requests that come through the smapi internally. If those contain the originator header with the value set as "sm", the thread executing the request will be classified as internal. This represents the first phase of classifing xapi threads as internal vs external. Signed-off-by: Gabriel Buica <[email protected]>
1 parent ddf2bc6 commit d2b9a9d

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

ocaml/libs/http-lib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
http_lib
4545
ipaddr
4646
polly
47+
tgroup
4748
threads.posix
4849
tracing
4950
uri

ocaml/libs/http-lib/http_svr.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ let handle_connection ~header_read_timeout ~header_total_timeout
560560
read_request ?proxy_seen ~read_timeout ~total_timeout
561561
~max_length:max_header_length ss
562562
in
563-
563+
Http.Request.with_originator_of req Tgroup.of_req_originator ;
564564
(* 2. now we attempt to process the request *)
565565
let finished =
566566
Option.fold ~none:true

ocaml/libs/tgroup/tgroup.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ module Cgroup = struct
126126
with Invalid_argument _ -> raise Cgroups_not_initialized
127127
)
128128

129-
let init dir =
130-
let () = Atomic.set cgroup_dir (Some dir) in
131-
Group.all
132-
|> List.map dir_of
133-
|> List.iter (fun dir -> Xapi_stdext_unix.Unixext.mkdir_rec dir 0o755)
134-
135129
let write_cur_tid_to_cgroup_file filename =
136130
try
137131
let perms = 0o640 in
@@ -163,6 +157,13 @@ module Cgroup = struct
163157

164158
let set_cgroup creator =
165159
set_cur_cgroup ~originator:creator.Group.Creator.originator
160+
161+
let init dir =
162+
let () = Atomic.set cgroup_dir (Some dir) in
163+
Group.all
164+
|> List.map dir_of
165+
|> List.iter (fun dir -> Xapi_stdext_unix.Unixext.mkdir_rec dir 0o755) ;
166+
set_cur_cgroup ~originator:Group.Originator.EXTERNAL
166167
end
167168

168169
let of_originator originator =

0 commit comments

Comments
 (0)