Skip to content

CP-53314: Read and watch <domain>/data/service in xenstore to DB #6317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

changlei-li
Copy link
Contributor

@changlei-li changlei-li commented Feb 25, 2025

The field VM_guest_metrics.services added previously (#6309) is used to store VM service information reported by guest tools.
Xapi does not use this data but just holds it for outside consumers.
This PR reads the xenstore path data/service and converts to [("service_name/key", "value")] pair list and then store to VM_guest_metrics.services.
The path to read is like:
/local/domain/<id>/data/service/<service_name>/<key> = <value>

1. xenopsd backend read and watch /local/domain/%d/data/service
2. xapi_guest_agent convert the data to (string, string) list
to store in VM_guest_metrics.services

Signed-off-by: Changlei Li <changlei.li@cloud.com>
@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from 3d45f0a to 634db51 Compare February 25, 2025 08:14
Copy link
Member

@psafont psafont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Member

@psafont psafont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a new module that seems security-related, but its usage is not obvious to me, it lacks dopcumentation, and is missing unit-tests. Please at least add documentation and intended usage so we can change the module to make usre there aren't any footguns lurking around. After that, unit-test will better document how touse it and highlight edge-cases.

Copy link
Contributor

@lindig lindig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs documentation. I'm approving this but expect this to be updated.

Read and convert to [(<service_name>/<key>, <value>)] pair list.
The list is intended to store in VM_guest_metrics.services at last *)
let get_guest_services (lookup : string -> string option)
(list : string -> string list) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the list function doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list is defined in xapi_xenops.ml update_vm. It lists all subdirs and keys in one depth under the given dir. In its definition, the data source is a big string string map like [("a", ""); ("a/b", ""); ("a/b/k1", "v1"); ("a/b/k2", "v2"); ("a/c/k1", "v1"); ("a/c/k2", "v2")]. Then function list "a" will give all subdirs ["b", "c"]. It needs to be noticed that the data source is not exposed to the caller in xapi_guest_agent.ml

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utop # list_subkeys ["aaa/bbb/c", "x"] "aaa/bb";;
- : string list = ["b"]

Is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's incorrect. I believe the real implementation of list in xapi_xenops.ml update_vm has this problem, too. Normally, it's a internal function and the caller only pass the parameter as a intact dir, so the problem is not exposed. It deserves to rasie a ticket to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  let ls assoc path =
    let split = String.split_on_char '/' in
    let prefix = split path in
    let paths = List.map (fun (path, _) -> split path) assoc in
    let rec entry prefix path =
      match prefix, path with
      | [], x::_ -> Some x
      | x::xs, y::ys when x = y -> entry xs ys
      | _ -> None
    in
      List.filter_map (entry prefix) paths

@andyhhp
Copy link
Collaborator

andyhhp commented Feb 25, 2025

xenstore is already a bottlekneck. Xapi watching these keys really means xenopsd watching it and more traffic over message switch, which has proved to be an amplification vector in the past.

How many new watches does this create?

@lindig
Copy link
Contributor

lindig commented Feb 25, 2025

I would not expect these values to be updated frequently over the lifetime of a VM - so would not expect an impact from watches. @last-genius

@changlei-li
Copy link
Contributor Author

Yes. Only single digit number of service-install data are written in data/service by guest agent. So, the path will be only written once after VM starting and expected not changed later.

@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from bb2816f to 1de3160 Compare February 26, 2025 09:27
@lindig
Copy link
Contributor

lindig commented Feb 26, 2025

I am a bit puzzled by introducing a Limit module but only using it for part of the keys that a VM is using. If there is no unified mechanism this is easy to circumvent by using different keys that don't maintain a quota.

@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from 1de3160 to 17a5a1a Compare February 26, 2025 10:12
@changlei-li

This comment was marked as outdated.

@changlei-li

This comment was marked as outdated.

@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from 17a5a1a to a09380e Compare February 27, 2025 05:09
@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from a09380e to d2c0b51 Compare March 3, 2025 12:26
@changlei-li
Copy link
Contributor Author

Xenopsd already has a quota limit mechanism for guest_agent when reading xenstore. Remove the amout, key_len, value_len limit in this PR. It's better to use the general quota limit mechanism to keep it simple.

Signed-off-by: Changlei Li <changlei.li@cloud.com>
@changlei-li changlei-li force-pushed the private/changleli/CP-53314 branch from d2c0b51 to a6b5b7c Compare March 4, 2025 01:32
@changlei-li changlei-li merged commit b15e765 into xapi-project:feature/guest-vm-service-aware Mar 4, 2025
15 checks passed
@changlei-li changlei-li deleted the private/changleli/CP-53314 branch March 4, 2025 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants