Pull in variant-enabled Broker

Switch the Broker submodule to a version with `broker::variant` enabled
and provide new overloads for `broker::variant` in the Broker manager.
This commit is contained in:
Dominik Charousset 2023-11-11 09:21:00 +01:00 committed by Tim Wojtulewicz
parent 6de51f0d7a
commit 0a84aad417
3 changed files with 30 additions and 5 deletions

@ -1 +1 @@
Subproject commit 69ccbf3329bf77d04854ae5dbafe3cb05346fc1c Subproject commit 861c20612e8b28811458ff9a96f091cc6de0c005

View file

@ -29,6 +29,10 @@
#include "zeek/telemetry/Manager.h" #include "zeek/telemetry/Manager.h"
#include "zeek/util.h" #include "zeek/util.h"
#ifdef BROKER_HAS_VARIANT
#include <broker/variant.hh>
#endif
using namespace std; using namespace std;
namespace { namespace {
@ -41,6 +45,19 @@ broker::data&& convert_if_broker_variant_or_move(broker::data& arg) { return std
broker::vector& broker_vector_from(broker::data& arg) { return broker::get<broker::vector>(arg); } broker::vector& broker_vector_from(broker::data& arg) { return broker::get<broker::vector>(arg); }
#ifdef BROKER_HAS_VARIANT
broker::data convert_if_broker_variant(const broker::variant& arg) { return arg.to_data(); }
broker::data convert_if_broker_variant_or_move(const broker::variant& arg) { return arg.to_data(); }
broker::vector broker_vector_from(const broker::variant& arg) {
auto tmp = arg.to_data();
return std::move(broker::get<broker::vector>(tmp));
}
#endif
// Converts a string_view into a string to make sure that we can safely call `.c_str()` on the result. // Converts a string_view into a string to make sure that we can safely call `.c_str()` on the result.
template<class View> template<class View>
std::enable_if_t<std::is_same_v<std::decay_t<View>, std::string_view>, std::string> c_str_safe(View&& arg) { std::enable_if_t<std::is_same_v<std::decay_t<View>, std::string_view>, std::string> c_str_safe(View&& arg) {
@ -195,6 +212,14 @@ namespace {
std::string RenderMessage(const broker::data& d) { return util::json_escape_utf8(broker::to_string(d)); } std::string RenderMessage(const broker::data& d) { return util::json_escape_utf8(broker::to_string(d)); }
#ifdef BROKER_HAS_VARIANT
std::string RenderMessage(const broker::variant& d) { return util::json_escape_utf8(broker::to_string(d)); }
std::string RenderMessage(const broker::variant_list& d) { return util::json_escape_utf8(broker::to_string(d)); }
#endif
std::string RenderMessage(const broker::store::response& x) { std::string RenderMessage(const broker::store::response& x) {
return util::fmt("%s [id %" PRIu64 "]", (x.answer ? broker::to_string(*x.answer).c_str() : "<no answer>"), x.id); return util::fmt("%s [id %" PRIu64 "]", (x.answer ? broker::to_string(*x.answer).c_str() : "<no answer>"), x.id);
} }
@ -207,9 +232,9 @@ std::string RenderMessage(const broker::status& s) { return broker::to_string(s.
std::string RenderMessage(const broker::error& e) { std::string RenderMessage(const broker::error& e) {
if ( auto ctx = e.context() ) if ( auto ctx = e.context() )
return util::fmt("%s (%s)", to_string(e.code()).c_str(), to_string(*ctx).c_str()); return util::fmt("%s (%s)", broker::to_string(e.code()).c_str(), to_string(*ctx).c_str());
else else
return util::fmt("%s (null)", to_string(e.code()).c_str()); return util::fmt("%s (null)", broker::to_string(e.code()).c_str());
} }
template<class DataOrVariant> template<class DataOrVariant>

View file

@ -18,8 +18,8 @@ Telemetry::INT_GAUGE, broker, buffered-messages, [type], [data], 0.0
count_value, 0 count_value, 0
Telemetry::INT_GAUGE, broker, buffered-messages, [type], [command], 0.0 Telemetry::INT_GAUGE, broker, buffered-messages, [type], [command], 0.0
count_value, 0 count_value, 0
Telemetry::INT_GAUGE, broker, buffered-messages, [type], [routing-update], 1.0 Telemetry::INT_GAUGE, broker, buffered-messages, [type], [routing-update], 0.0
count_value, 1 count_value, 0
Telemetry::INT_GAUGE, broker, buffered-messages, [type], [ping], 0.0 Telemetry::INT_GAUGE, broker, buffered-messages, [type], [ping], 0.0
count_value, 0 count_value, 0
Telemetry::INT_GAUGE, broker, buffered-messages, [type], [pong], 0.0 Telemetry::INT_GAUGE, broker, buffered-messages, [type], [pong], 0.0