Skip to content
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

tracing: observe modes and other tracing improvements. #5612

Conversation

GabrielBuica
Copy link
Contributor

As a follow-up to commenting out the warning when no tracer providers were enabled here #5583. This is meant to solve the issue of spamming the logs by properly setting the observe mode inside the library.

This is based on top of #5601 that addresses missing lock in the library.

Some other improvements:

  • removes some code duplication;
  • adds unit tests for the library;
  • moves functions under a more appropriate module level;
  • adds documentation on TracerProvider module.

Copy link
Contributor

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

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

Github doesn't let me comment on the commit messages, but you have some typos there. E.g. 'proveder', 'enbaled'.

Copy link
Contributor

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

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

The quality gate in the CI complains that we have 1 new .ml file without .mli. It probably refers to 'tracing_export.ml', if you add an .mli for it, the CI should pass

@GabrielBuica
Copy link
Contributor Author

The quality gate in the CI complains that we have 1 new .ml file without .mli. It probably refers to 'tracing_export.ml', if you add an .mli for it, the CI should pass

I think it's test_tracing.ml that's new.

@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-tracing-observe-modes branch from e01650c to 847aeba Compare May 2, 2024 15:00
@GabrielBuica
Copy link
Contributor Author

Passed BST-BVT 197856 and some manual testing.

ocaml/xapi/context.ml Outdated Show resolved Hide resolved
ocaml/libs/tracing/tracing.ml Outdated Show resolved Hide resolved
ocaml/libs/tracing/tracing.ml Show resolved Hide resolved
edwintorok and others added 3 commits May 7, 2024 11:25
It is not safe to access a global hashtable from multiple threads, even if the operations are read-only
(it may be concurrently changed by another thread, which then may result in errors in the racing thread).

This means we must always take the mutex, and because OCaml doesn't have a reader-writer mutex, we need to take the exclusive mutex.

Eventually we should use a better datastructure here (immutable maps, or lock-free datastructures), but for now
fix the datastructure that we currently use to be thread-safe.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
In preparation for OCaml 5, on OCaml 4 they'd be equivalent.

Note that adding Atomic doesn't make operations on these values always atomic: that is
the responsibility of surrounding code.
E.g. Atomic.get + Atomic.set is not atomic, because another domain might've raced and changed the value inbetween
(so in that case Atomic.compare_and_set should be used).

However for global flags that are read multiple times, but set from a central place this isn't a problem.

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Sets `observe` to `false` until at least one tracer provider is enabled.
If all tracer providers are disabled we set it back to `false`.

Prior to this `observe` seemed to be always `true` (apart from unit
tests). This would cause `with_tracing` to spam the logs with warnings
`No provider found...` until at least one tracer provider is enabled.

By setting `observe` to `false` as default and updating it depending on
the state of the tracer providers, `with_tracing` should now execute no
extra operations. Therefore, we avoid spamming the logs unnecessarily.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-tracing-observe-modes branch from 5a627c8 to f4eb5f2 Compare May 7, 2024 10:45
ocaml/libs/tracing/tracing.ml Show resolved Hide resolved
@@ -405,6 +404,13 @@ let test_hashtbl_leaks () =
let test_trace_log_dir = trace_log_dir ~test_name:"test_hashtbl_leaks" () in
let __context = Test_common.make_test_database () in
let self = test_create ~__context ~enabled:true () in
let filter_export_spans span =
match Span.get_name span with
| "Tracing.flush_spans" | "Tracing.File.export" | "Tracing.Http.export" ->
Copy link
Contributor

Choose a reason for hiding this comment

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

These are very specific names. Can we be sure they arrive exactly like this? Otherwise it would be good to downcase them before the match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've downcased them before matching.

Create a new unit test file `test_tracing.ml` for the `tracing` library.
Add tests for `create`/`set`/`destroy` tracer providers.

Now that we change the library to have `observe` modes based on whether
or not we have `tracer providers` enabled, we want to make sure that
functions on applied on tracer providers set the correct mode for the
library.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Removes code duplication in `storage_mux.ml` by using the
already existing `with_dbg` implementation from `debuginfo` module.

This should lower the chances of unintentionally introducing bugs by
having to maintain two version of the same functions. e.g. Not using the
no op when tracing is disabled and generating unwanted warning messages.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
Moves the following:

- `create` under `TracerProvider`;
- `set` under `TracerProvider`;
- `destroy` under `TracerProvider;
- `get_tracer_providers` unde `TracerProvider`;
- `get_tracer` under `Tracer`.

Adds documentation for `TracerProvider` module.

It kept being confusing of what `Tracing.set` does unless I was going through
the implementation again and again. Therefore, I moved some of the
functions so that their functionality becomes (hopefully) more intuitive.

Signed-off-by: Gabriel Buica <danutgabriel.buica@cloud.com>
@GabrielBuica GabrielBuica force-pushed the private/dbuica/CP-48195-tracing-observe-modes branch from f4eb5f2 to 43e26f3 Compare May 9, 2024 11:56
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: the new unit tests will capture future issues with the observe mode, and passed BVT & BST.

@GabrielBuica
Copy link
Contributor Author

Latest BVT+BST 198401 passed

@psafont psafont merged commit 568323b into xapi-project:master May 22, 2024
14 checks passed
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.

None yet

5 participants