Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection based, no app coupling), verified by the test suite (1103 passing): Data reflection: - Reflect.hpp now (de)serializes chrono::duration, chrono::time_point, std::variant (tagged), std::array, and non-string-keyed std::map; Meta.hpp gains is_time_point_v et al. Async: - EventBus gains Mode::Async (worker-thread dispatch + flush()). - ThreadPool gains a bounded queue, try_submit(), and rejection stats. New modules / containers: - Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker, ResourceMonitor. - Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V> (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats). - System: process/CPU/memory metrics (Metrics.hpp) and a streaming Process API. Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions, history states, deferred events), Configuration/Logging reflection helpers, and the accompanying test suites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
43b5a81504
commit
80293ee56f
93 files changed
+8500
-3312
No files matched your search
@@ -25,6 +25,15 @@ namespace Void::Logging
|
||||
m_count = fields.size();
|
||||
}
|
||||
|
||||
FieldScope::FieldScope(
|
||||
std::vector<std::pair<std::string, std::string>> fields)
|
||||
{
|
||||
m_count = fields.size();
|
||||
for (auto& [k, v] : fields) {
|
||||
t_fields.emplace_back(std::move(k), std::move(v));
|
||||
}
|
||||
}
|
||||
|
||||
FieldScope::~FieldScope() noexcept
|
||||
{
|
||||
if (!m_active) {
|
||||
|
||||
@@ -394,9 +394,14 @@ namespace Void::Logging
|
||||
if (!entry.fields.empty()) {
|
||||
auto fobj = Json::object();
|
||||
for (const auto& [k, v] : entry.fields) {
|
||||
if (!m_fields.allows(k)) {
|
||||
continue;
|
||||
}
|
||||
fobj.as_object().emplace_back(k, Json::Value{v});
|
||||
}
|
||||
o.emplace_back("fields", std::move(fobj));
|
||||
if (!fobj.as_object().empty()) {
|
||||
o.emplace_back("fields", std::move(fobj));
|
||||
}
|
||||
}
|
||||
o.emplace_back("message", Json::Value{entry.message});
|
||||
if (auto file = FormatDetail::file_basename(entry); !file.empty()) {
|
||||
@@ -440,6 +445,9 @@ namespace Void::Logging
|
||||
out += crumb;
|
||||
}
|
||||
for (const auto& [k, v] : entry.fields) {
|
||||
if (!m_fields.allows(k)) {
|
||||
continue;
|
||||
}
|
||||
out += ' ';
|
||||
out += k;
|
||||
out += '=';
|
||||
|
||||
+24
-12
@@ -101,13 +101,23 @@ namespace Void::Logging
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Field allow/deny lists for the structured (json/logfmt) sinks, from
|
||||
// the per-sink keys `fields.include` / `fields.exclude` (comma lists).
|
||||
FieldFilter make_field_filter(const Configuration::Config& cfg)
|
||||
{
|
||||
FieldFilter f;
|
||||
f.include = split_list(cfg.get_or("fields.include", ""));
|
||||
f.exclude = split_list(cfg.get_or("fields.exclude", ""));
|
||||
return f;
|
||||
}
|
||||
|
||||
std::shared_ptr<const Formatter>
|
||||
make_formatter(const Configuration::Config& cfg)
|
||||
{
|
||||
const auto format = cfg.get_or("format", "default");
|
||||
if (format == "pattern") {
|
||||
auto fmt = std::make_shared<PatternFormatter>(
|
||||
std::string{cfg.get_or(
|
||||
auto fmt =
|
||||
std::make_shared<PatternFormatter>(std::string{cfg.get_or(
|
||||
"pattern", "{time} [{level}] {scopes}{message}")});
|
||||
if (cfg.get_or_as<bool>("color", false)) {
|
||||
fmt->set_color_policy(ColorPolicy::defaults());
|
||||
@@ -115,10 +125,14 @@ namespace Void::Logging
|
||||
return fmt;
|
||||
}
|
||||
if (format == "json") {
|
||||
return std::make_shared<JsonLinesFormatter>();
|
||||
auto fmt = std::make_shared<JsonLinesFormatter>();
|
||||
fmt->set_field_filter(make_field_filter(cfg));
|
||||
return fmt;
|
||||
}
|
||||
if (format == "logfmt") {
|
||||
return std::make_shared<LogfmtFormatter>();
|
||||
auto fmt = std::make_shared<LogfmtFormatter>();
|
||||
fmt->set_field_filter(make_field_filter(cfg));
|
||||
return fmt;
|
||||
}
|
||||
return nullptr; // "default": per-sink built-in rendering
|
||||
}
|
||||
@@ -214,8 +228,7 @@ namespace Void::Logging
|
||||
"split.dir");
|
||||
}
|
||||
SplitFileLogger::Options opt;
|
||||
opt.combined =
|
||||
sub.get_or_as<bool>("split.combined", true);
|
||||
opt.combined = sub.get_or_as<bool>("split.combined", true);
|
||||
opt.max_bytes =
|
||||
sub.get_or_as<std::size_t>("split.max_kb", 1024) * 1024;
|
||||
opt.max_files =
|
||||
@@ -223,8 +236,8 @@ namespace Void::Logging
|
||||
opt.mode = dispatch.mode;
|
||||
opt.capacity = dispatch.capacity;
|
||||
opt.policy = dispatch.policy;
|
||||
auto sink = SplitFileLogger::open(
|
||||
std::filesystem::path{dir}, opt);
|
||||
auto sink =
|
||||
SplitFileLogger::open(std::filesystem::path{dir}, opt);
|
||||
if (!sink.has_value()) {
|
||||
return Void::Result::fail(std::move(sink).error());
|
||||
}
|
||||
@@ -241,15 +254,14 @@ namespace Void::Logging
|
||||
}
|
||||
HistoryLogger::Options opt;
|
||||
opt.max_bytes =
|
||||
sub.get_or_as<std::size_t>("history.max_kb", 8192) *
|
||||
1024;
|
||||
sub.get_or_as<std::size_t>("history.max_kb", 8192) * 1024;
|
||||
opt.max_files =
|
||||
sub.get_or_as<std::size_t>("history.max_files", 10);
|
||||
opt.mode = dispatch.mode;
|
||||
opt.capacity = dispatch.capacity;
|
||||
opt.policy = dispatch.policy;
|
||||
auto sink = HistoryLogger::open(
|
||||
std::filesystem::path{path}, opt);
|
||||
auto sink =
|
||||
HistoryLogger::open(std::filesystem::path{path}, opt);
|
||||
if (!sink.has_value()) {
|
||||
return Void::Result::fail(std::move(sink).error());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user