Skip to content

Conversation

@GabrielBuica
Copy link
Contributor

Sets up the necessary environment variables, TRACEPARENT and OBSERVER_CONFIG_DIR for SMAPI observer.py configuration.

@GabrielBuica GabrielBuica marked this pull request as draft January 10, 2024 13:31
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-46377 branch 2 times, most recently from f539910 to 5ba8c33 Compare January 12, 2024 16:37
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-46377 branch from 6a5d418 to bdce7b5 Compare January 15, 2024 15:12
@GabrielBuica GabrielBuica marked this pull request as ready for review January 15, 2024 16:55
Copy link
Member

@mg12 mg12 left a comment

Choose a reason for hiding this comment

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

lgtm & passed dt bvt

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-46377 branch from b9e3d63 to beb72e0 Compare January 23, 2024 13:50
@GabrielBuica GabrielBuica requested a review from lindig January 29, 2024 10:43
raise Api_errors.(Server_error (invalid_value, ["component"; component]))

let observed_components_of components =
match components with [] -> startup_components () | components -> components
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks dubious to me. How can an empty argument observe anything? I think the handling of the empty list is unexpected for clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I understand it, it is because of how things are stored in the database. When you create an observer and you don't specify the components, the expectation is that all components are enabled. Querying the database for this observer returns empty. I don't know the details of why was implemented like this, but I agree with it being annoying for clients.

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem with the current design is that you can't have no components being observed because the empty list maps to all components. I think @mg12 should review this. It would be cleaner to use an option:

let observed_components_of = function
| None -> startup_components ()
| Some comps -> comps

Now one could calls observed_components of (Some []) and get back the empty list. Alternatively the behaviour of the empty list needs to be documented.

Copy link
Member

Choose a reason for hiding this comment

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

@lindig I'll talk to @GabrielBuica about this. I think we should handle this specific change in a future PR, as this part is in the code for a long time and it's not related to the traceparent change of this PR.

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-46377 branch 2 times, most recently from e2a5cb4 to 92aa095 Compare January 31, 2024 09:42
@codecov
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (eff32e4) 45.38% compared to head (b5ce70d) 45.38%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5345   +/-   ##
=======================================
  Coverage   45.38%   45.38%           
=======================================
  Files          18       18           
  Lines        2937     2937           
=======================================
  Hits         1333     1333           
  Misses       1604     1604           
Flag Coverage Δ
python2.7 52.09% <ø> (ø)
python3.11 50.15% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Moves `module Component` in a separate file `xapi_observer_components.ml`.
Moves `module EnvRecord` in a seperate file `xapi_aux/env_record.ml`

Basic funcionality from `Xapi_observer` cannot be used from `sm_exec.ml`
because cycle dependencies. This commit does some housekeeping and
splits `xapi_observer.ml` into `xapi_observer.ml` and
`xapi_observer_components.ml` while also moving `module EnvRecord` under
`xapi_aux`. `xapi_observer_components.ml` also contains the functions
that act on components independent of the observers.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Adds a `xapi_observer_component.ml` function `is_component_enabled` ->
`component:t` --> `bool`. Returns `true` if the given `component`
is enabled in any of the observers.

A helper function is needed to check if `SMapi` component is enabled in
any of the observers.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
…_exec` calls

Adds `Tracing.SpanContext.trace_id_of_span_context` as an env variable.
Adds a new entry `observer_config_dir` in `xapi_globs.ml`. Sets this new
entry as an env variable.

Currently there is no path for SMAPI `observer.py` calls to access their
respective `TRACEPARENT`, nor to access the configuration files for
observers. This commit sets:
- `TRACEPARENT` as an environment variable if any smapi observer component
is enabled;
- `OBSERVER_CONFIG_DIR` as an environment variable if any smapi observer
component is enabled. This contains the path to the enabled observers
configuration files.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Defines `default_path_env_pair` as the default value used by optional
parameter `?env`.

External clients of `Forkhelpers` need to include the value
`default_path_env_pair` when passing an argument to `?env`. Now this
value is defined inside the module for client use.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Moves `config_root` under `observer_confi_dir` in `xapi_globs.ml`.
Adds `observer_conf_path` function that constructs the path based on
`uuid`.
Removes `~config_root` parameter.

There were various ways to define paths is `Dom0ObserverConfig` which
increase the probabilty of introducing bugs in the future. This
consolidates them into `observer_conf_path_of`.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Splits functionality `env_vars_of_observer` into `traceparent_of_dbg`
under `debuginfo.ml` and `env_vars_of_component` under
`xapi_observer_components.ml.

Doing the processing of traceparent and of the necessary observer env
vars under their respective modules increases the readablity of
`sm_exec.ml`.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-46377 branch from 449111a to b5ce70d Compare February 1, 2024 09:22
@GabrielBuica
Copy link
Contributor Author

GabrielBuica commented Feb 1, 2024

Passed bvt after addressing comments and rebasing.

@mg12 mg12 merged commit 0981f9e into xapi-project:master Feb 1, 2024
@github-actions
Copy link

github-actions bot commented Feb 1, 2024

pytype_reporter extracted 49 problem reports from pytype output.

You can check the results of the job here

@GabrielBuica GabrielBuica deleted the private/dbuica/CP-46377 branch February 6, 2024 15:34
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.

6 participants