Advise to cache Metric instance
This commit is contained in:
@@ -123,10 +123,14 @@ template <class T> struct Family {
|
|||||||
static_assert(std::is_same_v<T, Counter> || std::is_same_v<T, Gauge> ||
|
static_assert(std::is_same_v<T, Counter> || std::is_same_v<T, Gauge> ||
|
||||||
std::is_same_v<T, Histogram>);
|
std::is_same_v<T, Histogram>);
|
||||||
|
|
||||||
// Create metric instance with specific labels
|
// Create metric instance with specific labels.
|
||||||
// Labels are sorted by key for Prometheus compatibility
|
// For performance, it is recommended to create instances once and cache them
|
||||||
// ERROR: Will abort if labels already registered via register_callback()
|
// for reuse, rather than calling .create() repeatedly in
|
||||||
// OK: Multiple calls with same labels return same instance (idempotent)
|
// performance-critical paths.
|
||||||
|
//
|
||||||
|
// Labels are sorted by key for Prometheus compatibility.
|
||||||
|
// ERROR: Will abort if labels already registered via register_callback().
|
||||||
|
// OK: Multiple calls with same labels return same instance (idempotent).
|
||||||
T create(std::initializer_list<std::pair<std::string_view, std::string_view>>
|
T create(std::initializer_list<std::pair<std::string_view, std::string_view>>
|
||||||
labels) {
|
labels) {
|
||||||
return create(
|
return create(
|
||||||
|
|||||||
Reference in New Issue
Block a user