Skip to content

Commit

Permalink
Add the default_attributes to Dom0ObserverConfig Observers
Browse files Browse the repository at this point in the history
The default_attributes are not added to the DB and so these are missing
in the observer.conf. Dom0ObserverConfig currently lacks a single source
of truth outside of the DB (and default_attributes is not given to the
DB) and so attributes outside of the DB are lost whenever a different
setter function is used. This should be reworked in future so that
observer.conf is read from/updated instead of regenerated each time.

Signed-off-by: Steven Woods <[email protected]>
  • Loading branch information
snwoods committed Feb 26, 2024
1 parent 10d38c6 commit 7a0d3e4
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions ocaml/xapi/xapi_observer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ module Xapi_cluster = struct
end
end

let default_attributes ~__context ~host ~name_label ~component =
let pool = Helpers.get_pool ~__context in
let host_label = Db.Host.get_name_label ~__context ~self:host in
let host_uuid = Db.Host.get_uuid ~__context ~self:host in
let pool_uuid = Db.Pool.get_uuid ~__context ~self:pool in
[
("xs.pool.uuid", pool_uuid)
; ("xs.host.name", host_label)
; ("xs.host.uuid", host_uuid)
; ("xs.observer.name", name_label)
; ("service.name", to_string component)
]

module ObserverConfig = struct
type t = {
otel_service_name: string
Expand Down Expand Up @@ -247,12 +260,18 @@ module ObserverConfig = struct
attrs

let config_of_observer ~__context ~component ~observer =
(* In the future this should be updated so that the config is read
from and updated instead of being regenerated. *)
let endpoints = Db.Observer.get_endpoints ~__context ~self:observer in
let host = Helpers.get_localhost ~__context in
let name_label = Db.Observer.get_name_label ~__context ~self:observer in
{
otel_service_name= component
otel_service_name= to_string component
; otel_resource_attributes=
attributes_to_W3CBaggage
(Db.Observer.get_attributes ~__context ~self:observer)
(Db.Observer.get_attributes ~__context ~self:observer
@ default_attributes ~__context ~host ~name_label ~component
)
; xs_exporter_zipkin_endpoints= zipkin_endpoints endpoints
; xs_exporter_bugtool_endpoint= bugtool_endpoint endpoints
}
Expand Down Expand Up @@ -292,8 +311,7 @@ module Dom0ObserverConfig (ObserverComponent : OBSERVER_COMPONENT) :
if Db.Observer.get_enabled ~__context ~self:observer then (
let observer_config =
ObserverConfig.config_of_observer ~__context
~component:(to_string ObserverComponent.component)
~observer
~component:ObserverComponent.component ~observer
in
Xapi_stdext_unix.Unixext.mkdir_rec dir_name 0o755 ;
let file_name = observer_conf_path_of ~uuid in
Expand Down Expand Up @@ -429,19 +447,6 @@ let assert_valid_attributes attributes =
)
attributes

let default_attributes ~__context ~host ~name_label ~component =
let pool = Helpers.get_pool ~__context in
let host_label = Db.Host.get_name_label ~__context ~self:host in
let host_uuid = Db.Host.get_uuid ~__context ~self:host in
let pool_uuid = Db.Pool.get_uuid ~__context ~self:pool in
[
("xs.pool.uuid", pool_uuid)
; ("xs.host.name", host_label)
; ("xs.host.uuid", host_uuid)
; ("xs.observer.name", name_label)
; ("service.name", to_string component)
]

let register_component ~__context ~self ~host ~component =
let name_label = Db.Observer.get_name_label ~__context ~self in
let attributes =
Expand Down Expand Up @@ -609,7 +614,10 @@ let set_attributes ~__context ~self ~value =
(fun c ->
let module Forwarder = (val get_forwarder c : ObserverInterface) in
Forwarder.set_attributes ~__context ~uuid
~attributes:(default_attributes ~__context ~host ~name_label ~component:c @ value)
~attributes:
(default_attributes ~__context ~host ~name_label ~component:c
@ value
)
)
(Db.Observer.get_components ~__context ~self
|> List.map of_string
Expand Down

0 comments on commit 7a0d3e4

Please sign in to comment.