Merge branch 'topic/neverlord/broker-variant'

* topic/neverlord/broker-variant:
  Pull in variant-enabled Broker
This commit is contained in:
Tim Wojtulewicz 2024-02-20 10:57:30 -07:00
commit 04d965a13a
5 changed files with 38 additions and 6 deletions

View file

@ -1,3 +1,10 @@
6.2.0-dev.545 | 2024-02-20 10:57:30 -0700
* Pull in variant-enabled Broker (Dominik Charousset, Corelight)
Switch the Broker submodule to a version with `broker::variant` enabled
and provide new overloads for `broker::variant` in the Broker manager.
6.2.0-dev.543 | 2024-02-15 11:08:16 -0500 6.2.0-dev.543 | 2024-02-15 11:08:16 -0500
* Bump zkg to v3.0.0 (Tim Wojtulewicz, Corelight) * Bump zkg to v3.0.0 (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
6.2.0-dev.543 6.2.0-dev.545

@ -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