mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
|
@ -12,18 +12,18 @@
|
|||
#include "zeek/telemetry/Gauge.h"
|
||||
#include "zeek/telemetry/Histogram.h"
|
||||
|
||||
namespace zeek::telemetry {
|
||||
namespace zeek::telemetry
|
||||
{
|
||||
|
||||
/**
|
||||
* Manages a collection of metric families.
|
||||
*/
|
||||
class Manager {
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
class Impl;
|
||||
|
||||
explicit Manager(Impl* ptr) : pimpl(ptr)
|
||||
{
|
||||
}
|
||||
explicit Manager(Impl* ptr) : pimpl(ptr) { }
|
||||
|
||||
Manager(const Manager&) = delete;
|
||||
|
||||
|
@ -49,10 +49,10 @@ public:
|
|||
*/
|
||||
template <class ValueType = int64_t>
|
||||
auto CounterFamily(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false) {
|
||||
if constexpr (std::is_same<ValueType, int64_t>::value)
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
if constexpr ( std::is_same<ValueType, int64_t>::value )
|
||||
{
|
||||
return IntCounterFam(prefix, name, labels, helptext, unit, is_sum);
|
||||
}
|
||||
|
@ -62,19 +62,17 @@ public:
|
|||
"metrics only support int64_t and double values");
|
||||
return DblCounterFam(prefix, name, labels, helptext, unit, is_sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @copydoc CounterFamily
|
||||
template <class ValueType = int64_t>
|
||||
auto CounterFamily(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
std::initializer_list<std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return CounterFamily<ValueType>(prefix, name, lbl_span, helptext,
|
||||
unit, is_sum);
|
||||
}
|
||||
return CounterFamily<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses a counter instance. Creates the hosting metric family as well
|
||||
|
@ -88,26 +86,25 @@ public:
|
|||
* only the total value is of interest.
|
||||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Counter<ValueType>
|
||||
CounterInstance(std::string_view prefix, std::string_view name,
|
||||
Span<const LabelView> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
Counter<ValueType> CounterInstance(std::string_view prefix, std::string_view name,
|
||||
Span<const LabelView> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
return WithLabelNames(labels, [&, this](auto labelNames)
|
||||
{
|
||||
auto family = CounterFamily<ValueType>(prefix, name, labelNames,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
return WithLabelNames(labels,
|
||||
[&, this](auto labelNames)
|
||||
{
|
||||
auto family = CounterFamily<ValueType>(prefix, name, labelNames,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
}
|
||||
|
||||
/// @copydoc counterInstance
|
||||
template <class ValueType = int64_t>
|
||||
Counter<ValueType>
|
||||
CounterInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Counter<ValueType> CounterInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return CounterInstance(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||
|
@ -125,16 +122,14 @@ public:
|
|||
* only the total value is of interest.
|
||||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Counter<ValueType>
|
||||
CounterSingleton(std::string_view prefix, std::string_view name,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Counter<ValueType> CounterSingleton(std::string_view prefix, std::string_view name,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto labels = Span<const std::string_view>{};
|
||||
auto fam = CounterFamily<ValueType>(prefix, name, labels, helptext,
|
||||
unit, is_sum);
|
||||
auto fam = CounterFamily<ValueType>(prefix, name, labels, helptext, unit, is_sum);
|
||||
return fam.GetOrAdd({});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A gauge metric family. Creates the family lazily if necessary.
|
||||
|
@ -148,11 +143,10 @@ public:
|
|||
*/
|
||||
template <class ValueType = int64_t>
|
||||
auto GaugeFamily(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext,
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
if constexpr (std::is_same<ValueType, int64_t>::value)
|
||||
if constexpr ( std::is_same<ValueType, int64_t>::value )
|
||||
{
|
||||
return IntGaugeFam(prefix, name, labels, helptext, unit, is_sum);
|
||||
}
|
||||
|
@ -167,13 +161,11 @@ public:
|
|||
/// @copydoc GaugeFamily
|
||||
template <class ValueType = int64_t>
|
||||
auto GaugeFamily(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
std::initializer_list<std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return GaugeFamily<ValueType>(prefix, name, lbl_span, helptext,
|
||||
unit, is_sum);
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return GaugeFamily<ValueType>(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,26 +180,25 @@ public:
|
|||
* only the total value is of interest.
|
||||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Gauge<ValueType>
|
||||
GaugeInstance(std::string_view prefix, std::string_view name,
|
||||
Span<const LabelView> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
Gauge<ValueType> GaugeInstance(std::string_view prefix, std::string_view name,
|
||||
Span<const LabelView> labels, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
return WithLabelNames(labels, [&, this](auto labelNames)
|
||||
{
|
||||
auto family = GaugeFamily<ValueType>(prefix, name, labelNames,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
return WithLabelNames(labels,
|
||||
[&, this](auto labelNames)
|
||||
{
|
||||
auto family = GaugeFamily<ValueType>(prefix, name, labelNames,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
}
|
||||
|
||||
/// @copydoc GaugeInstance
|
||||
template <class ValueType = int64_t>
|
||||
Gauge<ValueType>
|
||||
GaugeInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Gauge<ValueType> GaugeInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return GaugeInstance(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||
|
@ -225,28 +216,24 @@ public:
|
|||
* only the total value is of interest.
|
||||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Gauge<ValueType>
|
||||
GaugeSingleton(std::string_view prefix, std::string_view name,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Gauge<ValueType> GaugeSingleton(std::string_view prefix, std::string_view name,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto labels = Span<const std::string_view>{};
|
||||
auto fam = GaugeFamily<ValueType>(prefix, name, labels, helptext,
|
||||
unit, is_sum);
|
||||
auto fam = GaugeFamily<ValueType>(prefix, name, labels, helptext, unit, is_sum);
|
||||
return fam.GetOrAdd({});
|
||||
}
|
||||
}
|
||||
|
||||
// Forces the compiler to use the type `Span<const T>` instead of trying to
|
||||
// match paremeters to a `span`.
|
||||
template <class T>
|
||||
struct ConstSpanOracle
|
||||
{
|
||||
using Type = Span<const T>;
|
||||
};
|
||||
template <class T> struct ConstSpanOracle
|
||||
{
|
||||
using Type = Span<const T>;
|
||||
};
|
||||
|
||||
// Convenience alias to safe some typing.
|
||||
template <class T>
|
||||
using ConstSpan = typename ConstSpanOracle<T>::Type;
|
||||
template <class T> using ConstSpan = typename ConstSpanOracle<T>::Type;
|
||||
|
||||
/**
|
||||
* Returns a histogram metric family. Creates the family lazily if
|
||||
|
@ -272,21 +259,18 @@ public:
|
|||
template <class ValueType = int64_t>
|
||||
auto HistogramFamily(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
ConstSpan<ValueType> default_upper_bounds, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
if constexpr (std::is_same<ValueType, int64_t>::value)
|
||||
if constexpr ( std::is_same<ValueType, int64_t>::value )
|
||||
{
|
||||
return IntHistoFam(prefix, name, labels, default_upper_bounds,
|
||||
helptext, unit, is_sum);
|
||||
return IntHistoFam(prefix, name, labels, default_upper_bounds, helptext, unit, is_sum);
|
||||
}
|
||||
else
|
||||
{
|
||||
static_assert(std::is_same<ValueType, double>::value,
|
||||
"metrics only support int64_t and double values");
|
||||
return DblHistoFam(prefix, name, labels, default_upper_bounds,
|
||||
helptext, unit, is_sum);
|
||||
return DblHistoFam(prefix, name, labels, default_upper_bounds, helptext, unit, is_sum);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,13 +278,11 @@ public:
|
|||
template <class ValueType = int64_t>
|
||||
auto HistogramFamily(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<std::string_view> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
ConstSpan<ValueType> default_upper_bounds, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||
return HistogramFamily<ValueType>(prefix, name, lbl_span,
|
||||
default_upper_bounds, helptext,
|
||||
return HistogramFamily<ValueType>(prefix, name, lbl_span, default_upper_bounds, helptext,
|
||||
unit, is_sum);
|
||||
}
|
||||
|
||||
|
@ -326,33 +308,30 @@ public:
|
|||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Histogram<ValueType>
|
||||
HistogramInstance(std::string_view prefix, std::string_view name,
|
||||
Span<const LabelView> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
HistogramInstance(std::string_view prefix, std::string_view name, Span<const LabelView> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds, std::string_view helptext,
|
||||
std::string_view unit = "1", bool is_sum = false)
|
||||
{
|
||||
return WithLabelNames(labels, [&, this](auto labelNames)
|
||||
{
|
||||
auto family = HistogramFamily<ValueType>(prefix, name, labelNames,
|
||||
default_upper_bounds,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
return WithLabelNames(labels,
|
||||
[&, this](auto labelNames)
|
||||
{
|
||||
auto family = HistogramFamily<ValueType>(prefix, name, labelNames,
|
||||
default_upper_bounds,
|
||||
helptext, unit, is_sum);
|
||||
return family.getOrAdd(labels);
|
||||
});
|
||||
}
|
||||
|
||||
/// @copdoc HistogramInstance
|
||||
template <class ValueType = int64_t>
|
||||
Histogram<ValueType>
|
||||
HistogramInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Histogram<ValueType> HistogramInstance(std::string_view prefix, std::string_view name,
|
||||
std::initializer_list<LabelView> labels,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto lbls = Span{labels.begin(), labels.size()};
|
||||
return HistogramInstance(prefix, name, lbls, default_upper_bounds,
|
||||
helptext, unit, is_sum);
|
||||
return HistogramInstance(prefix, name, lbls, default_upper_bounds, helptext, unit, is_sum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -377,79 +356,68 @@ public:
|
|||
* @p default_upper_bounds via run-time configuration.
|
||||
*/
|
||||
template <class ValueType = int64_t>
|
||||
Histogram<ValueType>
|
||||
HistogramSingleton(std::string_view prefix, std::string_view name,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
Histogram<ValueType> HistogramSingleton(std::string_view prefix, std::string_view name,
|
||||
ConstSpan<ValueType> default_upper_bounds,
|
||||
std::string_view helptext, std::string_view unit = "1",
|
||||
bool is_sum = false)
|
||||
{
|
||||
auto lbls = Span<const std::string_view>{};
|
||||
auto fam = HistogramFamily<ValueType>(prefix, name, lbls,
|
||||
default_upper_bounds, helptext,
|
||||
auto fam = HistogramFamily<ValueType>(prefix, name, lbls, default_upper_bounds, helptext,
|
||||
unit, is_sum);
|
||||
return fam.GetOrAdd({});
|
||||
}
|
||||
|
||||
protected:
|
||||
IntCounterFamily
|
||||
IntCounterFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit,
|
||||
bool is_sum);
|
||||
IntCounterFamily IntCounterFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
|
||||
DblCounterFamily
|
||||
DblCounterFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit,
|
||||
bool is_sum);
|
||||
DblCounterFamily DblCounterFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
|
||||
IntGaugeFamily
|
||||
IntGaugeFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit,
|
||||
bool is_sum);
|
||||
IntGaugeFamily IntGaugeFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
|
||||
DblGaugeFamily
|
||||
DblGaugeFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
std::string_view helptext, std::string_view unit,
|
||||
bool is_sum);
|
||||
DblGaugeFamily DblGaugeFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
|
||||
IntHistogramFamily
|
||||
IntHistoFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
Span<const int64_t> ubounds, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
IntHistogramFamily IntHistoFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, Span<const int64_t> ubounds,
|
||||
std::string_view helptext, std::string_view unit, bool is_sum);
|
||||
|
||||
DblHistogramFamily
|
||||
DblHistoFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels,
|
||||
Span<const double> ubounds, std::string_view helptext,
|
||||
std::string_view unit, bool is_sum);
|
||||
DblHistogramFamily DblHistoFam(std::string_view prefix, std::string_view name,
|
||||
Span<const std::string_view> labels, Span<const double> ubounds,
|
||||
std::string_view helptext, std::string_view unit, bool is_sum);
|
||||
|
||||
template <class F>
|
||||
static void WithLabelNames(Span<const LabelView> xs, F continuation)
|
||||
template <class F> static void WithLabelNames(Span<const LabelView> xs, F continuation)
|
||||
{
|
||||
if ( xs.size() <= 10 ) {
|
||||
if ( xs.size() <= 10 )
|
||||
{
|
||||
std::string_view buf[10];
|
||||
for ( size_t index = 0; index < xs.size(); ++index )
|
||||
buf[index] = xs[index].first;
|
||||
return continuation(Span{buf, xs.size()});
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string_view> buf;
|
||||
for ( auto x : xs )
|
||||
buf.emplace_back(x.first, x.second);
|
||||
return continuation(Span{buf});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Impl* pimpl;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace zeek::telemetry
|
||||
} // namespace zeek::telemetry
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
extern telemetry::Manager* telemetry_mgr;
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue