Repository navigation
Conversation
|
FYI: The code was internally reviewed (not as single PR ) and this is just a pushout. The main algos did not changed comapred to |
C++ health monitor: old API to new APIScopeThis report maps the old C++ health monitor API to the new one. Build targets
Headers
The new Namespaces
Return types
Access a HealthMonitorBuilder
HealthMonitor
Deadline monitor
Heartbeat monitor
Logic monitor
Tags
TimeRange
Thread parameters
Removed snake_case APIThe old API keeps deprecated snake_case forwarders.
Error mappingThe old
To check an error, compare Behaviour changesA Test supportThe old API has no mocks.
ExampleOld code, from #include <score/mw/health/common.h>
#include <score/mw/health/health_monitor.h>
#include <score/mw/log/rust/stdout_logger_init.h>
score::mw::log::rust::StdoutLoggerBuilder builder;
builder.Context("APP").LogLevel(score::mw::log::rust::LogLevel::Verbose).SetAsDefaultLogger();
using namespace score::mw::health;
auto builder_mon = deadline::DeadlineMonitorBuilder().AddDeadline(
DeadlineTag("deadline_1"), TimeRange(std::chrono::milliseconds(50), std::chrono::milliseconds(100)));
MonitorTag ident("monitor");
auto hm_res = HealthMonitorBuilder()
.AddDeadlineMonitor(ident, std::move(builder_mon))
.WithInternalProcessingCycle(std::chrono::milliseconds(50))
.WithSupervisorApiCycle(std::chrono::milliseconds(50))
.Build();
auto hm = std::move(*hm_res);
auto deadline_monitor_res = hm.GetDeadlineMonitor(ident);
hm.Start();
score::mw::lifecycle::report_running();
auto deadline_mon = std::move(*deadline_monitor_res);
auto deadline_res = deadline_mon.GetDeadline(DeadlineTag("deadline_1"));
auto deadline_guard = deadline_res.value().Start();New code: #include <score/health_monitor/deadline.h>
#include <score/health_monitor/deadline_monitor.h>
#include <score/health_monitor/deadline_monitor_builder.h>
#include <score/health_monitor/health_monitor.h>
#include <score/health_monitor/health_monitor_builder.h>
#include <score/health_monitor/tag.h>
#include <score/health_monitor/time_range.h>
using namespace score::health_monitor;
auto deadline_builder = DeadlineMonitorBuilder{}.AddDeadline(
DeadlineTag{"deadline_1"}, TimeRange{std::chrono::milliseconds(50), std::chrono::milliseconds(100)});
constexpr MonitorTag kDeadlineMonitor{"deadline_monitor"};
auto hm_res = HealthMonitorBuilder{}
.AddDeadlineMonitor(kDeadlineMonitor, std::move(deadline_builder))
.WithInternalProcessingCycle(std::chrono::milliseconds(50))
.WithSupervisorApiCycle(std::chrono::milliseconds(50))
.Build();
const auto hm = std::move(hm_res).value();
const auto deadline_mon = hm->GetDeadlineMonitor(kDeadlineMonitor).value();
const auto deadline = deadline_mon->GetDeadline(DeadlineTag{"deadline_1"}).value();
if (!hm->Start().has_value())
{
return EXIT_FAILURE;
}
score::mw::lifecycle::report_running();
const auto deadline_guard = deadline->Start();The short form calls The current example also uses a heartbeat monitor and a logic monitor. |
The C++ API in score/health_monitor/src/cpp wraps the Rust core through its FFI. Remove this wrapper, its tests and the targets cpp_unit_tests, cpp_integration_tests and health_monitoring_cc_stub_supervisor. A native C++ implementation replaces the wrapper in the next commits. The Rust core and its FFI do not change. Until the native implementation is complete, the health_monitoring_cc alias, the C++ example and the complex monitoring integration test refer to targets that do not exist. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Add the interfaces, value types, error domain, gmock mocks and unit tests of a native C++ health monitor in score/health_monitor/src/cpp. Applications include the public headers as score/health_monitor/<file>.h and the mocks as score/health_monitor/mock_<name>.h. The health_monitoring_cc alias points to the new :health_monitor target. - The builders are declared here and defined in a later step. - Every interface method, builder call, Deadline::Start() and the TimeRange constructor are noexcept. Errors come back through score::Result. - HealthMonitor::Start() documents that a failure to create the worker or to apply its ThreadParameters terminates the process. - MonitorTag, DeadlineTag and StateTag are each asserted to be standard-layout and trivially copyable. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Each C++ health monitor test records the comp_req__health_monitor__* requirements that it verifies through gtest RecordProperty. It also records the test type, the derivation technique and a description. This follows the S-CORE test-to-requirement linking convention, so docs-as-code links the tests to the requirements. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Port the Rust heartbeat monitor to HeartbeatMonitorImpl<Clock> in score/health_monitor/src/cpp/heartbeat_monitor. Its Create() factory checks the cycle, and one atomic word holds the heartbeat state. Add the internal MonitorEvaluator seam, a logger that names the monitor tag in every log line, and a fake clock for tests. Define the HeartbeatMonitorBuilder constructor. The unit tests record the comp_req__health_monitor__* requirements that they verify through gtest RecordProperty. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
The C++ health monitor runtime ports the Rust health monitor runtime. HealthMonitorBuilder::Build() validates the configuration and creates the heartbeat monitors. Build() rejects deadline monitors and logic monitors. Build() rejects a supervisor or internal cycle that steady_clock::duration cannot hold. HealthMonitor::GetHeartbeatMonitor() returns each heartbeat monitor only once. HealthMonitor::Start() connects the supervisor client and starts a jthread worker. The worker evaluates every monitor in each internal cycle. The worker sends an alive notification to the supervisor in each supervisor cycle. The worker stops at the first monitor failure. Each monitor logs its own evaluation failure. A NonRelocatableVector holds the monitor entries and does not grow after Build(). The label_flag //score/health_monitor/src/cpp:supervisor_client selects the supervisor client backend. The backend is the launch manager alive client by default, a stub, or an external cc_library. The public API tests use the stub backend and need no launch manager. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Port the Rust logic monitor to C++. HealthMonitorBuilder::Build() now creates logic monitors, and HealthMonitor::GetLogicMonitor() returns each logic monitor only once. The unit tests record the requirements that they verify. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Port the Rust deadline monitor to C++. HealthMonitorBuilder::Build() now creates deadline monitors, and HealthMonitor::GetDeadlineMonitor() returns each deadline monitor only once. Taken<T> gets a release hook, so a released deadline is available to the next GetDeadline() call without an allocation. The unit tests record the requirements that they verify. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
A blocked start log on the worker thread moved the start time of the monitors later. Heartbeats on time then counted as too early, and the first evaluation and alive notification came late. Start() now logs before it creates the worker. RecorderMock tests prove that healthy cycles do not log, and that failure logs come after the decisions that they report. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
The C++ example and the complex monitoring integration test use the API of the native C++ health monitor. They log through mw::log and no longer link the Rust stdout logger. Their behaviour does not change. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Compile-time checks show that a time range or a cycle cannot be set from microseconds or fractional milliseconds. A separate test binary counts every operator new after Start() while all three monitor kinds report and the worker runs, and expects none. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
The example now reports a heartbeat and moves a logic monitor between two states in each loop, next to the existing deadline measurement. The -d and -m options and the SIGUSR1 supervision failure keep their behaviour, so the demo verification is unchanged. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
The detailed design shows the src/cpp and src/rust trees and states that the two implementations are independent. The C++ code no longer uses the Rust FFI, which stays part of the Rust implementation. The module safety plan names the new C++ test targets, and the static analysis README uses :health_monitor as its example target. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
ReleaseHook deletes its copy and move operations, because a handle keeps the address of its hook, and the Taken converting constructor is explicit and its assignments are lvalue-qualified. This removes the MISRA C++:2023 results for rules 4.1.2, 7.11.3, 15.0.2, 15.1.3 and 18.4.1 in taken.h. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
| namespace score::health_monitor::details | ||
| { | ||
|
|
||
| DeadlineImpl::DeadlineImpl( |
| time}}; | ||
| } | ||
|
|
||
| HealthMonitorImpl::HealthMonitorImpl( |
|
|
||
| } // namespace | ||
|
|
||
| Worker::Worker( |
The supervisor client backends included internal/logger.h, which was a private header of :health_monitor_base. internal/logger.h is now the :logger library, and the backends depend on the targets of the headers they include. ToLogString moves to internal/log_string.h, so :logger does not need tag.h of :health_monitor_base. :health_monitor_base depends on the mw/log targets that provide its log headers. :error and :supervisor_client_interface drop their unused dependencies. This removes the findings of the Bazel dependency check (DWYU). Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
Every file includes the headers of the symbols it uses, and the targets depend on the libraries of those headers. The files that log include the mw/log headers directly. An IWYU pragma: export in internal/logger.h makes IWYU 0.26 abort with a failed assertion. The score_baselibs mapping names span.hpp as the header of score::cpp::span. Before, IWYU asked for type_traits.hpp, which only forward-declares span. thread_setup.cpp includes <algorithm> and <array> only on QNX, where it uses them. It keeps <climits> for PTHREAD_STACK_MIN in place of the private glibc header. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
adfcded to
c16eb72
Compare
The constructors of DeadlineImpl, HealthMonitorImpl and Worker take more than five parameters. Each parameter is a dependency that the object needs, and a parameter struct would add indirection without making the code easier to read. An in-source codeql comment above each definition suppresses the cpp/number-of-parameters-per-function result with this rationale. Signed-off-by: Arkadiusz Jedrzejewski <arkadiusz.jedrzejewski.ext@qorix.ai>
|
Documentation preview for this pull request is available at: |
C++ implementation of health monitor. Mostly same as Rust, but with some changes applied (e.g., changes in error handling, different order of logs).
Previous C++ bindings to Rust implementation are removed.
Once merged - PR containing Rust update to maintain parity is necessary.