mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Adhere to Zeek coding style
This commit is contained in:
parent
7c5c36959f
commit
2a21f2903a
9 changed files with 325 additions and 343 deletions
|
@ -61,7 +61,7 @@ auto opaque(NativeDblGaugeFamily* ptr)
|
|||
}
|
||||
|
||||
template <class F>
|
||||
auto withNative(Span<const std::string_view> xs, F continuation)
|
||||
auto with_native(Span<const std::string_view> xs, F continuation)
|
||||
{
|
||||
if ( xs.size() <= 10 )
|
||||
{
|
||||
|
@ -85,58 +85,58 @@ Manager::~Manager()
|
|||
{
|
||||
}
|
||||
|
||||
IntCounterFamily Manager::intCounterFam(std::string_view prefix,
|
||||
IntCounterFamily Manager::IntCounterFam(std::string_view prefix,
|
||||
std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
std::string_view unit, bool isSum)
|
||||
std::string_view unit, bool is_sum)
|
||||
{
|
||||
return withNative(labels, [&, this](auto xs)
|
||||
return with_native(labels, [&, this](auto xs)
|
||||
{
|
||||
auto ptr = deref(pimpl).counter_family(prefix, name, xs,
|
||||
helptext, unit, isSum);
|
||||
helptext, unit, is_sum);
|
||||
return IntCounterFamily{opaque(ptr)};
|
||||
});
|
||||
}
|
||||
|
||||
DblCounterFamily Manager::dblCounterFam(std::string_view prefix,
|
||||
DblCounterFamily Manager::DblCounterFam(std::string_view prefix,
|
||||
std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
std::string_view unit, bool isSum)
|
||||
std::string_view unit, bool is_sum)
|
||||
{
|
||||
return withNative(labels, [&, this](auto xs)
|
||||
return with_native(labels, [&, this](auto xs)
|
||||
{
|
||||
auto ptr = deref(pimpl).counter_family<double>(prefix, name, xs,
|
||||
helptext, unit, isSum);
|
||||
helptext, unit, is_sum);
|
||||
return DblCounterFamily{opaque(ptr)};
|
||||
});
|
||||
}
|
||||
|
||||
IntGaugeFamily Manager::intGaugeFam(std::string_view prefix,
|
||||
IntGaugeFamily Manager::IntGaugeFam(std::string_view prefix,
|
||||
std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
std::string_view unit, bool isSum)
|
||||
std::string_view unit, bool is_sum)
|
||||
{
|
||||
return withNative(labels, [&, this](auto xs)
|
||||
return with_native(labels, [&, this](auto xs)
|
||||
{
|
||||
auto ptr = deref(pimpl).gauge_family(prefix, name, xs,
|
||||
helptext, unit, isSum);
|
||||
helptext, unit, is_sum);
|
||||
return IntGaugeFamily{opaque(ptr)};
|
||||
});
|
||||
}
|
||||
|
||||
DblGaugeFamily Manager::dblGaugeFam(std::string_view prefix,
|
||||
DblGaugeFamily Manager::DblGaugeFam(std::string_view prefix,
|
||||
std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
std::string_view unit, bool isSum)
|
||||
std::string_view unit, bool is_sum)
|
||||
{
|
||||
return withNative(labels, [&, this](auto xs)
|
||||
return with_native(labels, [&, this](auto xs)
|
||||
{
|
||||
auto ptr = deref(pimpl).gauge_family<double>(prefix, name, xs,
|
||||
helptext, unit, isSum);
|
||||
helptext, unit, is_sum);
|
||||
return DblGaugeFamily{opaque(ptr)};
|
||||
});
|
||||
}
|
||||
|
@ -166,57 +166,57 @@ SCENARIO("telemetry managers provide access to counter singletons")
|
|||
{
|
||||
GIVEN("a telemetry manager")
|
||||
{
|
||||
NativeManager nativeMgr;
|
||||
Manager mgr{opaque(&nativeMgr)};
|
||||
NativeManager native_mgr;
|
||||
Manager mgr{opaque(&native_mgr)};
|
||||
WHEN("retrieving an IntCounter singleton")
|
||||
{
|
||||
auto first = mgr.counterSingleton("zeek", "int-count", "test");
|
||||
auto first = mgr.CounterSingleton("zeek", "int-count", "test");
|
||||
THEN("its initial value is zero")
|
||||
{
|
||||
CHECK_EQ(first.value(), 0);
|
||||
CHECK_EQ(first.Value(), 0);
|
||||
}
|
||||
AND_THEN("calling inc() or operator++ changes the value")
|
||||
AND_THEN("calling Inc() or operator++ changes the value")
|
||||
{
|
||||
first.inc();
|
||||
CHECK_EQ(first.value(), 1);
|
||||
first.inc(2);
|
||||
CHECK_EQ(first.value(), 3);
|
||||
first.Inc();
|
||||
CHECK_EQ(first.Value(), 1);
|
||||
first.Inc(2);
|
||||
CHECK_EQ(first.Value(), 3);
|
||||
CHECK_EQ(++first, 4);
|
||||
CHECK_EQ(first.value(), 4);
|
||||
CHECK_EQ(first.Value(), 4);
|
||||
}
|
||||
AND_THEN("calling counterSingleton again for the same name returns the same handle")
|
||||
{
|
||||
auto second = mgr.counterSingleton("zeek", "int-count", "test");
|
||||
auto second = mgr.CounterSingleton("zeek", "int-count", "test");
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("calling counterSingleton for a different name returns another handle")
|
||||
{
|
||||
auto third = mgr.counterSingleton("zeek", "int-count-2", "test");
|
||||
auto third = mgr.CounterSingleton("zeek", "int-count-2", "test");
|
||||
CHECK_NE(first, third);
|
||||
}
|
||||
}
|
||||
WHEN("retrieving a DblCounter singleton")
|
||||
{
|
||||
auto first = mgr.counterSingleton<double>("zeek", "dbl-count", "test");
|
||||
auto first = mgr.CounterSingleton<double>("zeek", "dbl-count", "test");
|
||||
THEN("its initial value is zero")
|
||||
{
|
||||
CHECK_EQ(first.value(), 0.0);
|
||||
CHECK_EQ(first.Value(), 0.0);
|
||||
}
|
||||
AND_THEN("calling inc() changes the value")
|
||||
AND_THEN("calling Inc() changes the value")
|
||||
{
|
||||
first.inc();
|
||||
CHECK_EQ(first.value(), 1.0);
|
||||
first.inc(3.0);
|
||||
CHECK_EQ(first.value(), 4.0);
|
||||
first.Inc();
|
||||
CHECK_EQ(first.Value(), 1.0);
|
||||
first.Inc(3.0);
|
||||
CHECK_EQ(first.Value(), 4.0);
|
||||
}
|
||||
AND_THEN("calling counterSingleton again for the same name returns the same handle")
|
||||
{
|
||||
auto second = mgr.counterSingleton<double>("zeek", "dbl-count", "test");
|
||||
auto second = mgr.CounterSingleton<double>("zeek", "dbl-count", "test");
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("calling counterSingleton for a different name returns another handle")
|
||||
{
|
||||
auto third = mgr.counterSingleton<double>("zeek", "dbl-count-2", "test");
|
||||
auto third = mgr.CounterSingleton<double>("zeek", "dbl-count-2", "test");
|
||||
CHECK_NE(first, third);
|
||||
}
|
||||
}
|
||||
|
@ -227,55 +227,55 @@ SCENARIO("telemetry managers provide access to counter families")
|
|||
{
|
||||
GIVEN("a telemetry manager")
|
||||
{
|
||||
NativeManager nativeMgr;
|
||||
Manager mgr{opaque(&nativeMgr)};
|
||||
NativeManager native_mgr;
|
||||
Manager mgr{opaque(&native_mgr)};
|
||||
WHEN("retrieving an IntCounter family")
|
||||
{
|
||||
auto family = mgr.counterFamily("zeek", "requests", {"method"}, "test", "1", true);
|
||||
auto family = mgr.CounterFamily("zeek", "requests", {"method"}, "test", "1", true);
|
||||
THEN("the family object stores the parameters")
|
||||
{
|
||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.name(), "requests"sv);
|
||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"method"s});
|
||||
CHECK_EQ(family.helptext(), "test"sv);
|
||||
CHECK_EQ(family.unit(), "1"sv);
|
||||
CHECK_EQ(family.isSum(), true);
|
||||
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.Name(), "requests"sv);
|
||||
CHECK_EQ(toVector(family.LabelNames()), std::vector{"method"s});
|
||||
CHECK_EQ(family.Helptext(), "test"sv);
|
||||
CHECK_EQ(family.Unit(), "1"sv);
|
||||
CHECK_EQ(family.IsSum(), true);
|
||||
}
|
||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"method", "get"}});
|
||||
auto second = family.getOrAdd({{"method", "get"}});
|
||||
auto first = family.GetOrAdd({{"method", "get"}});
|
||||
auto second = family.GetOrAdd({{"method", "get"}});
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"method", "get"}});
|
||||
auto second = family.getOrAdd({{"method", "put"}});
|
||||
auto first = family.GetOrAdd({{"method", "get"}});
|
||||
auto second = family.GetOrAdd({{"method", "put"}});
|
||||
CHECK_NE(first, second);
|
||||
}
|
||||
}
|
||||
WHEN("retrieving a DblCounter family")
|
||||
{
|
||||
auto family = mgr.counterFamily<double>("zeek", "runtime", {"query"}, "test", "seconds", true);
|
||||
auto family = mgr.CounterFamily<double>("zeek", "runtime", {"query"}, "test", "seconds", true);
|
||||
THEN("the family object stores the parameters")
|
||||
{
|
||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.name(), "runtime"sv);
|
||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"query"s});
|
||||
CHECK_EQ(family.helptext(), "test"sv);
|
||||
CHECK_EQ(family.unit(), "seconds"sv);
|
||||
CHECK_EQ(family.isSum(), true);
|
||||
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.Name(), "runtime"sv);
|
||||
CHECK_EQ(toVector(family.LabelNames()), std::vector{"query"s});
|
||||
CHECK_EQ(family.Helptext(), "test"sv);
|
||||
CHECK_EQ(family.Unit(), "seconds"sv);
|
||||
CHECK_EQ(family.IsSum(), true);
|
||||
}
|
||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"query", "foo"}});
|
||||
auto second = family.getOrAdd({{"query", "foo"}});
|
||||
auto first = family.GetOrAdd({{"query", "foo"}});
|
||||
auto second = family.GetOrAdd({{"query", "foo"}});
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"query", "foo"}});
|
||||
auto second = family.getOrAdd({{"query", "bar"}});
|
||||
auto first = family.GetOrAdd({{"query", "foo"}});
|
||||
auto second = family.GetOrAdd({{"query", "bar"}});
|
||||
CHECK_NE(first, second);
|
||||
}
|
||||
}
|
||||
|
@ -286,65 +286,67 @@ SCENARIO("telemetry managers provide access to gauge singletons")
|
|||
{
|
||||
GIVEN("a telemetry manager")
|
||||
{
|
||||
NativeManager nativeMgr;
|
||||
Manager mgr{opaque(&nativeMgr)};
|
||||
NativeManager native_mgr;
|
||||
Manager mgr{opaque(&native_mgr)};
|
||||
WHEN("retrieving an IntGauge singleton")
|
||||
{
|
||||
auto first = mgr.gaugeSingleton("zeek", "int-gauge", "test");
|
||||
auto first = mgr.GaugeSingleton("zeek", "int-gauge", "test");
|
||||
THEN("its initial value is zero")
|
||||
{
|
||||
CHECK_EQ(first.value(), 0);
|
||||
CHECK_EQ(first.Value(), 0);
|
||||
}
|
||||
AND_THEN("calling inc(), dec(), operator++ or operator-- changes the value")
|
||||
AND_THEN("calling Inc(), Dec(), operator++ or operator-- changes the value")
|
||||
{
|
||||
first.inc();
|
||||
CHECK_EQ(first.value(), 1);
|
||||
first.inc(2);
|
||||
CHECK_EQ(first.value(), 3);
|
||||
first.dec();
|
||||
CHECK_EQ(first.value(), 2);
|
||||
first.Inc();
|
||||
CHECK_EQ(first.Value(), 1);
|
||||
first.Inc(2);
|
||||
CHECK_EQ(first.Value(), 3);
|
||||
first.Dec();
|
||||
CHECK_EQ(first.Value(), 2);
|
||||
CHECK_EQ(++first, 3);
|
||||
CHECK_EQ(first.value(), 3);
|
||||
CHECK_EQ(first.Value(), 3);
|
||||
CHECK_EQ(--first, 2);
|
||||
CHECK_EQ(first.value(), 2);
|
||||
CHECK_EQ(first.Value(), 2);
|
||||
first.Dec(2);
|
||||
CHECK_EQ(first.Value(), 0);
|
||||
}
|
||||
AND_THEN("calling gaugeSingleton again for the same name returns the same handle")
|
||||
{
|
||||
auto second = mgr.gaugeSingleton("zeek", "int-gauge", "test");
|
||||
auto second = mgr.GaugeSingleton("zeek", "int-gauge", "test");
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("calling gaugeSingleton for a different name returns another handle")
|
||||
{
|
||||
auto third = mgr.gaugeSingleton("zeek", "int-gauge-2", "test");
|
||||
auto third = mgr.GaugeSingleton("zeek", "int-gauge-2", "test");
|
||||
CHECK_NE(first, third);
|
||||
}
|
||||
}
|
||||
WHEN("retrieving a DblGauge singleton")
|
||||
{
|
||||
auto first = mgr.gaugeSingleton<double>("zeek", "dbl-gauge", "test");
|
||||
auto first = mgr.GaugeSingleton<double>("zeek", "dbl-gauge", "test");
|
||||
THEN("its initial value is zero")
|
||||
{
|
||||
CHECK_EQ(first.value(), 0.0);
|
||||
CHECK_EQ(first.Value(), 0.0);
|
||||
}
|
||||
AND_THEN("calling inc() or dec() changes the value")
|
||||
AND_THEN("calling Inc() or Dec() changes the value")
|
||||
{
|
||||
first.inc();
|
||||
CHECK_EQ(first.value(), 1.0);
|
||||
first.inc(3.0);
|
||||
CHECK_EQ(first.value(), 4.0);
|
||||
first.dec(2.0);
|
||||
CHECK_EQ(first.value(), 2.0);
|
||||
first.dec();
|
||||
CHECK_EQ(first.value(), 1.0);
|
||||
first.Inc();
|
||||
CHECK_EQ(first.Value(), 1.0);
|
||||
first.Inc(3.0);
|
||||
CHECK_EQ(first.Value(), 4.0);
|
||||
first.Dec(2.0);
|
||||
CHECK_EQ(first.Value(), 2.0);
|
||||
first.Dec();
|
||||
CHECK_EQ(first.Value(), 1.0);
|
||||
}
|
||||
AND_THEN("calling gaugeSingleton again for the same name returns the same handle")
|
||||
{
|
||||
auto second = mgr.gaugeSingleton<double>("zeek", "dbl-gauge", "test");
|
||||
auto second = mgr.GaugeSingleton<double>("zeek", "dbl-gauge", "test");
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("calling gaugeSingleton for a different name returns another handle")
|
||||
{
|
||||
auto third = mgr.gaugeSingleton<double>("zeek", "dbl-gauge-2", "test");
|
||||
auto third = mgr.GaugeSingleton<double>("zeek", "dbl-gauge-2", "test");
|
||||
CHECK_NE(first, third);
|
||||
}
|
||||
}
|
||||
|
@ -355,55 +357,55 @@ SCENARIO("telemetry managers provide access to gauge families")
|
|||
{
|
||||
GIVEN("a telemetry manager")
|
||||
{
|
||||
NativeManager nativeMgr;
|
||||
Manager mgr{opaque(&nativeMgr)};
|
||||
NativeManager native_mgr;
|
||||
Manager mgr{opaque(&native_mgr)};
|
||||
WHEN("retrieving an IntGauge family")
|
||||
{
|
||||
auto family = mgr.gaugeFamily("zeek", "open-connections", {"protocol"}, "test");
|
||||
auto family = mgr.GaugeFamily("zeek", "open-connections", {"protocol"}, "test");
|
||||
THEN("the family object stores the parameters")
|
||||
{
|
||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.name(), "open-connections"sv);
|
||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"protocol"s});
|
||||
CHECK_EQ(family.helptext(), "test"sv);
|
||||
CHECK_EQ(family.unit(), "1"sv);
|
||||
CHECK_EQ(family.isSum(), false);
|
||||
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.Name(), "open-connections"sv);
|
||||
CHECK_EQ(toVector(family.LabelNames()), std::vector{"protocol"s});
|
||||
CHECK_EQ(family.Helptext(), "test"sv);
|
||||
CHECK_EQ(family.Unit(), "1"sv);
|
||||
CHECK_EQ(family.IsSum(), false);
|
||||
}
|
||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"protocol", "tcp"}});
|
||||
auto second = family.getOrAdd({{"protocol", "tcp"}});
|
||||
auto first = family.GetOrAdd({{"protocol", "tcp"}});
|
||||
auto second = family.GetOrAdd({{"protocol", "tcp"}});
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"protocol", "tcp"}});
|
||||
auto second = family.getOrAdd({{"protocol", "quic"}});
|
||||
auto first = family.GetOrAdd({{"protocol", "tcp"}});
|
||||
auto second = family.GetOrAdd({{"protocol", "quic"}});
|
||||
CHECK_NE(first, second);
|
||||
}
|
||||
}
|
||||
WHEN("retrieving a DblGauge family")
|
||||
{
|
||||
auto family = mgr.gaugeFamily<double>("zeek", "water-level", {"river"}, "test", "meters");
|
||||
auto family = mgr.GaugeFamily<double>("zeek", "water-level", {"river"}, "test", "meters");
|
||||
THEN("the family object stores the parameters")
|
||||
{
|
||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.name(), "water-level"sv);
|
||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"river"s});
|
||||
CHECK_EQ(family.helptext(), "test"sv);
|
||||
CHECK_EQ(family.unit(), "meters"sv);
|
||||
CHECK_EQ(family.isSum(), false);
|
||||
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||
CHECK_EQ(family.Name(), "water-level"sv);
|
||||
CHECK_EQ(toVector(family.LabelNames()), std::vector{"river"s});
|
||||
CHECK_EQ(family.Helptext(), "test"sv);
|
||||
CHECK_EQ(family.Unit(), "meters"sv);
|
||||
CHECK_EQ(family.IsSum(), false);
|
||||
}
|
||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"river", "Sacramento"}});
|
||||
auto second = family.getOrAdd({{"river", "Sacramento"}});
|
||||
auto first = family.GetOrAdd({{"river", "Sacramento"}});
|
||||
auto second = family.GetOrAdd({{"river", "Sacramento"}});
|
||||
CHECK_EQ(first, second);
|
||||
}
|
||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||
{
|
||||
auto first = family.getOrAdd({{"query", "Sacramento"}});
|
||||
auto second = family.getOrAdd({{"query", "San Joaquin"}});
|
||||
auto first = family.GetOrAdd({{"query", "Sacramento"}});
|
||||
auto second = family.GetOrAdd({{"query", "San Joaquin"}});
|
||||
CHECK_NE(first, second);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue