-
Notifications
You must be signed in to change notification settings - Fork 11
Deadline monitoring CPP API #48
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
base: main
Are you sure you want to change the base?
Deadline monitoring CPP API #48
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //:license-checkStatus: Click to expand output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a C++ FFI (Foreign Function Interface) API for deadline monitoring functionality in the health monitoring library. The changes enable C++ code to interact with the Rust-based deadline monitoring system through a well-defined interface.
Changes:
- Added FFI bindings in Rust to expose deadline monitoring functionality to C++
- Implemented C++ wrapper classes (
HealthMonitor,DeadlineMonitor,Deadline) that interface with the Rust backend - Created build configuration for compiling both Rust static library and C++ library components
Reviewed changes
Copilot reviewed 20 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/health_monitoring_lib/src/lib.rs | Added HealthMonitor and HealthMonitorBuilder structs to manage deadline monitors |
| src/health_monitoring_lib/src/ffi.rs | New FFI functions for health monitor builder creation, destruction, and deadline monitor management |
| src/health_monitoring_lib/src/deadline/ffi.rs | New FFI functions for deadline monitor operations including builder, monitor, and deadline lifecycle management |
| src/health_monitoring_lib/src/deadline/deadline_monitor.rs | Refactored deadline monitoring to support FFI usage with internal helper methods |
| src/health_monitoring_lib/src/common.rs | Changed IdentTag to FFI-compatible representation and added FFI helper utilities |
| src/health_monitoring_lib/cpp/include/score/hm/health_monitor.h | C++ header defining HealthMonitor and HealthMonitorBuilder classes |
| src/health_monitoring_lib/cpp/include/score/hm/deadline/deadline_monitor.h | C++ header defining deadline monitoring classes (DeadlineMonitor, Deadline, DeadlineHandle) |
| src/health_monitoring_lib/cpp/include/score/hm/common.h | C++ header with common types including IdentTag, TimeRange, and FFI helpers |
| src/health_monitoring_lib/cpp/health_monitor.cpp | Implementation of C++ HealthMonitor classes |
| src/health_monitoring_lib/cpp/deadline/deadline_monitor.cpp | Implementation of C++ deadline monitoring classes |
| src/health_monitoring_lib/cpp/common.cpp | Implementation of DroppableFFIHandle utility class |
| src/health_monitoring_lib/cpp/ffi_helpers.h | Helper function to convert Rust error codes to C++ Error enum |
| src/health_monitoring_lib/cpp/tests/health_monitor_test.cpp | Basic test demonstrating the C++ API usage |
| src/health_monitoring_lib/BUILD | Updated build configuration to include Rust static library and C++ library targets |
Comments suppressed due to low confidence (1)
src/health_monitoring_lib/src/deadline/ffi.rs:1
- Corrected grammar from 'This function is provides' to 'This function is provided'.
use crate::common::ffi::*;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/health_monitoring_lib/cpp/include/score/hm/health_monitor.h
Outdated
Show resolved
Hide resolved
|
The created documentation from the pull request is available at: docu-html |
c1dd35a to
28fbfd4
Compare
28fbfd4 to
b9c92b8
Compare
|
I will fix QNX8 after first review rounds |
arkjedrz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nitpicks, but error handling can definitely be improved.
| use_repo(toolchains_qnx, "toolchains_qnx_ifs") | ||
|
|
||
| bazel_dep(name = "score_baselibs_rust", version = "0.0.3") | ||
| bazel_dep(name = "score_baselibs", version = "0.2.2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why moved here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep in code deps in single place
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
| #ifndef SCORE_HM_DEADLINE_DEADLINE_MONITOR_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not #pragma once?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because score ues ifdefs
src/health_monitoring_lib/cpp/include/score/hm/health_monitor.h
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I'm not against committing editor config files into repo, but this makes sense if we all use the same editor.
Maybe this file should be on the git ignore list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some ide shall work out of box, and this IDE is used mostly in score. If someone does not use it, it's no harm. If you have specific settings. So those are shared settings. user settings can always be overwritten/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said, I'm not against having those files in git. But if you want to enforce some style, then maybe you should look at repo hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this is checked by CI or (formatting etc )? If we don't add this, each user will have to do it manually for VS Code (and figure out how to do it with s-core bazel first).
| #include "score/hm/deadline/deadline_monitor.h" | ||
| #include "ffi_helpers.h" | ||
|
|
||
| extern "C" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this C interface is not declared in its own header?
At the moment it is hard to follow this code, but I understand it to work like this:
- We have core implementation in Rust.
- Then we have Foreign Function Interface (FFI) around that.
- Finally we have intended Cpp interface that is linked with FFI library.
I could be wrong above, but if I'm right, I would prefer to have folder and file structure organized around that. That should allow us to see boundaries easier and also should make build files a bit easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be more specific. Not sure what you mean here but from call site You are correct. I can extract C FFI calls to a separate header but not sure what it would help ;) I keep them isolated in context of where they are used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that there is not much comments in the code, there is also no description in readme file on the approach taken in this PR.
I would strongly recommend to explain how this code is working.
If you think that current folder / file structure is good, then I would recommend adding readme file that is specific to health monitoring library.
There I would expect some explanation on the approach taken and some description about folder structure.
This will help with maintainability and onboarding of new developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more doc. Note that the public API will get full doc only once the library stabilizes with other monitors to not need to rewrite docs that may change. If you need some specific additions, let me know.
src/health_monitoring_lib/cpp/include/score/hm/deadline/deadline_monitor.h
Outdated
Show resolved
Hide resolved
|
|
||
| ~HealthMonitor(); | ||
|
|
||
| score::cpp::expected<deadline::DeadlineMonitor, Error> get_deadline_monitor(const IdentTag& tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In baselibs there is also score::Result datatype which achieves the same as score::cpp::expected but also provides an error message to the user in addition to the error code.
Probably, we should decide once which of these types we will use in the public API and then consistently use one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, we can decide. I keep it kind of rust comaptible, where error is not restricted to be int32. I still prefer std::expected in this case.
| /// Adds a deadline with the given tag and duration range to the monitor. | ||
| DeadlineMonitorBuilder add_deadline(const IdentTag& tag, const TimeRange& range) &&; | ||
|
|
||
| ::score::cpp::optional<internal::FFIHandle> __drop_by_rust_impl() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is a way to make this method private/protected?
If I understand correctly, if the user would call this it would lead to undefined behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would not, it has defined behaviour.But I made it hidden
|
The FFI part looks like the place where things can go elegantly and subtle wrong without being warned. "In Rust unsafe is a keyword that allows programmers to bypass the compiler's automatic memory safety checks.." I would very much like to see Sanitizer being used in cpp and rust. A good start would be the AddressSanitizer. |
Correct! Feel free to create a ticket for that and bring this into the infrastructure team on how the asan shall be used in s-core (probably just a PR with a job integrated with bazel would be enough). for the Rust, miri is tracked in s-core however it's bigger story for bazel. eclipse-score/score#2010 |
bazel_cpp_toolchains offers features = ["asan"], for |
Great, then we need to wait a bit for the toolchain being officially rolled out and then we can do it, for me, no issue. Can you please create ticket for it in this repo ? Btw |
Here is an example how to use unreleased versions Using Unreleased Versions. It's a easy clean up once it's officially rolled out. |
|
77d3142 to
f31d045
Compare
| #include "score/hm/deadline/deadline_monitor.h" | ||
| #include "ffi_helpers.h" | ||
|
|
||
| extern "C" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that there is not much comments in the code, there is also no description in readme file on the approach taken in this PR.
I would strongly recommend to explain how this code is working.
If you think that current folder / file structure is good, then I would recommend adding readme file that is specific to health monitoring library.
There I would expect some explanation on the approach taken and some description about folder structure.
This will help with maintainability and onboarding of new developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If would say lets move that to the module template
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyway needed here or ? but should be in module template, agree
| rust_library( | ||
| name = "health_monitoring_lib", | ||
| srcs = glob(["src/**/*.rs"]), | ||
| srcs = glob(["rust/**/*.rs"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that right?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i made it symetric to cpp
| @@ -0,0 +1,108 @@ | |||
| /******************************************************************************** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some small test for the ffi call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do more UT on cpp side, either after all points of API and other are fine for everyone or as follow up, since I would prefer to have at least a second monitor (checkpoints) before making impl bit locked by UT
| Implementation structure | ||
| ------------------------ | ||
|
|
||
| src |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: bash
src
└── health_monitoring_lib
├── cpp # C++ API using Rust FFI
│ ├── include # C++ public header files.
│ │ └── ...
│ └── tests
└── rust # Rust implementation + FFI for C++
└── deadline
|
|
||
| #include <score/expected.hpp> | ||
| #include <score/hm/common.h> | ||
| #include <functional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> #include <optional>?
| DeadlineMonitor::new(self.deadlines) | ||
| } | ||
|
|
||
| pub(crate) fn _add_deadline_internal(&mut self, tag: &IdentTag, range: TimeRange) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> add_deadline_internal? It's already crate-internal and used, why prefix with _?
Closes #14