userver: samples/testsuite-support/src/metrics.cpp
Loading...
Searching...
No Matches
samples/testsuite-support/src/metrics.cpp
#include "metrics.hpp"
#include <userver/utils/statistics/metrics_storage.hpp>
namespace tests::handlers {
namespace {
const utils::statistics::MetricTag<utils::statistics::RateCounter> kFooMetric{"sample-metrics.foo"};
} // namespace
Metrics::Metrics(const components::ComponentConfig& config, const components::ComponentContext& context)
metrics_(context.FindComponent<components::StatisticsStorage>().GetMetricsStorage())
{}
formats::json::Value Metrics::HandleRequestJsonThrow(
[[maybe_unused]] const server::http::HttpRequest& request,
[[maybe_unused]] const formats::json::Value& request_body,
[[maybe_unused]] server::request::RequestContext& context
) const {
request.GetHttpResponse().SetContentType(http::content_type::kApplicationJson);
utils::statistics::RateCounter& foo_metric = metrics_->GetMetric(kFooMetric);
++foo_metric; // safe to increment concurrently
return result.ExtractValue();
}
} // namespace tests::handlers