userver: utils::statistics::Snapshot Class Reference
Loading...
Searching...
No Matches
utils::statistics::Snapshot Class Referencefinal

#include <userver/utils/statistics/testing.hpp>

Detailed Description

A snapshot of metrics from utils::statistics::Storage.

Definition at line 31 of file testing.hpp.

Public Member Functions

 Snapshot (const Storage &storage, std::string prefix={}, std::vector< Label > require_labels={})
 Create a new snapshot of metrics with paths starting with prefix and labels containing require_labels.
 
 Snapshot (const Snapshot &other)=default
 
 Snapshot (Snapshot &&other) noexcept=default
 
MetricValue SingleMetric (std::string path, std::vector< Label > require_labels={}) const
 Find a single metric by the given filter.
 

Constructor & Destructor Documentation

◆ Snapshot()

utils::statistics::Snapshot::Snapshot ( const Storage & storage,
std::string prefix = {},
std::vector< Label > require_labels = {} )
explicit

Create a new snapshot of metrics with paths starting with prefix and labels containing require_labels.

Exceptions
std::exceptionif a metric writer throws.

Member Function Documentation

◆ SingleMetric()

MetricValue utils::statistics::Snapshot::SingleMetric ( std::string path,
std::vector< Label > require_labels = {} ) const

Find a single metric by the given filter.

Parameters
pathThe path of the target metric. prefix specified in the constructor is prepended to the path.
require_labelsLabels that the target metric should have.
Returns
The value of the single found metric.
Exceptions
MetricQueryErrorif none or multiple metrics are found.

Friends And Related Symbol Documentation

◆ PrintTo

void PrintTo ( const Snapshot & data,
std::ostream *  )
friend

Support for gtest diagnostics for utils::statistics::Snapshot.

Warning
Never check the printed value programmatically! The string is not stable and may change, depending on the version of stdlib and userver.

Valid usage:

EXPECT_EQ(..., ...) << testing::PrintToString(snapshot);

Invalid usage:

std::ostringstream stream;
PrintTo(snapshot, &stream);
EXPECT_EQ(stream.str(), ...);

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