Merge remote-tracking branch 'origin/topic/awelzel/2262-telemetry-ditch-singleton-metrics'

* origin/topic/awelzel/2262-telemetry-ditch-singleton-metrics:
  telemetry: Remove singleton BIFs and the C++ pieces
This commit is contained in:
Robin Sommer 2022-08-11 11:54:52 +02:00
commit 9de2eceb2a
No known key found for this signature in database
GPG key ID: 6BEDA4DA6B8B23E3
7 changed files with 16 additions and 357 deletions

View file

@ -513,60 +513,6 @@ template <class T> auto toVector(zeek::Span<T> xs)
} // namespace
SCENARIO("telemetry managers provide access to counter singletons")
{
GIVEN("a telemetry manager")
{
Manager mgr;
WHEN("retrieving an IntCounter singleton")
{
auto first = mgr.CounterSingleton("zeek", "int-count", "test");
THEN("its initial value is zero") { CHECK_EQ(first.Value(), 0); }
AND_THEN("calling Inc() or operator++ changes the value")
{
first.Inc();
CHECK_EQ(first.Value(), 1);
first.Inc(2);
CHECK_EQ(first.Value(), 3);
CHECK_EQ(++first, 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");
CHECK_EQ(first, second);
}
AND_THEN("calling counterSingleton for a different name returns another handle")
{
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");
THEN("its initial value is zero") { CHECK_EQ(first.Value(), 0.0); }
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);
}
AND_THEN("calling counterSingleton again for the same name returns the same handle")
{
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");
CHECK_NE(first, third);
}
}
}
}
SCENARIO("telemetry managers provide access to counter families")
{
GIVEN("a telemetry manager")
@ -626,70 +572,6 @@ SCENARIO("telemetry managers provide access to counter families")
}
}
SCENARIO("telemetry managers provide access to gauge singletons")
{
GIVEN("a telemetry manager")
{
Manager mgr;
WHEN("retrieving an IntGauge singleton")
{
auto first = mgr.GaugeSingleton("zeek", "int-gauge", "test");
THEN("its initial value is zero") { CHECK_EQ(first.Value(), 0); }
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);
CHECK_EQ(++first, 3);
CHECK_EQ(first.Value(), 3);
CHECK_EQ(--first, 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");
CHECK_EQ(first, second);
}
AND_THEN("calling gaugeSingleton for a different name returns another handle")
{
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");
THEN("its initial value is zero") { CHECK_EQ(first.Value(), 0.0); }
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);
}
AND_THEN("calling gaugeSingleton again for the same name returns the same handle")
{
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");
CHECK_NE(first, third);
}
}
}
}
SCENARIO("telemetry managers provide access to gauge families")
{
GIVEN("a telemetry manager")
@ -749,92 +631,6 @@ SCENARIO("telemetry managers provide access to gauge families")
}
}
SCENARIO("telemetry managers provide access to histogram singletons")
{
GIVEN("a telemetry manager")
{
Manager mgr;
WHEN("retrieving an IntHistogram singleton")
{
const auto max_int = std::numeric_limits<int64_t>::max();
int64_t buckets[] = {10, 20};
auto first = mgr.HistogramSingleton("zeek", "int-hist", buckets, "test");
THEN("it initially has no observations")
{
REQUIRE_EQ(first.NumBuckets(), 3u);
CHECK_EQ(first.Sum(), 0);
CHECK_EQ(first.CountAt(0), 0);
CHECK_EQ(first.CountAt(1), 0);
CHECK_EQ(first.CountAt(2), 0);
CHECK_EQ(first.UpperBoundAt(0), 10);
CHECK_EQ(first.UpperBoundAt(1), 20);
CHECK_EQ(first.UpperBoundAt(2), max_int);
}
AND_THEN("calling Observe() increments bucket counters")
{
first.Observe(1);
first.Observe(9);
first.Observe(10);
first.Observe(11);
first.Observe(19);
first.Observe(20);
first.Observe(21);
CHECK_EQ(first.Sum(), 91);
CHECK_EQ(first.CountAt(0), 3);
CHECK_EQ(first.CountAt(1), 3);
CHECK_EQ(first.CountAt(2), 1);
}
AND_THEN("calling HistogramSingleton again for the same name returns the same handle")
{
auto second = mgr.HistogramSingleton("zeek", "int-hist", buckets, "test");
CHECK_EQ(first, second);
}
AND_THEN("calling HistogramSingleton for a different name returns another handle")
{
auto third = mgr.HistogramSingleton("zeek", "int-hist-2", buckets, "test");
CHECK_NE(first, third);
}
}
WHEN("retrieving a DblHistogram singleton")
{
double buckets[] = {10.0, 20.0};
auto first = mgr.HistogramSingleton<double>("zeek", "dbl-count", buckets, "test");
THEN("it initially has no observations")
{
REQUIRE_EQ(first.NumBuckets(), 3u);
CHECK_EQ(first.Sum(), 0.0);
CHECK_EQ(first.CountAt(0), 0);
CHECK_EQ(first.CountAt(1), 0);
CHECK_EQ(first.CountAt(2), 0);
CHECK_EQ(first.UpperBoundAt(0), 10.0);
CHECK_EQ(first.UpperBoundAt(1), 20.0);
}
AND_THEN("calling Observe() increments bucket counters")
{
first.Observe(2.0);
first.Observe(4.0);
first.Observe(8.0);
first.Observe(16.0);
first.Observe(32.0);
CHECK_EQ(first.Sum(), 62.0);
CHECK_EQ(first.CountAt(0), 3);
CHECK_EQ(first.CountAt(1), 1);
CHECK_EQ(first.CountAt(2), 1);
}
AND_THEN("calling histogramSingleton again for the same name returns the same handle")
{
auto second = mgr.HistogramSingleton<double>("zeek", "dbl-count", buckets, "test");
CHECK_EQ(first, second);
}
AND_THEN("calling histogramSingleton for a different name returns another handle")
{
auto third = mgr.HistogramSingleton<double>("zeek", "dbl-count-2", buckets, "test");
CHECK_NE(first, third);
}
}
}
}
SCENARIO("telemetry managers provide access to histogram families")
{
GIVEN("a telemetry manager")