prom 0.1.0
Client-independent C++23 Prometheus/OpenMetrics metric abstraction
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
prom::MetricBase< Derived > Class Template Reference

CRTP base shared by every metric type. More...

#include <metric_base.hpp>

Collaboration diagram for prom::MetricBase< Derived >:
Collaboration graph
[legend]

Classes

struct  Binding
 A resolved (adapter, handle) snapshot — the result of bind(). More...
 

Public Member Functions

std::string_view name () const noexcept
 The metric's fully-qualified name.
 
MetricType type () const noexcept
 The metric kind.
 

Protected Member Functions

 MetricBase (const MetricType type, const std::string_view name, const std::string_view help)
 Standalone, unbound construction from a name and help string.
 
 MetricBase (std::shared_ptr< MetricCore > core)
 Adopt an already-populated core (registered metrics and children).
 
 MetricBase (const MetricBase &)=default
 
MetricBaseoperator= (const MetricBase &)=default
 
 MetricBase (MetricBase &&)=default
 
MetricBaseoperator= (MetricBase &&)=default
 
 ~MetricBase ()=default
 
Binding bind () const noexcept
 Resolve the adapter and backend handle this metric should record against.
 
const std::shared_ptr< MetricCore > & core () const noexcept
 
Derived make_child (const Labels &dynamic) const noexcept
 Resolve a labeled child of the same metric type.
 
bool reconcile_unit (const Unit &observed, Adapter &adapter) const noexcept
 Reconcile an observed unit against the family's known unit.
 
bool check_finite (const double value, std::string_view op) const noexcept
 Drop-and-log guard for a non-finite sample.
 

Static Protected Member Functions

static spdlog::logger * logger () noexcept
 The shared per-process metrics logger.
 

Protected Attributes

std::shared_ptr< MetricCorecore_
 

Detailed Description

template<class Derived>
class prom::MetricBase< Derived >

CRTP base shared by every metric type.

Provides the binding machinery and the protected helpers (record_*, make_child, reconcile_unit) the concrete types build their public surface from.

Constructor & Destructor Documentation

◆ MetricBase() [1/4]

template<class Derived >
prom::MetricBase< Derived >::MetricBase ( const MetricType  type,
const std::string_view  name,
const std::string_view  help 
)
inlineprotected

Standalone, unbound construction from a name and help string.

Reads its adapter from the process-wide cell and binds lazily on first use. It also follows the process-wide global decoration, so a prefix / labels installed via Registry::global() reach standalone metrics too; with the default (empty) decoration the effective name and labels are unchanged.

◆ MetricBase() [2/4]

template<class Derived >
prom::MetricBase< Derived >::MetricBase ( std::shared_ptr< MetricCore core)
inlineexplicitprotected

Adopt an already-populated core (registered metrics and children).

◆ MetricBase() [3/4]

template<class Derived >
prom::MetricBase< Derived >::MetricBase ( const MetricBase< Derived > &  )
protecteddefault

◆ MetricBase() [4/4]

template<class Derived >
prom::MetricBase< Derived >::MetricBase ( MetricBase< Derived > &&  )
protecteddefault

◆ ~MetricBase()

template<class Derived >
prom::MetricBase< Derived >::~MetricBase ( )
protecteddefault

Member Function Documentation

◆ bind()

template<class Derived >
Binding prom::MetricBase< Derived >::bind ( ) const
inlineprotectednoexcept

Resolve the adapter and backend handle this metric should record against.

Fast path: load the published binding. A pinned binding (a labeled child) is returned as-is — children never migrate. Otherwise the binding is reused while it matches the source's adapter version() and, for a scoped metric, the scope's config version().

Slow path (rebind): resolve the current adapter from the source, recompute the name / labels / display from the live scope (if scoped), register the family, and publish a fresh binding. This fires on first use of a standalone/scoped metric, on an adapter swap (live migration to the new backend — the previous backend's series are left behind), and on a scope reconfiguration.

◆ check_finite()

template<class Derived >
bool prom::MetricBase< Derived >::check_finite ( const double  value,
std::string_view  op 
) const
inlineprotectednoexcept

Drop-and-log guard for a non-finite sample.

Returns true when the value is safe to record.

◆ core()

template<class Derived >
const std::shared_ptr< MetricCore > & prom::MetricBase< Derived >::core ( ) const
inlineprotectednoexcept

◆ logger()

template<class Derived >
static spdlog::logger * prom::MetricBase< Derived >::logger ( )
inlinestaticprotectednoexcept

The shared per-process metrics logger.

◆ make_child()

template<class Derived >
Derived prom::MetricBase< Derived >::make_child ( const Labels dynamic) const
inlineprotectednoexcept

Resolve a labeled child of the same metric type.

The child carries the backend's resolved child handle and points back at this family for unit reconciliation. The child is pinned: it snapshots the adapter and the scope-decorated state in effect at the time of the labels() call and never migrates, even if the source adapter or scope later changes.

◆ name()

template<class Derived >
std::string_view prom::MetricBase< Derived >::name ( ) const
inlinenoexcept

The metric's fully-qualified name.

◆ operator=() [1/2]

template<class Derived >
MetricBase & prom::MetricBase< Derived >::operator= ( const MetricBase< Derived > &  )
protecteddefault

◆ operator=() [2/2]

template<class Derived >
MetricBase & prom::MetricBase< Derived >::operator= ( MetricBase< Derived > &&  )
protecteddefault

◆ reconcile_unit()

template<class Derived >
bool prom::MetricBase< Derived >::reconcile_unit ( const Unit observed,
Adapter adapter 
) const
inlineprotectednoexcept

Reconcile an observed unit against the family's known unit.

Returns false (and logs) when a dimensional sample's kind contradicts the latched kind, signalling the caller to drop the sample. A unitless sample always passes. The first dimensional sample latches the unit.

◆ type()

template<class Derived >
MetricType prom::MetricBase< Derived >::type ( ) const
inlinenoexcept

The metric kind.

Member Data Documentation

◆ core_

template<class Derived >
std::shared_ptr<MetricCore> prom::MetricBase< Derived >::core_
protected

The documentation for this class was generated from the following files: