mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +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
52
src/Span.h
52
src/Span.h
|
@ -45,46 +45,40 @@ public:
|
||||||
|
|
||||||
// -- constructors, destructors, and assignment operators ------------------
|
// -- constructors, destructors, and assignment operators ------------------
|
||||||
|
|
||||||
constexpr Span() noexcept : memoryBlock(nullptr), numElements(0)
|
constexpr Span() noexcept : memory_block(nullptr), num_elements(0)
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span(pointer ptr, size_t size)
|
constexpr Span(pointer ptr, size_t size)
|
||||||
: memoryBlock(ptr), numElements(size)
|
: memory_block(ptr), num_elements(size)
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span(pointer first, pointer last)
|
constexpr Span(pointer first, pointer last)
|
||||||
: memoryBlock(first), numElements(static_cast<size_t>(last - first))
|
: memory_block(first), num_elements(static_cast<size_t>(last - first))
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t Size>
|
template <size_t Size>
|
||||||
constexpr Span(element_type (&arr)[Size]) noexcept
|
constexpr Span(element_type (&arr)[Size]) noexcept
|
||||||
: memoryBlock(arr), numElements(Size)
|
: memory_block(arr), num_elements(Size)
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Container,
|
template <class Container,
|
||||||
class Data = typename Container::value_type,
|
class Data = typename Container::value_type,
|
||||||
class = std::enable_if_t<std::is_convertible_v<Data*, T*>>>
|
class = std::enable_if_t<std::is_convertible_v<Data*, T*>>>
|
||||||
Span(Container& xs) noexcept
|
Span(Container& xs) noexcept
|
||||||
: memoryBlock(xs.data()), numElements(xs.size())
|
: memory_block(xs.data()), num_elements(xs.size())
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Container,
|
template <class Container,
|
||||||
class Data = typename Container::value_type,
|
class Data = typename Container::value_type,
|
||||||
class = std::enable_if_t<std::is_convertible_v<const Data*, T*>>>
|
class = std::enable_if_t<std::is_convertible_v<const Data*, T*>>>
|
||||||
Span(const Container& xs) noexcept
|
Span(const Container& xs) noexcept
|
||||||
: memoryBlock(xs.data()), numElements(xs.size())
|
: memory_block(xs.data()), num_elements(xs.size())
|
||||||
{
|
{
|
||||||
// nop
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span(const Span&) noexcept = default;
|
constexpr Span(const Span&) noexcept = default;
|
||||||
|
@ -95,22 +89,22 @@ public:
|
||||||
|
|
||||||
constexpr iterator begin() const noexcept
|
constexpr iterator begin() const noexcept
|
||||||
{
|
{
|
||||||
return memoryBlock;
|
return memory_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const_iterator cbegin() const noexcept
|
constexpr const_iterator cbegin() const noexcept
|
||||||
{
|
{
|
||||||
return memoryBlock;
|
return memory_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr iterator end() const noexcept
|
constexpr iterator end() const noexcept
|
||||||
{
|
{
|
||||||
return begin() + numElements;
|
return begin() + num_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const_iterator cend() const noexcept
|
constexpr const_iterator cend() const noexcept
|
||||||
{
|
{
|
||||||
return cbegin() + numElements;
|
return cbegin() + num_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr reverse_iterator rbegin() const noexcept
|
constexpr reverse_iterator rbegin() const noexcept
|
||||||
|
@ -137,71 +131,71 @@ public:
|
||||||
|
|
||||||
constexpr reference operator[](size_t index) const noexcept
|
constexpr reference operator[](size_t index) const noexcept
|
||||||
{
|
{
|
||||||
return memoryBlock[index];
|
return memory_block[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr reference front() const noexcept
|
constexpr reference front() const noexcept
|
||||||
{
|
{
|
||||||
return *memoryBlock;
|
return *memory_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr reference back() const noexcept
|
constexpr reference back() const noexcept
|
||||||
{
|
{
|
||||||
return (*this)[numElements - 1];
|
return (*this)[num_elements - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- properties -----------------------------------------------------------
|
// -- properties -----------------------------------------------------------
|
||||||
|
|
||||||
constexpr size_t size() const noexcept
|
constexpr size_t size() const noexcept
|
||||||
{
|
{
|
||||||
return numElements;
|
return num_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t size_bytes() const noexcept
|
constexpr size_t size_bytes() const noexcept
|
||||||
{
|
{
|
||||||
return numElements * sizeof(element_type);
|
return num_elements * sizeof(element_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool empty() const noexcept
|
constexpr bool empty() const noexcept
|
||||||
{
|
{
|
||||||
return numElements == 0;
|
return num_elements == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr pointer data() const noexcept
|
constexpr pointer data() const noexcept
|
||||||
{
|
{
|
||||||
return memoryBlock;
|
return memory_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- subviews -------------------------------------------------------------
|
// -- subviews -------------------------------------------------------------
|
||||||
|
|
||||||
constexpr Span subspan(size_t offset, size_t num_elements) const
|
constexpr Span subspan(size_t offset, size_t num_elements) const
|
||||||
{
|
{
|
||||||
return {memoryBlock + offset, num_elements};
|
return {memory_block + offset, num_elements};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span subspan(size_t offset) const
|
constexpr Span subspan(size_t offset) const
|
||||||
{
|
{
|
||||||
return {memoryBlock + offset, numElements - offset};
|
return {memory_block + offset, num_elements - offset};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span first(size_t num_elements) const
|
constexpr Span first(size_t num_elements) const
|
||||||
{
|
{
|
||||||
return {memoryBlock, num_elements};
|
return {memory_block, num_elements};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Span last(size_t num_elements) const
|
constexpr Span last(size_t num_elements) const
|
||||||
{
|
{
|
||||||
return subspan(numElements - num_elements, num_elements);
|
return subspan(num_elements - num_elements, num_elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// -- member variables -----------------------------------------------------
|
// -- member variables -----------------------------------------------------
|
||||||
|
|
||||||
/// Points to the first element in the contiguous memory block.
|
/// Points to the first element in the contiguous memory block.
|
||||||
pointer memoryBlock;
|
pointer memory_block;
|
||||||
|
|
||||||
/// Stores the number of elements in the contiguous memory block.
|
/// Stores the number of elements in the contiguous memory block.
|
||||||
size_t numElements;
|
size_t num_elements;
|
||||||
};
|
};
|
||||||
|
|
||||||
// -- deduction guides ---------------------------------------------------------
|
// -- deduction guides ---------------------------------------------------------
|
||||||
|
|
|
@ -96,12 +96,12 @@ auto withNativeLabels(Span<const LabelView> xs, F continuation)
|
||||||
|
|
||||||
// -- IntCounter ---------------------------------------------------------------
|
// -- IntCounter ---------------------------------------------------------------
|
||||||
|
|
||||||
void IntCounter::inc() noexcept
|
void IntCounter::Inc() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc();
|
deref(pimpl).inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntCounter::inc(int64_t amount) noexcept
|
void IntCounter::Inc(int64_t amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc(amount);
|
deref(pimpl).inc(amount);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ int64_t IntCounter::operator++() noexcept
|
||||||
return ++deref(pimpl);
|
return ++deref(pimpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t IntCounter::value() const noexcept
|
int64_t IntCounter::Value() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).value();
|
return deref(pimpl).value();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ IntCounterFamily::IntCounterFamily(Impl* ptr) : MetricFamily(upcast(ptr))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IntCounter IntCounterFamily::getOrAdd(Span<const LabelView> labels)
|
IntCounter IntCounterFamily::GetOrAdd(Span<const LabelView> labels)
|
||||||
{
|
{
|
||||||
return withNativeLabels(labels, [this](auto nativeLabels)
|
return withNativeLabels(labels, [this](auto nativeLabels)
|
||||||
{
|
{
|
||||||
|
@ -131,17 +131,17 @@ IntCounter IntCounterFamily::getOrAdd(Span<const LabelView> labels)
|
||||||
|
|
||||||
// -- DblCounter ---------------------------------------------------------------
|
// -- DblCounter ---------------------------------------------------------------
|
||||||
|
|
||||||
void DblCounter::inc() noexcept
|
void DblCounter::Inc() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc();
|
deref(pimpl).inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DblCounter::inc(double amount) noexcept
|
void DblCounter::Inc(double amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc(amount);
|
deref(pimpl).inc(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
double DblCounter::value() const noexcept
|
double DblCounter::Value() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).value();
|
return deref(pimpl).value();
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ DblCounterFamily::DblCounterFamily(Impl* ptr) : MetricFamily(upcast(ptr))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DblCounter DblCounterFamily::getOrAdd(Span<const LabelView> labels)
|
DblCounter DblCounterFamily::GetOrAdd(Span<const LabelView> labels)
|
||||||
{
|
{
|
||||||
return withNativeLabels(labels, [this](auto nativeLabels)
|
return withNativeLabels(labels, [this](auto nativeLabels)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,29 +31,29 @@ public:
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
void inc() noexcept;
|
void Inc() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
* @pre `amount >= 0`
|
* @pre `amount >= 0`
|
||||||
*/
|
*/
|
||||||
void inc(int64_t amount) noexcept;
|
void Inc(int64_t amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
* @returns the new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
int64_t operator++() noexcept;
|
int64_t operator++() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
int64_t value() const noexcept;
|
int64_t Value() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether @c this and @p other refer to the same counter.
|
* @return Whether @c this and @p other refer to the same counter.
|
||||||
*/
|
*/
|
||||||
constexpr bool isSameAs(IntCounter other) const noexcept
|
constexpr bool IsSameAs(IntCounter other) const noexcept
|
||||||
{
|
{
|
||||||
return pimpl == other.pimpl;
|
return pimpl == other.pimpl;
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether two @ref IntCounter handles are identical.
|
* Checks whether two @ref IntCounter handles are identical.
|
||||||
* @returns whether @p lhs and @p rhs refer to the same object.
|
* @return Whether @p lhs and @p rhs refer to the same object.
|
||||||
* @note compare their @c value instead to check for equality.
|
* @note compare their @c value instead to check for equality.
|
||||||
*/
|
*/
|
||||||
constexpr bool operator==(IntCounter lhs, IntCounter rhs) noexcept
|
constexpr bool operator==(IntCounter lhs, IntCounter rhs) noexcept
|
||||||
{
|
{
|
||||||
return lhs.isSameAs(rhs);
|
return lhs.IsSameAs(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @relates IntCounter
|
/// @relates IntCounter
|
||||||
|
@ -98,14 +98,14 @@ public:
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
IntCounter getOrAdd(Span<const LabelView> labels);
|
IntCounter GetOrAdd(Span<const LabelView> labels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc getOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
IntCounter getOrAdd(std::initializer_list<LabelView> labels)
|
IntCounter GetOrAdd(std::initializer_list<LabelView> labels)
|
||||||
{
|
{
|
||||||
return getOrAdd(Span{labels.begin(), labels.size()});
|
return GetOrAdd(Span{labels.begin(), labels.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -129,23 +129,23 @@ public:
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
void inc() noexcept;
|
void Inc() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
* @pre `amount >= 0`
|
* @pre `amount >= 0`
|
||||||
*/
|
*/
|
||||||
void inc(double amount) noexcept;
|
void Inc(double amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
double value() const noexcept;
|
double Value() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether @c this and @p other refer to the same counter.
|
* @return Whether @c this and @p other refer to the same counter.
|
||||||
*/
|
*/
|
||||||
constexpr bool isSameAs(DblCounter other) const noexcept
|
constexpr bool IsSameAs(DblCounter other) const noexcept
|
||||||
{
|
{
|
||||||
return pimpl == other.pimpl;
|
return pimpl == other.pimpl;
|
||||||
}
|
}
|
||||||
|
@ -160,12 +160,12 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether two @ref DblCounter handles are identical.
|
* Checks whether two @ref DblCounter handles are identical.
|
||||||
* @returns whether @p lhs and @p rhs refer to the same object.
|
* @return Whether @p lhs and @p rhs refer to the same object.
|
||||||
* @note compare their @c value instead to check for equality.
|
* @note compare their @c value instead to check for equality.
|
||||||
*/
|
*/
|
||||||
constexpr bool operator==(DblCounter lhs, DblCounter rhs) noexcept
|
constexpr bool operator==(DblCounter lhs, DblCounter rhs) noexcept
|
||||||
{
|
{
|
||||||
return lhs.isSameAs(rhs);
|
return lhs.IsSameAs(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @relates DblCounter
|
/// @relates DblCounter
|
||||||
|
@ -190,14 +190,14 @@ public:
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
DblCounter getOrAdd(Span<const LabelView> labels);
|
DblCounter GetOrAdd(Span<const LabelView> labels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc getOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
DblCounter getOrAdd(std::initializer_list<LabelView> labels)
|
DblCounter GetOrAdd(std::initializer_list<LabelView> labels)
|
||||||
{
|
{
|
||||||
return getOrAdd(Span{labels.begin(), labels.size()});
|
return GetOrAdd(Span{labels.begin(), labels.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -212,15 +212,11 @@ struct CounterOracle {
|
||||||
"Counter<T> only supports int64_t and double");
|
"Counter<T> only supports int64_t and double");
|
||||||
|
|
||||||
using type = IntCounter;
|
using type = IntCounter;
|
||||||
|
|
||||||
using family_type = IntCounterFamily;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct CounterOracle<double> {
|
struct CounterOracle<double> {
|
||||||
using type = DblCounter;
|
using type = DblCounter;
|
||||||
|
|
||||||
using family_type = DblCounterFamily;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -228,7 +224,4 @@ struct CounterOracle<double> {
|
||||||
template <class T>
|
template <class T>
|
||||||
using Counter = typename detail::CounterOracle<T>::type;
|
using Counter = typename detail::CounterOracle<T>::type;
|
||||||
|
|
||||||
template <class T>
|
|
||||||
using CounterFamily = typename detail::CounterOracle<T>::family_type;
|
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
|
@ -96,22 +96,22 @@ auto withNativeLabels(Span<const LabelView> xs, F continuation)
|
||||||
|
|
||||||
// -- IntGauge ---------------------------------------------------------------
|
// -- IntGauge ---------------------------------------------------------------
|
||||||
|
|
||||||
void IntGauge::inc() noexcept
|
void IntGauge::Inc() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc();
|
deref(pimpl).inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntGauge::inc(int64_t amount) noexcept
|
void IntGauge::Inc(int64_t amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc(amount);
|
deref(pimpl).inc(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntGauge::dec() noexcept
|
void IntGauge::Dec() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).dec();
|
deref(pimpl).dec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntGauge::dec(int64_t amount) noexcept
|
void IntGauge::Dec(int64_t amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).dec(amount);
|
deref(pimpl).dec(amount);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ int64_t IntGauge::operator--() noexcept
|
||||||
return --deref(pimpl);
|
return --deref(pimpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t IntGauge::value() const noexcept
|
int64_t IntGauge::Value() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).value();
|
return deref(pimpl).value();
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ IntGaugeFamily::IntGaugeFamily(Impl* ptr) : MetricFamily(upcast(ptr))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IntGauge IntGaugeFamily::getOrAdd(Span<const LabelView> labels)
|
IntGauge IntGaugeFamily::GetOrAdd(Span<const LabelView> labels)
|
||||||
{
|
{
|
||||||
return withNativeLabels(labels, [this](auto nativeLabels)
|
return withNativeLabels(labels, [this](auto nativeLabels)
|
||||||
{
|
{
|
||||||
|
@ -146,27 +146,27 @@ IntGauge IntGaugeFamily::getOrAdd(Span<const LabelView> labels)
|
||||||
|
|
||||||
// -- DblGauge ---------------------------------------------------------------
|
// -- DblGauge ---------------------------------------------------------------
|
||||||
|
|
||||||
void DblGauge::inc() noexcept
|
void DblGauge::Inc() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc();
|
deref(pimpl).inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DblGauge::inc(double amount) noexcept
|
void DblGauge::Inc(double amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).inc(amount);
|
deref(pimpl).inc(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DblGauge::dec() noexcept
|
void DblGauge::Dec() noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).dec();
|
deref(pimpl).dec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DblGauge::dec(double amount) noexcept
|
void DblGauge::Dec(double amount) noexcept
|
||||||
{
|
{
|
||||||
deref(pimpl).dec(amount);
|
deref(pimpl).dec(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
double DblGauge::value() const noexcept
|
double DblGauge::Value() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).value();
|
return deref(pimpl).value();
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ DblGaugeFamily::DblGaugeFamily(Impl* ptr) : MetricFamily(upcast(ptr))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DblGauge DblGaugeFamily::getOrAdd(Span<const LabelView> labels)
|
DblGauge DblGaugeFamily::GetOrAdd(Span<const LabelView> labels)
|
||||||
{
|
{
|
||||||
return withNativeLabels(labels, [this](auto nativeLabels)
|
return withNativeLabels(labels, [this](auto nativeLabels)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,44 +32,44 @@ public:
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
void inc() noexcept;
|
void Inc() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void inc(int64_t amount) noexcept;
|
void Inc(int64_t amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
* @returns the new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
int64_t operator++() noexcept;
|
int64_t operator++() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the value by 1.
|
* Decrements the value by 1.
|
||||||
*/
|
*/
|
||||||
void dec() noexcept;
|
void Dec() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the value by @p amount.
|
* Decrements the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void dec(int64_t amount) noexcept;
|
void Dec(int64_t amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrements the value by 1.
|
* Decrements the value by 1.
|
||||||
* @returns the new value.
|
* @return The new value.
|
||||||
*/
|
*/
|
||||||
int64_t operator--() noexcept;
|
int64_t operator--() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
int64_t value() const noexcept;
|
int64_t Value() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether @c this and @p other refer to the same counter.
|
* @return Whether @c this and @p other refer to the same counter.
|
||||||
*/
|
*/
|
||||||
constexpr bool isSameAs(IntGauge other) const noexcept
|
constexpr bool IsSameAs(IntGauge other) const noexcept
|
||||||
{
|
{
|
||||||
return pimpl == other.pimpl;
|
return pimpl == other.pimpl;
|
||||||
}
|
}
|
||||||
|
@ -84,12 +84,12 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether two @ref IntGauge handles are identical.
|
* Checks whether two @ref IntGauge handles are identical.
|
||||||
* @returns whether @p lhs and @p rhs refer to the same object.
|
* @return Whether @p lhs and @p rhs refer to the same object.
|
||||||
* @note compare their @c value instead to check for equality.
|
* @note compare their @c value instead to check for equality.
|
||||||
*/
|
*/
|
||||||
constexpr bool operator==(IntGauge lhs, IntGauge rhs) noexcept
|
constexpr bool operator==(IntGauge lhs, IntGauge rhs) noexcept
|
||||||
{
|
{
|
||||||
return lhs.isSameAs(rhs);
|
return lhs.IsSameAs(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @relates IntGauge
|
/// @relates IntGauge
|
||||||
|
@ -114,14 +114,14 @@ public:
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
IntGauge getOrAdd(Span<const LabelView> labels);
|
IntGauge GetOrAdd(Span<const LabelView> labels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc getOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
IntGauge getOrAdd(std::initializer_list<LabelView> labels)
|
IntGauge GetOrAdd(std::initializer_list<LabelView> labels)
|
||||||
{
|
{
|
||||||
return getOrAdd(Span{labels.begin(), labels.size()});
|
return GetOrAdd(Span{labels.begin(), labels.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -146,32 +146,32 @@ public:
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
void inc() noexcept;
|
void Inc() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void inc(double amount) noexcept;
|
void Inc(double amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by 1.
|
* Increments the value by 1.
|
||||||
*/
|
*/
|
||||||
void dec() noexcept;
|
void Dec() noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the value by @p amount.
|
* Increments the value by @p amount.
|
||||||
*/
|
*/
|
||||||
void dec(double amount) noexcept;
|
void Dec(double amount) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the current value.
|
* @return The current value.
|
||||||
*/
|
*/
|
||||||
double value() const noexcept;
|
double Value() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether @c this and @p other refer to the same counter.
|
* @return Whether @c this and @p other refer to the same counter.
|
||||||
*/
|
*/
|
||||||
constexpr bool isSameAs(DblGauge other) const noexcept
|
constexpr bool IsSameAs(DblGauge other) const noexcept
|
||||||
{
|
{
|
||||||
return pimpl == other.pimpl;
|
return pimpl == other.pimpl;
|
||||||
}
|
}
|
||||||
|
@ -186,12 +186,12 @@ private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether two @ref DblGauge handles are identical.
|
* Checks whether two @ref DblGauge handles are identical.
|
||||||
* @returns whether @p lhs and @p rhs refer to the same object.
|
* @return Whether @p lhs and @p rhs refer to the same object.
|
||||||
* @note compare their @c value instead to check for equality.
|
* @note compare their @c value instead to check for equality.
|
||||||
*/
|
*/
|
||||||
constexpr bool operator==(DblGauge lhs, DblGauge rhs) noexcept
|
constexpr bool operator==(DblGauge lhs, DblGauge rhs) noexcept
|
||||||
{
|
{
|
||||||
return lhs.isSameAs(rhs);
|
return lhs.IsSameAs(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @relates DblGauge
|
/// @relates DblGauge
|
||||||
|
@ -216,14 +216,14 @@ public:
|
||||||
* Returns the metrics handle for given labels, creating a new instance
|
* Returns the metrics handle for given labels, creating a new instance
|
||||||
* lazily if necessary.
|
* lazily if necessary.
|
||||||
*/
|
*/
|
||||||
DblGauge getOrAdd(Span<const LabelView> labels);
|
DblGauge GetOrAdd(Span<const LabelView> labels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc getOrAdd
|
* @copydoc GetOrAdd
|
||||||
*/
|
*/
|
||||||
DblGauge getOrAdd(std::initializer_list<LabelView> labels)
|
DblGauge GetOrAdd(std::initializer_list<LabelView> labels)
|
||||||
{
|
{
|
||||||
return getOrAdd(Span{labels.begin(), labels.size()});
|
return GetOrAdd(Span{labels.begin(), labels.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -238,15 +238,11 @@ struct GaugeOracle {
|
||||||
"Gauge<T> only supports int64_t and double");
|
"Gauge<T> only supports int64_t and double");
|
||||||
|
|
||||||
using type = IntGauge;
|
using type = IntGauge;
|
||||||
|
|
||||||
using family_type = IntGaugeFamily;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct GaugeOracle<double> {
|
struct GaugeOracle<double> {
|
||||||
using type = DblGauge;
|
using type = DblGauge;
|
||||||
|
|
||||||
using family_type = DblGaugeFamily;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -254,7 +250,4 @@ struct GaugeOracle<double> {
|
||||||
template <class T>
|
template <class T>
|
||||||
using Gauge = typename detail::GaugeOracle<T>::type;
|
using Gauge = typename detail::GaugeOracle<T>::type;
|
||||||
|
|
||||||
template <class T>
|
|
||||||
using GaugeFamily = typename detail::GaugeOracle<T>::family_type;
|
|
||||||
|
|
||||||
} // namespace zeek::telemetry
|
} // namespace zeek::telemetry
|
||||||
|
|
|
@ -61,7 +61,7 @@ auto opaque(NativeDblGaugeFamily* ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class F>
|
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 )
|
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,
|
std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext,
|
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,
|
auto ptr = deref(pimpl).counter_family(prefix, name, xs,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return IntCounterFamily{opaque(ptr)};
|
return IntCounterFamily{opaque(ptr)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DblCounterFamily Manager::dblCounterFam(std::string_view prefix,
|
DblCounterFamily Manager::DblCounterFam(std::string_view prefix,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext,
|
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,
|
auto ptr = deref(pimpl).counter_family<double>(prefix, name, xs,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return DblCounterFamily{opaque(ptr)};
|
return DblCounterFamily{opaque(ptr)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
IntGaugeFamily Manager::intGaugeFam(std::string_view prefix,
|
IntGaugeFamily Manager::IntGaugeFam(std::string_view prefix,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext,
|
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,
|
auto ptr = deref(pimpl).gauge_family(prefix, name, xs,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return IntGaugeFamily{opaque(ptr)};
|
return IntGaugeFamily{opaque(ptr)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DblGaugeFamily Manager::dblGaugeFam(std::string_view prefix,
|
DblGaugeFamily Manager::DblGaugeFam(std::string_view prefix,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext,
|
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,
|
auto ptr = deref(pimpl).gauge_family<double>(prefix, name, xs,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return DblGaugeFamily{opaque(ptr)};
|
return DblGaugeFamily{opaque(ptr)};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -166,57 +166,57 @@ SCENARIO("telemetry managers provide access to counter singletons")
|
||||||
{
|
{
|
||||||
GIVEN("a telemetry manager")
|
GIVEN("a telemetry manager")
|
||||||
{
|
{
|
||||||
NativeManager nativeMgr;
|
NativeManager native_mgr;
|
||||||
Manager mgr{opaque(&nativeMgr)};
|
Manager mgr{opaque(&native_mgr)};
|
||||||
WHEN("retrieving an IntCounter singleton")
|
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")
|
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();
|
first.Inc();
|
||||||
CHECK_EQ(first.value(), 1);
|
CHECK_EQ(first.Value(), 1);
|
||||||
first.inc(2);
|
first.Inc(2);
|
||||||
CHECK_EQ(first.value(), 3);
|
CHECK_EQ(first.Value(), 3);
|
||||||
CHECK_EQ(++first, 4);
|
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")
|
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);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("calling counterSingleton for a different name returns another handle")
|
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);
|
CHECK_NE(first, third);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblCounter singleton")
|
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")
|
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();
|
first.Inc();
|
||||||
CHECK_EQ(first.value(), 1.0);
|
CHECK_EQ(first.Value(), 1.0);
|
||||||
first.inc(3.0);
|
first.Inc(3.0);
|
||||||
CHECK_EQ(first.value(), 4.0);
|
CHECK_EQ(first.Value(), 4.0);
|
||||||
}
|
}
|
||||||
AND_THEN("calling counterSingleton again for the same name returns the same handle")
|
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);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("calling counterSingleton for a different name returns another handle")
|
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);
|
CHECK_NE(first, third);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,55 +227,55 @@ SCENARIO("telemetry managers provide access to counter families")
|
||||||
{
|
{
|
||||||
GIVEN("a telemetry manager")
|
GIVEN("a telemetry manager")
|
||||||
{
|
{
|
||||||
NativeManager nativeMgr;
|
NativeManager native_mgr;
|
||||||
Manager mgr{opaque(&nativeMgr)};
|
Manager mgr{opaque(&native_mgr)};
|
||||||
WHEN("retrieving an IntCounter family")
|
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")
|
THEN("the family object stores the parameters")
|
||||||
{
|
{
|
||||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||||
CHECK_EQ(family.name(), "requests"sv);
|
CHECK_EQ(family.Name(), "requests"sv);
|
||||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"method"s});
|
CHECK_EQ(toVector(family.LabelNames()), std::vector{"method"s});
|
||||||
CHECK_EQ(family.helptext(), "test"sv);
|
CHECK_EQ(family.Helptext(), "test"sv);
|
||||||
CHECK_EQ(family.unit(), "1"sv);
|
CHECK_EQ(family.Unit(), "1"sv);
|
||||||
CHECK_EQ(family.isSum(), true);
|
CHECK_EQ(family.IsSum(), true);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"method", "get"}});
|
auto first = family.GetOrAdd({{"method", "get"}});
|
||||||
auto second = family.getOrAdd({{"method", "get"}});
|
auto second = family.GetOrAdd({{"method", "get"}});
|
||||||
CHECK_EQ(first, second);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"method", "get"}});
|
auto first = family.GetOrAdd({{"method", "get"}});
|
||||||
auto second = family.getOrAdd({{"method", "put"}});
|
auto second = family.GetOrAdd({{"method", "put"}});
|
||||||
CHECK_NE(first, second);
|
CHECK_NE(first, second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblCounter family")
|
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")
|
THEN("the family object stores the parameters")
|
||||||
{
|
{
|
||||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||||
CHECK_EQ(family.name(), "runtime"sv);
|
CHECK_EQ(family.Name(), "runtime"sv);
|
||||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"query"s});
|
CHECK_EQ(toVector(family.LabelNames()), std::vector{"query"s});
|
||||||
CHECK_EQ(family.helptext(), "test"sv);
|
CHECK_EQ(family.Helptext(), "test"sv);
|
||||||
CHECK_EQ(family.unit(), "seconds"sv);
|
CHECK_EQ(family.Unit(), "seconds"sv);
|
||||||
CHECK_EQ(family.isSum(), true);
|
CHECK_EQ(family.IsSum(), true);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"query", "foo"}});
|
auto first = family.GetOrAdd({{"query", "foo"}});
|
||||||
auto second = family.getOrAdd({{"query", "foo"}});
|
auto second = family.GetOrAdd({{"query", "foo"}});
|
||||||
CHECK_EQ(first, second);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"query", "foo"}});
|
auto first = family.GetOrAdd({{"query", "foo"}});
|
||||||
auto second = family.getOrAdd({{"query", "bar"}});
|
auto second = family.GetOrAdd({{"query", "bar"}});
|
||||||
CHECK_NE(first, second);
|
CHECK_NE(first, second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,65 +286,67 @@ SCENARIO("telemetry managers provide access to gauge singletons")
|
||||||
{
|
{
|
||||||
GIVEN("a telemetry manager")
|
GIVEN("a telemetry manager")
|
||||||
{
|
{
|
||||||
NativeManager nativeMgr;
|
NativeManager native_mgr;
|
||||||
Manager mgr{opaque(&nativeMgr)};
|
Manager mgr{opaque(&native_mgr)};
|
||||||
WHEN("retrieving an IntGauge singleton")
|
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")
|
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();
|
first.Inc();
|
||||||
CHECK_EQ(first.value(), 1);
|
CHECK_EQ(first.Value(), 1);
|
||||||
first.inc(2);
|
first.Inc(2);
|
||||||
CHECK_EQ(first.value(), 3);
|
CHECK_EQ(first.Value(), 3);
|
||||||
first.dec();
|
first.Dec();
|
||||||
CHECK_EQ(first.value(), 2);
|
CHECK_EQ(first.Value(), 2);
|
||||||
CHECK_EQ(++first, 3);
|
CHECK_EQ(++first, 3);
|
||||||
CHECK_EQ(first.value(), 3);
|
CHECK_EQ(first.Value(), 3);
|
||||||
CHECK_EQ(--first, 2);
|
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")
|
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);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("calling gaugeSingleton for a different name returns another handle")
|
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);
|
CHECK_NE(first, third);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblGauge singleton")
|
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")
|
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();
|
first.Inc();
|
||||||
CHECK_EQ(first.value(), 1.0);
|
CHECK_EQ(first.Value(), 1.0);
|
||||||
first.inc(3.0);
|
first.Inc(3.0);
|
||||||
CHECK_EQ(first.value(), 4.0);
|
CHECK_EQ(first.Value(), 4.0);
|
||||||
first.dec(2.0);
|
first.Dec(2.0);
|
||||||
CHECK_EQ(first.value(), 2.0);
|
CHECK_EQ(first.Value(), 2.0);
|
||||||
first.dec();
|
first.Dec();
|
||||||
CHECK_EQ(first.value(), 1.0);
|
CHECK_EQ(first.Value(), 1.0);
|
||||||
}
|
}
|
||||||
AND_THEN("calling gaugeSingleton again for the same name returns the same handle")
|
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);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("calling gaugeSingleton for a different name returns another handle")
|
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);
|
CHECK_NE(first, third);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,55 +357,55 @@ SCENARIO("telemetry managers provide access to gauge families")
|
||||||
{
|
{
|
||||||
GIVEN("a telemetry manager")
|
GIVEN("a telemetry manager")
|
||||||
{
|
{
|
||||||
NativeManager nativeMgr;
|
NativeManager native_mgr;
|
||||||
Manager mgr{opaque(&nativeMgr)};
|
Manager mgr{opaque(&native_mgr)};
|
||||||
WHEN("retrieving an IntGauge family")
|
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")
|
THEN("the family object stores the parameters")
|
||||||
{
|
{
|
||||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||||
CHECK_EQ(family.name(), "open-connections"sv);
|
CHECK_EQ(family.Name(), "open-connections"sv);
|
||||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"protocol"s});
|
CHECK_EQ(toVector(family.LabelNames()), std::vector{"protocol"s});
|
||||||
CHECK_EQ(family.helptext(), "test"sv);
|
CHECK_EQ(family.Helptext(), "test"sv);
|
||||||
CHECK_EQ(family.unit(), "1"sv);
|
CHECK_EQ(family.Unit(), "1"sv);
|
||||||
CHECK_EQ(family.isSum(), false);
|
CHECK_EQ(family.IsSum(), false);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"protocol", "tcp"}});
|
auto first = family.GetOrAdd({{"protocol", "tcp"}});
|
||||||
auto second = family.getOrAdd({{"protocol", "tcp"}});
|
auto second = family.GetOrAdd({{"protocol", "tcp"}});
|
||||||
CHECK_EQ(first, second);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"protocol", "tcp"}});
|
auto first = family.GetOrAdd({{"protocol", "tcp"}});
|
||||||
auto second = family.getOrAdd({{"protocol", "quic"}});
|
auto second = family.GetOrAdd({{"protocol", "quic"}});
|
||||||
CHECK_NE(first, second);
|
CHECK_NE(first, second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WHEN("retrieving a DblGauge family")
|
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")
|
THEN("the family object stores the parameters")
|
||||||
{
|
{
|
||||||
CHECK_EQ(family.prefix(), "zeek"sv);
|
CHECK_EQ(family.Prefix(), "zeek"sv);
|
||||||
CHECK_EQ(family.name(), "water-level"sv);
|
CHECK_EQ(family.Name(), "water-level"sv);
|
||||||
CHECK_EQ(toVector(family.labelNames()), std::vector{"river"s});
|
CHECK_EQ(toVector(family.LabelNames()), std::vector{"river"s});
|
||||||
CHECK_EQ(family.helptext(), "test"sv);
|
CHECK_EQ(family.Helptext(), "test"sv);
|
||||||
CHECK_EQ(family.unit(), "meters"sv);
|
CHECK_EQ(family.Unit(), "meters"sv);
|
||||||
CHECK_EQ(family.isSum(), false);
|
CHECK_EQ(family.IsSum(), false);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns the same metric for the same labels")
|
AND_THEN("getOrAdd returns the same metric for the same labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"river", "Sacramento"}});
|
auto first = family.GetOrAdd({{"river", "Sacramento"}});
|
||||||
auto second = family.getOrAdd({{"river", "Sacramento"}});
|
auto second = family.GetOrAdd({{"river", "Sacramento"}});
|
||||||
CHECK_EQ(first, second);
|
CHECK_EQ(first, second);
|
||||||
}
|
}
|
||||||
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
AND_THEN("getOrAdd returns different metric for the disjoint labels")
|
||||||
{
|
{
|
||||||
auto first = family.getOrAdd({{"query", "Sacramento"}});
|
auto first = family.GetOrAdd({{"query", "Sacramento"}});
|
||||||
auto second = family.getOrAdd({{"query", "San Joaquin"}});
|
auto second = family.GetOrAdd({{"query", "San Joaquin"}});
|
||||||
CHECK_NE(first, second);
|
CHECK_NE(first, second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,44 +31,42 @@ public:
|
||||||
virtual ~Manager();
|
virtual ~Manager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a counter metric family. Creates the family lazily if necessary.
|
* @return A counter metric family. Creates the family lazily if necessary.
|
||||||
* @param prefix The prefix (namespace) this family belongs to.
|
* @param prefix The prefix (namespace) this family belongs to.
|
||||||
* @param name The human-readable name of the metric, e.g., `requests`.
|
* @param name The human-readable name of the metric, e.g., `requests`.
|
||||||
* @param labels Names for all label dimensions of the metric.
|
* @param labels Names for all label dimensions of the metric.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
CounterFamily<ValueType>
|
auto CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
counterFamily(std::string_view prefix, std::string_view name,
|
Span<const std::string_view> labels,
|
||||||
Span<const std::string_view> labels,
|
std::string_view helptext,
|
||||||
std::string_view helptext,
|
std::string_view unit = "1", bool is_sum = false) {
|
||||||
std::string_view unit = "1", bool isSum = false) {
|
|
||||||
if constexpr (std::is_same<ValueType, int64_t>::value)
|
if constexpr (std::is_same<ValueType, int64_t>::value)
|
||||||
{
|
{
|
||||||
return intCounterFam(prefix, name, labels, helptext, unit, isSum);
|
return IntCounterFam(prefix, name, labels, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static_assert(std::is_same<ValueType, double>::value,
|
static_assert(std::is_same<ValueType, double>::value,
|
||||||
"metrics only support int64_t and double values");
|
"metrics only support int64_t and double values");
|
||||||
return dblCounterFam(prefix, name, labels, helptext, unit, isSum);
|
return DblCounterFam(prefix, name, labels, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc counterFamily
|
/// @copydoc CounterFamily
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
CounterFamily<ValueType>
|
auto CounterFamily(std::string_view prefix, std::string_view name,
|
||||||
counterFamily(std::string_view prefix, std::string_view name,
|
std::initializer_list<std::string_view> labels,
|
||||||
std::initializer_list<std::string_view> labels,
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
bool is_sum = false)
|
||||||
bool isSum = false)
|
|
||||||
{
|
{
|
||||||
auto lblSpan = Span{labels.begin(), labels.size()};
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
return counterFamily<ValueType>(prefix, name, lblSpan, helptext,
|
return CounterFamily<ValueType>(prefix, name, lbl_span, helptext,
|
||||||
unit, isSum);
|
unit, is_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,19 +77,19 @@ public:
|
||||||
* @param labels Values for all label dimensions of the metric.
|
* @param labels Values for all label dimensions of the metric.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Counter<ValueType>
|
Counter<ValueType>
|
||||||
counterInstance(std::string_view prefix, std::string_view name,
|
CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
Span<const LabelView> labels, std::string_view helptext,
|
Span<const LabelView> labels, std::string_view helptext,
|
||||||
std::string_view unit = "1", bool isSum = false)
|
std::string_view unit = "1", bool is_sum = false)
|
||||||
{
|
{
|
||||||
return withLabelNames(labels, [&, this](auto labelNames)
|
return WithLabelNames(labels, [&, this](auto labelNames)
|
||||||
{
|
{
|
||||||
auto family = counterFamily<ValueType>(prefix, name, labelNames,
|
auto family = CounterFamily<ValueType>(prefix, name, labelNames,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return family.getOrAdd(labels);
|
return family.getOrAdd(labels);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -99,13 +97,13 @@ public:
|
||||||
/// @copydoc counterInstance
|
/// @copydoc counterInstance
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Counter<ValueType>
|
Counter<ValueType>
|
||||||
counterInstance(std::string_view prefix, std::string_view name,
|
CounterInstance(std::string_view prefix, std::string_view name,
|
||||||
std::initializer_list<LabelView> labels,
|
std::initializer_list<LabelView> labels,
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
bool isSum = false)
|
bool is_sum = false)
|
||||||
{
|
{
|
||||||
auto lblSpan = Span{labels.begin(), labels.size()};
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
return counterInstance(prefix, name, lblSpan, helptext, unit, isSum);
|
return CounterInstance(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,60 +114,58 @@ public:
|
||||||
* @param name The human-readable name of the metric, e.g., `requests`.
|
* @param name The human-readable name of the metric, e.g., `requests`.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Counter<ValueType>
|
Counter<ValueType>
|
||||||
counterSingleton(std::string_view prefix, std::string_view name,
|
CounterSingleton(std::string_view prefix, std::string_view name,
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
bool isSum = false)
|
bool is_sum = false)
|
||||||
{
|
{
|
||||||
auto labels = Span<const std::string_view>{};
|
auto labels = Span<const std::string_view>{};
|
||||||
auto fam = counterFamily<ValueType>(prefix, name, labels, helptext,
|
auto fam = CounterFamily<ValueType>(prefix, name, labels, helptext,
|
||||||
unit, isSum);
|
unit, is_sum);
|
||||||
return fam.getOrAdd({});
|
return fam.GetOrAdd({});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a gauge metric family. Creates the family lazily if necessary.
|
* @return A gauge metric family. Creates the family lazily if necessary.
|
||||||
* @param prefix The prefix (namespace) this family belongs to.
|
* @param prefix The prefix (namespace) this family belongs to.
|
||||||
* @param name The human-readable name of the metric, e.g., `requests`.
|
* @param name The human-readable name of the metric, e.g., `requests`.
|
||||||
* @param labels Names for all label dimensions of the metric.
|
* @param labels Names for all label dimensions of the metric.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
GaugeFamily<ValueType>
|
auto GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
gaugeFamily(std::string_view prefix, std::string_view name,
|
Span<const std::string_view> labels,
|
||||||
Span<const std::string_view> labels,
|
std::string_view helptext,
|
||||||
std::string_view helptext,
|
std::string_view unit = "1", bool is_sum = false) {
|
||||||
std::string_view unit = "1", bool isSum = 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, isSum);
|
return IntGaugeFam(prefix, name, labels, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static_assert(std::is_same<ValueType, double>::value,
|
static_assert(std::is_same<ValueType, double>::value,
|
||||||
"metrics only support int64_t and double values");
|
"metrics only support int64_t and double values");
|
||||||
return dblGaugeFam(prefix, name, labels, helptext, unit, isSum);
|
return DblGaugeFam(prefix, name, labels, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc gaugeFamily
|
/// @copydoc GaugeFamily
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
GaugeFamily<ValueType>
|
auto GaugeFamily(std::string_view prefix, std::string_view name,
|
||||||
gaugeFamily(std::string_view prefix, std::string_view name,
|
std::initializer_list<std::string_view> labels,
|
||||||
std::initializer_list<std::string_view> labels,
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
bool is_sum = false)
|
||||||
bool isSum = false)
|
|
||||||
{
|
{
|
||||||
auto lblSpan = Span{labels.begin(), labels.size()};
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
return gaugeFamily<ValueType>(prefix, name, lblSpan, helptext,
|
return GaugeFamily<ValueType>(prefix, name, lbl_span, helptext,
|
||||||
unit, isSum);
|
unit, is_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -180,33 +176,33 @@ public:
|
||||||
* @param labels Values for all label dimensions of the metric.
|
* @param labels Values for all label dimensions of the metric.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Gauge<ValueType>
|
Gauge<ValueType>
|
||||||
gaugeInstance(std::string_view prefix, std::string_view name,
|
GaugeInstance(std::string_view prefix, std::string_view name,
|
||||||
Span<const LabelView> labels, std::string_view helptext,
|
Span<const LabelView> labels, std::string_view helptext,
|
||||||
std::string_view unit = "1", bool isSum = false)
|
std::string_view unit = "1", bool is_sum = false)
|
||||||
{
|
{
|
||||||
return withLabelNames(labels, [&, this](auto labelNames)
|
return WithLabelNames(labels, [&, this](auto labelNames)
|
||||||
{
|
{
|
||||||
auto family = gaugeFamily<ValueType>(prefix, name, labelNames,
|
auto family = GaugeFamily<ValueType>(prefix, name, labelNames,
|
||||||
helptext, unit, isSum);
|
helptext, unit, is_sum);
|
||||||
return family.getOrAdd(labels);
|
return family.getOrAdd(labels);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @copydoc gaugeInstance
|
/// @copydoc GaugeInstance
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Gauge<ValueType>
|
Gauge<ValueType>
|
||||||
gaugeInstance(std::string_view prefix, std::string_view name,
|
GaugeInstance(std::string_view prefix, std::string_view name,
|
||||||
std::initializer_list<LabelView> labels,
|
std::initializer_list<LabelView> labels,
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
bool isSum = false)
|
bool is_sum = false)
|
||||||
{
|
{
|
||||||
auto lblSpan = Span{labels.begin(), labels.size()};
|
auto lbl_span = Span{labels.begin(), labels.size()};
|
||||||
return gaugeInstance(prefix, name, lblSpan, helptext, unit, isSum);
|
return GaugeInstance(prefix, name, lbl_span, helptext, unit, is_sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,44 +213,48 @@ public:
|
||||||
* @param name The human-readable name of the metric, e.g., `requests`.
|
* @param name The human-readable name of the metric, e.g., `requests`.
|
||||||
* @param helptext Short explanation of the metric.
|
* @param helptext Short explanation of the metric.
|
||||||
* @param unit Unit of measurement.
|
* @param unit Unit of measurement.
|
||||||
* @param isSum Indicates whether this metric accumulates something, where
|
* @param is_sum Indicates whether this metric accumulates something, where
|
||||||
* only the total value is of interest.
|
* only the total value is of interest.
|
||||||
*/
|
*/
|
||||||
template <class ValueType = int64_t>
|
template <class ValueType = int64_t>
|
||||||
Gauge<ValueType>
|
Gauge<ValueType>
|
||||||
gaugeSingleton(std::string_view prefix, std::string_view name,
|
GaugeSingleton(std::string_view prefix, std::string_view name,
|
||||||
std::string_view helptext, std::string_view unit = "1",
|
std::string_view helptext, std::string_view unit = "1",
|
||||||
bool isSum = false)
|
bool is_sum = false)
|
||||||
{
|
{
|
||||||
auto labels = Span<const std::string_view>{};
|
auto labels = Span<const std::string_view>{};
|
||||||
auto fam = gaugeFamily<ValueType>(prefix, name, labels, helptext,
|
auto fam = GaugeFamily<ValueType>(prefix, name, labels, helptext,
|
||||||
unit, isSum);
|
unit, is_sum);
|
||||||
return fam.getOrAdd({});
|
return fam.GetOrAdd({});
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IntCounterFamily
|
IntCounterFamily
|
||||||
intCounterFam(std::string_view prefix, std::string_view name,
|
IntCounterFam(std::string_view prefix, std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit, bool isSum);
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum);
|
||||||
|
|
||||||
DblCounterFamily
|
DblCounterFamily
|
||||||
dblCounterFam(std::string_view prefix, std::string_view name,
|
DblCounterFam(std::string_view prefix, std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit, bool isSum);
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum);
|
||||||
|
|
||||||
IntGaugeFamily
|
IntGaugeFamily
|
||||||
intGaugeFam(std::string_view prefix, std::string_view name,
|
IntGaugeFam(std::string_view prefix, std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit, bool isSum);
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum);
|
||||||
|
|
||||||
DblGaugeFamily
|
DblGaugeFamily
|
||||||
dblGaugeFam(std::string_view prefix, std::string_view name,
|
DblGaugeFam(std::string_view prefix, std::string_view name,
|
||||||
Span<const std::string_view> labels,
|
Span<const std::string_view> labels,
|
||||||
std::string_view helptext, std::string_view unit, bool isSum);
|
std::string_view helptext, std::string_view unit,
|
||||||
|
bool is_sum);
|
||||||
|
|
||||||
template <class F>
|
template <class F>
|
||||||
static void withLabelNames(Span<const LabelView> xs, F continuation)
|
static void WithLabelNames(Span<const LabelView> xs, F continuation)
|
||||||
{
|
{
|
||||||
if ( xs.size() <= 10 ) {
|
if ( xs.size() <= 10 ) {
|
||||||
std::string_view buf[10];
|
std::string_view buf[10];
|
||||||
|
|
|
@ -19,32 +19,32 @@ auto& deref(MetricFamily::Impl* ptr)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::string_view MetricFamily::prefix() const noexcept
|
std::string_view MetricFamily::Prefix() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).prefix();
|
return deref(pimpl).prefix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view MetricFamily::name() const noexcept
|
std::string_view MetricFamily::Name() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).name();
|
return deref(pimpl).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
Span<const std::string> MetricFamily::labelNames() const noexcept
|
Span<const std::string> MetricFamily::LabelNames() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).label_names();
|
return deref(pimpl).label_names();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view MetricFamily::helptext() const noexcept
|
std::string_view MetricFamily::Helptext() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).helptext();
|
return deref(pimpl).helptext();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view MetricFamily::unit() const noexcept
|
std::string_view MetricFamily::Unit() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).unit();
|
return deref(pimpl).unit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MetricFamily::isSum() const noexcept
|
bool MetricFamily::IsSum() const noexcept
|
||||||
{
|
{
|
||||||
return deref(pimpl).is_sum();
|
return deref(pimpl).is_sum();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,42 +28,42 @@ public:
|
||||||
MetricFamily& operator=(const MetricFamily&) noexcept = default;
|
MetricFamily& operator=(const MetricFamily&) noexcept = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the prefix (namespace) this family belongs to. Builtin metrics
|
* @return The prefix (namespace) this family belongs to. Builtin metrics
|
||||||
* of Zeek return @c zeek. Custom metrics, e.g., created in a
|
* of Zeek return @c zeek. Custom metrics, e.g., created in a
|
||||||
* script, may use a prefix that represents the application/script
|
* script, may use a prefix that represents the application/script
|
||||||
* or protocol (e.g. @c http) name.
|
* or protocol (e.g. @c http) name.
|
||||||
*/
|
*/
|
||||||
std::string_view prefix() const noexcept;
|
std::string_view Prefix() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the human-readable name of the metric, e.g.,
|
* @return The human-readable name of the metric, e.g.,
|
||||||
* @p open-connections.
|
* @p open-connections.
|
||||||
*/
|
*/
|
||||||
std::string_view name() const noexcept;
|
std::string_view Name() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the names for all label dimensions.
|
* @return The names for all label dimensions.
|
||||||
*/
|
*/
|
||||||
Span<const std::string> labelNames() const noexcept;
|
Span<const std::string> LabelNames() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a short explanation of the metric.
|
* @return A short explanation of the metric.
|
||||||
*/
|
*/
|
||||||
std::string_view helptext() const noexcept;
|
std::string_view Helptext() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the unit of measurement, preferably a base unit such as
|
* @return The unit of measurement, preferably a base unit such as
|
||||||
* @c bytes or @c seconds. Dimensionless counts return the
|
* @c bytes or @c seconds. Dimensionless counts return the
|
||||||
* pseudo-unit @c 1.
|
* pseudo-unit @c 1.
|
||||||
*/
|
*/
|
||||||
std::string_view unit() const noexcept;
|
std::string_view Unit() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns whether metrics of this family accumulate values, where only the
|
* @return Whether metrics of this family accumulate values, where only the
|
||||||
* total value is of interest. For example, the total number of
|
* total value is of interest. For example, the total number of
|
||||||
* HTTP requests.
|
* HTTP requests.
|
||||||
*/
|
*/
|
||||||
bool isSum() const noexcept;
|
bool IsSum() const noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit MetricFamily(Impl* ptr) : pimpl(ptr)
|
explicit MetricFamily(Impl* ptr) : pimpl(ptr)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue