Skip to content

Conversation

can-anyscale
Copy link
Contributor

@can-anyscale can-anyscale commented Aug 12, 2025

Currently, the Metric class registers the metric name each time it records a new value, due to the C++ static initialization order fiasco. The base of this PR move all static metrics to runtime initialization, allowing us to safely perform metric registration in the constructor.

Note that I'm only doing this for the open-telemetry stack. The opencensus has a complex registration sequence using view+measure and I have hard time make it to work so I don't bother fixing it.

Test:

  • CI

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors metric registration by moving it from the Record method into the constructors of metric classes. This is a good change for performance and clarity. However, I've identified a potential thread-safety issue where a mutex was removed during this refactoring, which could lead to race conditions. I've also pointed out an opportunity to reduce code duplication in the derived metric classes to improve maintainability. Please see the detailed comments for suggestions.

@can-anyscale can-anyscale changed the title Can obsclean04 [core][obsclean/04] move metric registration to constructor Aug 12, 2025
@can-anyscale can-anyscale force-pushed the can-obsclean04 branch 2 times, most recently from 5210e2a to 12139b6 Compare August 12, 2025 20:28
@can-anyscale can-anyscale marked this pull request as ready for review August 12, 2025 20:29
@can-anyscale can-anyscale requested a review from a team as a code owner August 12, 2025 20:29
@can-anyscale can-anyscale added the go add ONLY when ready to merge, run all tests label Aug 12, 2025
@can-anyscale can-anyscale force-pushed the can-obsclean04 branch 2 times, most recently from 2705ff8 to 0750a73 Compare August 12, 2025 22:24
@can-anyscale can-anyscale marked this pull request as draft August 12, 2025 23:56
Base automatically changed from can-obsclean03 to can-obsclean02 August 13, 2025 17:02
@can-anyscale can-anyscale marked this pull request as ready for review August 13, 2025 17:11
Base automatically changed from can-obsclean02 to master August 13, 2025 19:56
@ray-gardener ray-gardener bot added core Issues that should be addressed in Ray Core observability Issues related to the Ray Dashboard, Logging, Metrics, Tracing, and/or Profiling labels Aug 14, 2025
@can-anyscale can-anyscale force-pushed the can-obsclean04 branch 2 times, most recently from bd6f10c to 4e6d29a Compare August 25, 2025 21:47
Copy link
Contributor

@MengjinYan MengjinYan left a comment

Choose a reason for hiding this comment

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

Nice!

@can-anyscale can-anyscale merged commit 306db86 into master Aug 26, 2025
5 checks passed
@can-anyscale can-anyscale deleted the can-obsclean04 branch August 26, 2025 16:29
liulehui pushed a commit to liulehui/ray that referenced this pull request Aug 26, 2025
…ect#55544)

Currently, the `Metric` class registers the metric name each time it
records a new value, due to the [C++ static initialization order
fiasco](https://en.cppreference.com/w/cpp/language/siof.html). The base
of this PR move all static metrics to runtime initialization, allowing
us to safely perform metric registration in the constructor.

Note that I'm only doing this for the open-telemetry stack. The
opencensus has a complex registration sequence using view+measure and I
have hard time make it to work so I don't bother fixing it.

Test:
- CI

Signed-off-by: Cuong Nguyen <[email protected]>
Signed-off-by: Lehui Liu <[email protected]>
tohtana pushed a commit to tohtana/ray that referenced this pull request Aug 29, 2025
…ect#55544)

Currently, the `Metric` class registers the metric name each time it
records a new value, due to the [C++ static initialization order
fiasco](https://en.cppreference.com/w/cpp/language/siof.html). The base
of this PR move all static metrics to runtime initialization, allowing
us to safely perform metric registration in the constructor.

Note that I'm only doing this for the open-telemetry stack. The
opencensus has a complex registration sequence using view+measure and I
have hard time make it to work so I don't bother fixing it.

Test:
- CI

Signed-off-by: Cuong Nguyen <[email protected]>
Signed-off-by: Masahiro Tanaka <[email protected]>
tohtana pushed a commit to tohtana/ray that referenced this pull request Aug 29, 2025
…ect#55544)

Currently, the `Metric` class registers the metric name each time it
records a new value, due to the [C++ static initialization order
fiasco](https://en.cppreference.com/w/cpp/language/siof.html). The base
of this PR move all static metrics to runtime initialization, allowing
us to safely perform metric registration in the constructor.

Note that I'm only doing this for the open-telemetry stack. The
opencensus has a complex registration sequence using view+measure and I
have hard time make it to work so I don't bother fixing it.

Test:
- CI

Signed-off-by: Cuong Nguyen <[email protected]>
Signed-off-by: Masahiro Tanaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests observability Issues related to the Ray Dashboard, Logging, Metrics, Tracing, and/or Profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants