diff options
author | Vladimir Gordiychuk <folyga@gmail.com> | 2022-02-10 16:50:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:21 +0300 |
commit | 9315561a79f8c08b28065daf027ef493ae27a6d2 (patch) | |
tree | 015bf2f66ecea81b37d6791fe2e8948e18e07186 | |
parent | 0dd632d6fc5676c75d7004172992cefaa2192db0 (diff) | |
download | ydb-9315561a79f8c08b28065daf027ef493ae27a6d2.tar.gz |
Restoring authorship annotation for Vladimir Gordiychuk <folyga@gmail.com>. Commit 1 of 2.
-rw-r--r-- | library/cpp/grpc/client/grpc_client_low.cpp | 118 | ||||
-rw-r--r-- | library/cpp/grpc/client/grpc_client_low.h | 8 | ||||
-rw-r--r-- | library/cpp/grpc/server/grpc_server.cpp | 90 | ||||
-rw-r--r-- | library/cpp/grpc/server/grpc_server.h | 10 | ||||
-rw-r--r-- | library/cpp/monlib/encode/spack/spack_v1_ut.cpp | 2 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/fake.cpp | 40 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/fake.h | 56 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric.h | 246 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry.cpp | 64 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry.h | 26 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry_ut.cpp | 116 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_type.h | 4 |
12 files changed, 390 insertions, 390 deletions
diff --git a/library/cpp/grpc/client/grpc_client_low.cpp b/library/cpp/grpc/client/grpc_client_low.cpp index 73cc908ef8..75f80767dd 100644 --- a/library/cpp/grpc/client/grpc_client_low.cpp +++ b/library/cpp/grpc/client/grpc_client_low.cpp @@ -5,8 +5,8 @@ #include <library/cpp/containers/stack_vector/stack_vec.h> #include <util/string/printf.h> -#include <util/system/thread.h> -#include <util/random/random.h> +#include <util/system/thread.h> +#include <util/random/random.h> #if !defined(_WIN32) && !defined(_WIN64) #include <sys/types.h> @@ -175,24 +175,24 @@ void TChannelPool::EraseFromQueueByTime(const TInstant& lastUseTime, const TStri LastUsedQueue_.erase(pos); } -static void PullEvents(grpc::CompletionQueue* cq) { - TThread::SetCurrentThreadName("grpc_client"); - while (true) { - void* tag; - bool ok; - - if (!cq->Next(&tag, &ok)) { - break; - } - - if (auto* ev = static_cast<IQueueClientEvent*>(tag)) { - if (!ev->Execute(ok)) { - ev->Destroy(); - } - } - } -} - +static void PullEvents(grpc::CompletionQueue* cq) { + TThread::SetCurrentThreadName("grpc_client"); + while (true) { + void* tag; + bool ok; + + if (!cq->Next(&tag, &ok)) { + break; + } + + if (auto* ev = static_cast<IQueueClientEvent*>(tag)) { + if (!ev->Execute(ok)) { + ev->Destroy(); + } + } + } +} + class TGRpcClientLow::TContextImpl final : public std::enable_shared_from_this<TContextImpl> , public IQueueClientContext @@ -249,7 +249,7 @@ public: // It's now safe to initialize parent and owner child->Parent = std::move(self); child->Owner = Owner; - child->CQ = CQ; + child->CQ = CQ; // Propagate cancellation to a child context if (Cancelled.load(std::memory_order_relaxed)) { @@ -262,7 +262,7 @@ public: grpc::CompletionQueue* CompletionQueue() override { Y_VERIFY(Owner, "Uninitialized context"); - return CQ; + return CQ; } bool IsCancelled() const override { @@ -388,7 +388,7 @@ private: // These fields are initialized on successful registration TContextPtr Parent; TGRpcClientLow* Owner = nullptr; - grpc::CompletionQueue* CQ = nullptr; + grpc::CompletionQueue* CQ = nullptr; // Some children are stored inline, others are in a set std::array<TContextImpl*, 2> InlineChildren{ { nullptr, nullptr } }; @@ -401,46 +401,46 @@ private: std::atomic<bool> Cancelled; }; -TGRpcClientLow::TGRpcClientLow(size_t numWorkerThread, bool useCompletionQueuePerThread) - : UseCompletionQueuePerThread_(useCompletionQueuePerThread) -{ +TGRpcClientLow::TGRpcClientLow(size_t numWorkerThread, bool useCompletionQueuePerThread) + : UseCompletionQueuePerThread_(useCompletionQueuePerThread) +{ Init(numWorkerThread); } void TGRpcClientLow::Init(size_t numWorkerThread) { SetCqState(WORKING); - if (UseCompletionQueuePerThread_) { - for (size_t i = 0; i < numWorkerThread; i++) { - CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); - auto* cq = CQS_.back().get(); - WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { - PullEvents(cq); - }).Release()); - } - } else { - CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); - auto* cq = CQS_.back().get(); - for (size_t i = 0; i < numWorkerThread; i++) { - WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { - PullEvents(cq); - }).Release()); - } + if (UseCompletionQueuePerThread_) { + for (size_t i = 0; i < numWorkerThread; i++) { + CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); + auto* cq = CQS_.back().get(); + WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { + PullEvents(cq); + }).Release()); + } + } else { + CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); + auto* cq = CQS_.back().get(); + for (size_t i = 0; i < numWorkerThread; i++) { + WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { + PullEvents(cq); + }).Release()); + } } } void TGRpcClientLow::AddWorkerThreadForTest() { - if (UseCompletionQueuePerThread_) { - CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); - auto* cq = CQS_.back().get(); - WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { - PullEvents(cq); - }).Release()); - } else { - auto* cq = CQS_.back().get(); - WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { - PullEvents(cq); - }).Release()); - } + if (UseCompletionQueuePerThread_) { + CQS_.push_back(std::make_unique<grpc::CompletionQueue>()); + auto* cq = CQS_.back().get(); + WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { + PullEvents(cq); + }).Release()); + } else { + auto* cq = CQS_.back().get(); + WorkerThreads_.emplace_back(SystemThreadFactory()->Run([cq]() { + PullEvents(cq); + }).Release()); + } } TGRpcClientLow::~TGRpcClientLow() { @@ -503,9 +503,9 @@ void TGRpcClientLow::StopInternal(bool silent) { } if (shutdown) { - for (auto& cq : CQS_) { - cq->Shutdown(); - } + for (auto& cq : CQS_) { + cq->Shutdown(); + } } } @@ -577,8 +577,8 @@ void TGRpcClientLow::ForgetContext(TContextImpl* context) { if (shutdown) { // This was the last context, shutdown CQ - for (auto& cq : CQS_) { - cq->Shutdown(); + for (auto& cq : CQS_) { + cq->Shutdown(); } } } diff --git a/library/cpp/grpc/client/grpc_client_low.h b/library/cpp/grpc/client/grpc_client_low.h index ab0a0627be..627c88ca67 100644 --- a/library/cpp/grpc/client/grpc_client_low.h +++ b/library/cpp/grpc/client/grpc_client_low.h @@ -1320,7 +1320,7 @@ private: }; class TGRpcClientLow - : public IQueueClientContextProvider + : public IQueueClientContextProvider { class TContextImpl; friend class TContextImpl; @@ -1332,7 +1332,7 @@ class TGRpcClientLow }; public: - explicit TGRpcClientLow(size_t numWorkerThread = DEFAULT_NUM_THREADS, bool useCompletionQueuePerThread = false); + explicit TGRpcClientLow(size_t numWorkerThread = DEFAULT_NUM_THREADS, bool useCompletionQueuePerThread = false); ~TGRpcClientLow(); // Tries to stop all currently running requests (via their stop callbacks) @@ -1372,7 +1372,7 @@ public: private: using IThreadRef = std::unique_ptr<IThreadFactory::IThread>; - using CompletionQueueRef = std::unique_ptr<grpc::CompletionQueue>; + using CompletionQueueRef = std::unique_ptr<grpc::CompletionQueue>; void Init(size_t numWorkerThread); inline ECqState GetCqState() const { return (ECqState) AtomicGet(CqState_); } @@ -1384,7 +1384,7 @@ private: void ForgetContext(TContextImpl* context); private: - bool UseCompletionQueuePerThread_; + bool UseCompletionQueuePerThread_; std::vector<CompletionQueueRef> CQS_; std::vector<IThreadRef> WorkerThreads_; TAtomic CqState_ = -1; diff --git a/library/cpp/grpc/server/grpc_server.cpp b/library/cpp/grpc/server/grpc_server.cpp index 7437b7a8f5..5d72f74d29 100644 --- a/library/cpp/grpc/server/grpc_server.cpp +++ b/library/cpp/grpc/server/grpc_server.cpp @@ -19,24 +19,24 @@ namespace NGrpc { using NThreading::TFuture; -static void PullEvents(grpc::ServerCompletionQueue* cq) { - TThread::SetCurrentThreadName("grpc_server"); - while (true) { - void* tag; // uniquely identifies a request. - bool ok; - - if (cq->Next(&tag, &ok)) { - IQueueEvent* const ev(static_cast<IQueueEvent*>(tag)); - - if (!ev->Execute(ok)) { - ev->DestroyRequest(); - } - } else { - break; - } - } -} - +static void PullEvents(grpc::ServerCompletionQueue* cq) { + TThread::SetCurrentThreadName("grpc_server"); + while (true) { + void* tag; // uniquely identifies a request. + bool ok; + + if (cq->Next(&tag, &ok)) { + IQueueEvent* const ev(static_cast<IQueueEvent*>(tag)); + + if (!ev->Execute(ok)) { + ev->DestroyRequest(); + } + } else { + break; + } + } +} + TGRpcServer::TGRpcServer(const TServerOptions& opts) : Options_(opts) , Limiter_(Options_.MaxGlobalRequestInFlight) @@ -124,14 +124,14 @@ void TGRpcServer::Start() { builder.SetOption(std::make_unique<TKeepAliveOption>()); } - if (Options_.UseCompletionQueuePerThread) { - for (size_t i = 0; i < Options_.WorkerThreads; ++i) { - CQS_.push_back(builder.AddCompletionQueue()); - } - } else { - CQS_.push_back(builder.AddCompletionQueue()); - } - + if (Options_.UseCompletionQueuePerThread) { + for (size_t i = 0; i < Options_.WorkerThreads; ++i) { + CQS_.push_back(builder.AddCompletionQueue()); + } + } else { + CQS_.push_back(builder.AddCompletionQueue()); + } + if (Options_.GRpcMemoryQuotaBytes) { // See details KIKIMR-6932 /* @@ -149,27 +149,27 @@ void TGRpcServer::Start() { if (!Server_) { ythrow yexception() << "can't start grpc server on " << server_address; } - - size_t index = 0; + + size_t index = 0; for (IGRpcServicePtr service : Services_) { - // TODO: provide something else for services instead of ServerCompletionQueue + // TODO: provide something else for services instead of ServerCompletionQueue service->InitService(CQS_[index++ % CQS_.size()].get(), Options_.Logger); } - if (Options_.UseCompletionQueuePerThread) { - for (size_t i = 0; i < Options_.WorkerThreads; ++i) { - auto* cq = &CQS_[i]; - Ts.push_back(SystemThreadFactory()->Run([cq] { - PullEvents(cq->get()); - })); - } - } else { - for (size_t i = 0; i < Options_.WorkerThreads; ++i) { - auto* cq = &CQS_[0]; - Ts.push_back(SystemThreadFactory()->Run([cq] { - PullEvents(cq->get()); - })); - } + if (Options_.UseCompletionQueuePerThread) { + for (size_t i = 0; i < Options_.WorkerThreads; ++i) { + auto* cq = &CQS_[i]; + Ts.push_back(SystemThreadFactory()->Run([cq] { + PullEvents(cq->get()); + })); + } + } else { + for (size_t i = 0; i < Options_.WorkerThreads; ++i) { + auto* cq = &CQS_[0]; + Ts.push_back(SystemThreadFactory()->Run([cq] { + PullEvents(cq->get()); + })); + } } if (Options_.ExternalListener) { @@ -214,8 +214,8 @@ void TGRpcServer::Stop() { } // Always shutdown the completion queue after the server. - for (auto& cq : CQS_) { - cq->Shutdown(); + for (auto& cq : CQS_) { + cq->Shutdown(); } for (auto ti = Ts.begin(); ti != Ts.end(); ++ti) { diff --git a/library/cpp/grpc/server/grpc_server.h b/library/cpp/grpc/server/grpc_server.h index d6814a90a0..4d6626efb9 100644 --- a/library/cpp/grpc/server/grpc_server.h +++ b/library/cpp/grpc/server/grpc_server.h @@ -53,9 +53,9 @@ struct TServerOptions { //! Number of worker threads. DECLARE_FIELD(WorkerThreads, size_t, 2); - //! Create one completion queue per thread - DECLARE_FIELD(UseCompletionQueuePerThread, bool, false); - + //! Create one completion queue per thread + DECLARE_FIELD(UseCompletionQueuePerThread, bool, false); + //! Memory quota size for grpc server in bytes. Zero means unlimited. DECLARE_FIELD(GRpcMemoryQuotaBytes, size_t, 0); @@ -328,7 +328,7 @@ private: TAdaptiveLock Lock_; }; -class TGRpcServer { +class TGRpcServer { public: using IGRpcServicePtr = TIntrusivePtr<IGRpcService>; TGRpcServer(const TServerOptions& opts); @@ -346,7 +346,7 @@ private: const TServerOptions Options_; std::unique_ptr<grpc::Server> Server_; - std::vector<std::unique_ptr<grpc::ServerCompletionQueue>> CQS_; + std::vector<std::unique_ptr<grpc::ServerCompletionQueue>> CQS_; TVector<IThreadRef> Ts; TVector<IGRpcServicePtr> Services_; diff --git a/library/cpp/monlib/encode/spack/spack_v1_ut.cpp b/library/cpp/monlib/encode/spack/spack_v1_ut.cpp index fe778eb7e0..f8e893071d 100644 --- a/library/cpp/monlib/encode/spack/spack_v1_ut.cpp +++ b/library/cpp/monlib/encode/spack/spack_v1_ut.cpp @@ -211,7 +211,7 @@ Y_UNIT_TEST_SUITE(TSpackTest) { }; ui8 expectedMetric8[] = { - 0x26, // types (LOGHIST | ONE_WITH_TS) (fixed ui8) + 0x26, // types (LOGHIST | ONE_WITH_TS) (fixed ui8) 0x00, // flags (fixed ui8) 0x01, // metric labels count (variant) 0x00, // label name index (variant) diff --git a/library/cpp/monlib/metrics/fake.cpp b/library/cpp/monlib/metrics/fake.cpp index b6f5e37af8..b6cc61f1c9 100644 --- a/library/cpp/monlib/metrics/fake.cpp +++ b/library/cpp/monlib/metrics/fake.cpp @@ -6,38 +6,38 @@ namespace NMonitoring { return Metric<TFakeGauge, EMetricType::GAUGE>(std::move(labels)); } - ILazyGauge* TFakeMetricRegistry::LazyGauge(ILabelsPtr labels, std::function<double()> supplier) { - Y_UNUSED(supplier); - return Metric<TFakeLazyGauge, EMetricType::GAUGE>(std::move(labels)); - } - + ILazyGauge* TFakeMetricRegistry::LazyGauge(ILabelsPtr labels, std::function<double()> supplier) { + Y_UNUSED(supplier); + return Metric<TFakeLazyGauge, EMetricType::GAUGE>(std::move(labels)); + } + IIntGauge* TFakeMetricRegistry::IntGauge(ILabelsPtr labels) { return Metric<TFakeIntGauge, EMetricType::IGAUGE>(std::move(labels)); } - ILazyIntGauge* TFakeMetricRegistry::LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) { - Y_UNUSED(supplier); - return Metric<TFakeLazyIntGauge, EMetricType::IGAUGE>(std::move(labels)); - } - + ILazyIntGauge* TFakeMetricRegistry::LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) { + Y_UNUSED(supplier); + return Metric<TFakeLazyIntGauge, EMetricType::IGAUGE>(std::move(labels)); + } + ICounter* TFakeMetricRegistry::Counter(ILabelsPtr labels) { return Metric<TFakeCounter, EMetricType::COUNTER>(std::move(labels)); } - ILazyCounter* TFakeMetricRegistry::LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) { - Y_UNUSED(supplier); - return Metric<TFakeLazyCounter, EMetricType::COUNTER>(std::move(labels)); - } - + ILazyCounter* TFakeMetricRegistry::LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) { + Y_UNUSED(supplier); + return Metric<TFakeLazyCounter, EMetricType::COUNTER>(std::move(labels)); + } + IRate* TFakeMetricRegistry::Rate(ILabelsPtr labels) { return Metric<TFakeRate, EMetricType::RATE>(std::move(labels)); } - ILazyRate* TFakeMetricRegistry::LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) { - Y_UNUSED(supplier); - return Metric<TFakeLazyRate, EMetricType::RATE>(std::move(labels)); - } - + ILazyRate* TFakeMetricRegistry::LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) { + Y_UNUSED(supplier); + return Metric<TFakeLazyRate, EMetricType::RATE>(std::move(labels)); + } + IHistogram* TFakeMetricRegistry::HistogramCounter(ILabelsPtr labels, IHistogramCollectorPtr collector) { Y_UNUSED(collector); return Metric<TFakeHistogram, EMetricType::HIST>(std::move(labels), false); diff --git a/library/cpp/monlib/metrics/fake.h b/library/cpp/monlib/metrics/fake.h index 61ba4f2bd4..70f36e3d25 100644 --- a/library/cpp/monlib/metrics/fake.h +++ b/library/cpp/monlib/metrics/fake.h @@ -17,13 +17,13 @@ namespace NMonitoring { } IGauge* Gauge(ILabelsPtr labels) override; - ILazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) override; + ILazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) override; IIntGauge* IntGauge(ILabelsPtr labels) override; - ILazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) override; + ILazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) override; ICounter* Counter(ILabelsPtr labels) override; - ILazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) override; + ILazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) override; IRate* Rate(ILabelsPtr labels) override; - ILazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) override; + ILazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) override; IHistogram* HistogramCounter( ILabelsPtr labels, @@ -70,12 +70,12 @@ namespace NMonitoring { } }; - struct TFakeLazyIntGauge final: public TFakeAcceptor<ILazyIntGauge> { - i64 Get() const noexcept override { - return 0; - } - }; - + struct TFakeLazyIntGauge final: public TFakeAcceptor<ILazyIntGauge> { + i64 Get() const noexcept override { + return 0; + } + }; + struct TFakeRate final: public TFakeAcceptor<IRate> { ui64 Add(ui64 n) noexcept override { Y_UNUSED(n); @@ -90,12 +90,12 @@ namespace NMonitoring { } }; - struct TFakeLazyRate final: public TFakeAcceptor<ILazyRate> { - ui64 Get() const noexcept override { - return 0; - } - }; - + struct TFakeLazyRate final: public TFakeAcceptor<ILazyRate> { + ui64 Get() const noexcept override { + return 0; + } + }; + struct TFakeGauge final: public TFakeAcceptor<IGauge> { double Add(double n) noexcept override { Y_UNUSED(n); @@ -111,12 +111,12 @@ namespace NMonitoring { } }; - struct TFakeLazyGauge final: public TFakeAcceptor<ILazyGauge> { - double Get() const noexcept override { - return 0; - } - }; - + struct TFakeLazyGauge final: public TFakeAcceptor<ILazyGauge> { + double Get() const noexcept override { + return 0; + } + }; + struct TFakeHistogram final: public IHistogram { TFakeHistogram(bool isRate = false) : IHistogram{isRate} @@ -156,10 +156,10 @@ namespace NMonitoring { void Reset() noexcept override { } }; - - struct TFakeLazyCounter final: public TFakeAcceptor<ILazyCounter> { - ui64 Get() const noexcept override { - return 0; - } - }; + + struct TFakeLazyCounter final: public TFakeAcceptor<ILazyCounter> { + ui64 Get() const noexcept override { + return 0; + } + }; } // namespace NMonitoring diff --git a/library/cpp/monlib/metrics/metric.h b/library/cpp/monlib/metrics/metric.h index b8ce12d753..8794177e7e 100644 --- a/library/cpp/monlib/metrics/metric.h +++ b/library/cpp/monlib/metrics/metric.h @@ -33,14 +33,14 @@ namespace NMonitoring { } }; - class ILazyGauge: public IMetric { - public: - EMetricType Type() const noexcept final { - return EMetricType::GAUGE; - } - virtual double Get() const noexcept = 0; - }; - + class ILazyGauge: public IMetric { + public: + EMetricType Type() const noexcept final { + return EMetricType::GAUGE; + } + virtual double Get() const noexcept = 0; + }; + class IIntGauge: public IMetric { public: EMetricType Type() const noexcept final { @@ -63,15 +63,15 @@ namespace NMonitoring { } }; - class ILazyIntGauge: public IMetric { - public: - EMetricType Type() const noexcept final { - return EMetricType::IGAUGE; - } - - virtual i64 Get() const noexcept = 0; - }; - + class ILazyIntGauge: public IMetric { + public: + EMetricType Type() const noexcept final { + return EMetricType::IGAUGE; + } + + virtual i64 Get() const noexcept = 0; + }; + class ICounter: public IMetric { public: EMetricType Type() const noexcept final { @@ -87,15 +87,15 @@ namespace NMonitoring { virtual void Reset() noexcept = 0; }; - class ILazyCounter: public IMetric { - public: - EMetricType Type() const noexcept final { - return EMetricType::COUNTER; - } - - virtual ui64 Get() const noexcept = 0; - }; - + class ILazyCounter: public IMetric { + public: + EMetricType Type() const noexcept final { + return EMetricType::COUNTER; + } + + virtual ui64 Get() const noexcept = 0; + }; + class IRate: public IMetric { public: EMetricType Type() const noexcept final { @@ -111,15 +111,15 @@ namespace NMonitoring { virtual void Reset() noexcept = 0; }; - class ILazyRate: public IMetric { - public: - EMetricType Type() const noexcept final { - return EMetricType::RATE; - } - - virtual ui64 Get() const noexcept = 0; - }; - + class ILazyRate: public IMetric { + public: + EMetricType Type() const noexcept final { + return EMetricType::RATE; + } + + virtual ui64 Get() const noexcept = 0; + }; + class IHistogram: public IMetric { public: explicit IHistogram(bool isRate) @@ -177,28 +177,28 @@ namespace NMonitoring { }; /////////////////////////////////////////////////////////////////////////////// - // TLazyGauge - /////////////////////////////////////////////////////////////////////////////// - class TLazyGauge final: public ILazyGauge { - public: - explicit TLazyGauge(std::function<double()> supplier) - : Supplier_(std::move(supplier)) - { - } - - double Get() const noexcept override { - return Supplier_(); - } - - void Accept(TInstant time, IMetricConsumer* consumer) const override { - consumer->OnDouble(time, Get()); - } - - private: - std::function<double()> Supplier_; - }; - - /////////////////////////////////////////////////////////////////////////////// + // TLazyGauge + /////////////////////////////////////////////////////////////////////////////// + class TLazyGauge final: public ILazyGauge { + public: + explicit TLazyGauge(std::function<double()> supplier) + : Supplier_(std::move(supplier)) + { + } + + double Get() const noexcept override { + return Supplier_(); + } + + void Accept(TInstant time, IMetricConsumer* consumer) const override { + consumer->OnDouble(time, Get()); + } + + private: + std::function<double()> Supplier_; + }; + + /////////////////////////////////////////////////////////////////////////////// // TIntGauge /////////////////////////////////////////////////////////////////////////////// class TIntGauge final: public IIntGauge { @@ -228,28 +228,28 @@ namespace NMonitoring { }; /////////////////////////////////////////////////////////////////////////////// - // TLazyIntGauge - /////////////////////////////////////////////////////////////////////////////// - class TLazyIntGauge final: public ILazyIntGauge { - public: - explicit TLazyIntGauge(std::function<i64()> supplier) - : Supplier_(std::move(supplier)) - { - } - - i64 Get() const noexcept override { - return Supplier_(); - } - - void Accept(TInstant time, IMetricConsumer* consumer) const override { - consumer->OnInt64(time, Get()); - } - - private: - std::function<i64()> Supplier_; - }; - - /////////////////////////////////////////////////////////////////////////////// + // TLazyIntGauge + /////////////////////////////////////////////////////////////////////////////// + class TLazyIntGauge final: public ILazyIntGauge { + public: + explicit TLazyIntGauge(std::function<i64()> supplier) + : Supplier_(std::move(supplier)) + { + } + + i64 Get() const noexcept override { + return Supplier_(); + } + + void Accept(TInstant time, IMetricConsumer* consumer) const override { + consumer->OnInt64(time, Get()); + } + + private: + std::function<i64()> Supplier_; + }; + + /////////////////////////////////////////////////////////////////////////////// // TCounter /////////////////////////////////////////////////////////////////////////////// class TCounter final: public ICounter { @@ -279,28 +279,28 @@ namespace NMonitoring { }; /////////////////////////////////////////////////////////////////////////////// - // TLazyCounter - /////////////////////////////////////////////////////////////////////////////// - class TLazyCounter final: public ILazyCounter { - public: - explicit TLazyCounter(std::function<ui64()> supplier) - : Supplier_(std::move(supplier)) - { - } - - ui64 Get() const noexcept override { - return Supplier_(); - } - - void Accept(TInstant time, IMetricConsumer* consumer) const override { - consumer->OnUint64(time, Get()); - } - - private: - std::function<ui64()> Supplier_; - }; - - /////////////////////////////////////////////////////////////////////////////// + // TLazyCounter + /////////////////////////////////////////////////////////////////////////////// + class TLazyCounter final: public ILazyCounter { + public: + explicit TLazyCounter(std::function<ui64()> supplier) + : Supplier_(std::move(supplier)) + { + } + + ui64 Get() const noexcept override { + return Supplier_(); + } + + void Accept(TInstant time, IMetricConsumer* consumer) const override { + consumer->OnUint64(time, Get()); + } + + private: + std::function<ui64()> Supplier_; + }; + + /////////////////////////////////////////////////////////////////////////////// // TRate /////////////////////////////////////////////////////////////////////////////// class TRate final: public IRate { @@ -330,28 +330,28 @@ namespace NMonitoring { }; /////////////////////////////////////////////////////////////////////////////// - // TLazyRate - /////////////////////////////////////////////////////////////////////////////// - class TLazyRate final: public ILazyRate { - public: - explicit TLazyRate(std::function<ui64()> supplier) - : Supplier_(std::move(supplier)) - { - } - - ui64 Get() const noexcept override { - return Supplier_(); - } - - void Accept(TInstant time, IMetricConsumer* consumer) const override { - consumer->OnUint64(time, Get()); - } - - private: - std::function<ui64()> Supplier_; - }; - - /////////////////////////////////////////////////////////////////////////////// + // TLazyRate + /////////////////////////////////////////////////////////////////////////////// + class TLazyRate final: public ILazyRate { + public: + explicit TLazyRate(std::function<ui64()> supplier) + : Supplier_(std::move(supplier)) + { + } + + ui64 Get() const noexcept override { + return Supplier_(); + } + + void Accept(TInstant time, IMetricConsumer* consumer) const override { + consumer->OnUint64(time, Get()); + } + + private: + std::function<ui64()> Supplier_; + }; + + /////////////////////////////////////////////////////////////////////////////// // THistogram /////////////////////////////////////////////////////////////////////////////// class THistogram final: public IHistogram { diff --git a/library/cpp/monlib/metrics/metric_registry.cpp b/library/cpp/monlib/metrics/metric_registry.cpp index b083163a7b..7c5245c78a 100644 --- a/library/cpp/monlib/metrics/metric_registry.cpp +++ b/library/cpp/monlib/metrics/metric_registry.cpp @@ -52,14 +52,14 @@ namespace NMonitoring { return Metric<TGauge, EMetricType::GAUGE>(std::move(labels)); } - TLazyGauge* TMetricRegistry::LazyGauge(TLabels labels, std::function<double()> supplier) { - return Metric<TLazyGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); - } - - TLazyGauge* TMetricRegistry::LazyGauge(ILabelsPtr labels, std::function<double()> supplier) { - return Metric<TLazyGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); - } - + TLazyGauge* TMetricRegistry::LazyGauge(TLabels labels, std::function<double()> supplier) { + return Metric<TLazyGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); + } + + TLazyGauge* TMetricRegistry::LazyGauge(ILabelsPtr labels, std::function<double()> supplier) { + return Metric<TLazyGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); + } + TIntGauge* TMetricRegistry::IntGauge(TLabels labels) { return Metric<TIntGauge, EMetricType::IGAUGE>(std::move(labels)); } @@ -68,14 +68,14 @@ namespace NMonitoring { return Metric<TIntGauge, EMetricType::IGAUGE>(std::move(labels)); } - TLazyIntGauge* TMetricRegistry::LazyIntGauge(TLabels labels, std::function<i64()> supplier) { - return Metric<TLazyIntGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); - } - - TLazyIntGauge* TMetricRegistry::LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) { - return Metric<TLazyIntGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); - } - + TLazyIntGauge* TMetricRegistry::LazyIntGauge(TLabels labels, std::function<i64()> supplier) { + return Metric<TLazyIntGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); + } + + TLazyIntGauge* TMetricRegistry::LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) { + return Metric<TLazyIntGauge, EMetricType::GAUGE>(std::move(labels), std::move(supplier)); + } + TCounter* TMetricRegistry::Counter(TLabels labels) { return Metric<TCounter, EMetricType::COUNTER>(std::move(labels)); } @@ -84,14 +84,14 @@ namespace NMonitoring { return Metric<TCounter, EMetricType::COUNTER>(std::move(labels)); } - TLazyCounter* TMetricRegistry::LazyCounter(TLabels labels, std::function<ui64()> supplier) { - return Metric<TLazyCounter, EMetricType::COUNTER>(std::move(labels), std::move(supplier)); - } - - TLazyCounter* TMetricRegistry::LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) { - return Metric<TLazyCounter, EMetricType::COUNTER>(std::move(labels), std::move(supplier)); - } - + TLazyCounter* TMetricRegistry::LazyCounter(TLabels labels, std::function<ui64()> supplier) { + return Metric<TLazyCounter, EMetricType::COUNTER>(std::move(labels), std::move(supplier)); + } + + TLazyCounter* TMetricRegistry::LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) { + return Metric<TLazyCounter, EMetricType::COUNTER>(std::move(labels), std::move(supplier)); + } + TRate* TMetricRegistry::Rate(TLabels labels) { return Metric<TRate, EMetricType::RATE>(std::move(labels)); } @@ -100,14 +100,14 @@ namespace NMonitoring { return Metric<TRate, EMetricType::RATE>(std::move(labels)); } - TLazyRate* TMetricRegistry::LazyRate(TLabels labels, std::function<ui64()> supplier) { - return Metric<TLazyRate, EMetricType::RATE>(std::move(labels), std::move(supplier)); - } - - TLazyRate* TMetricRegistry::LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) { - return Metric<TLazyRate, EMetricType::RATE>(std::move(labels), std::move(supplier)); - } - + TLazyRate* TMetricRegistry::LazyRate(TLabels labels, std::function<ui64()> supplier) { + return Metric<TLazyRate, EMetricType::RATE>(std::move(labels), std::move(supplier)); + } + + TLazyRate* TMetricRegistry::LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) { + return Metric<TLazyRate, EMetricType::RATE>(std::move(labels), std::move(supplier)); + } + THistogram* TMetricRegistry::HistogramCounter(TLabels labels, IHistogramCollectorPtr collector) { return Metric<THistogram, EMetricType::HIST>(std::move(labels), std::move(collector), false); } diff --git a/library/cpp/monlib/metrics/metric_registry.h b/library/cpp/monlib/metrics/metric_registry.h index 670cf8651e..2f288acb97 100644 --- a/library/cpp/monlib/metrics/metric_registry.h +++ b/library/cpp/monlib/metrics/metric_registry.h @@ -14,14 +14,14 @@ namespace NMonitoring { virtual ~IMetricFactory() = default; virtual IGauge* Gauge(ILabelsPtr labels) = 0; - virtual ILazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) = 0; + virtual ILazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) = 0; virtual IIntGauge* IntGauge(ILabelsPtr labels) = 0; - virtual ILazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) = 0; + virtual ILazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) = 0; virtual ICounter* Counter(ILabelsPtr labels) = 0; - virtual ILazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) = 0; - + virtual ILazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) = 0; + virtual IRate* Rate(ILabelsPtr labels) = 0; - virtual ILazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) = 0; + virtual ILazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) = 0; virtual IHistogram* HistogramCounter( ILabelsPtr labels, @@ -63,13 +63,13 @@ namespace NMonitoring { static TMetricRegistry* Instance(); TGauge* Gauge(TLabels labels); - TLazyGauge* LazyGauge(TLabels labels, std::function<double()> supplier); + TLazyGauge* LazyGauge(TLabels labels, std::function<double()> supplier); TIntGauge* IntGauge(TLabels labels); - TLazyIntGauge* LazyIntGauge(TLabels labels, std::function<i64()> supplier); + TLazyIntGauge* LazyIntGauge(TLabels labels, std::function<i64()> supplier); TCounter* Counter(TLabels labels); - TLazyCounter* LazyCounter(TLabels labels, std::function<ui64()> supplier); + TLazyCounter* LazyCounter(TLabels labels, std::function<ui64()> supplier); TRate* Rate(TLabels labels); - TLazyRate* LazyRate(TLabels labels, std::function<ui64()> supplier); + TLazyRate* LazyRate(TLabels labels, std::function<ui64()> supplier); THistogram* HistogramCounter( TLabels labels, @@ -99,13 +99,13 @@ namespace NMonitoring { private: TGauge* Gauge(ILabelsPtr labels) override; - TLazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) override; + TLazyGauge* LazyGauge(ILabelsPtr labels, std::function<double()> supplier) override; TIntGauge* IntGauge(ILabelsPtr labels) override; - TLazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) override; + TLazyIntGauge* LazyIntGauge(ILabelsPtr labels, std::function<i64()> supplier) override; TCounter* Counter(ILabelsPtr labels) override; - TLazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) override; + TLazyCounter* LazyCounter(ILabelsPtr labels, std::function<ui64()> supplier) override; TRate* Rate(ILabelsPtr labels) override; - TLazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) override; + TLazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) override; THistogram* HistogramCounter( ILabelsPtr labels, diff --git a/library/cpp/monlib/metrics/metric_registry_ut.cpp b/library/cpp/monlib/metrics/metric_registry_ut.cpp index 86d9a52ec0..bd3e701635 100644 --- a/library/cpp/monlib/metrics/metric_registry_ut.cpp +++ b/library/cpp/monlib/metrics/metric_registry_ut.cpp @@ -57,24 +57,24 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), val, 1E-6); } - Y_UNIT_TEST(LazyGauge) { - TMetricRegistry registry(TLabels{{"common", "label"}}); - double val = 0.0; - TLazyGauge* g = registry.LazyGauge({{"my", "lazyGauge"}}, [&val](){return val;}); - - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 0.0, 1E-6); - val = 12.34; - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 12.34, 1E-6); - - val += 1.2; - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 13.54, 1E-6); - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), val, 1E-6); - - val += -3.47; - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 10.07, 1E-6); - UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), val, 1E-6); - } - + Y_UNIT_TEST(LazyGauge) { + TMetricRegistry registry(TLabels{{"common", "label"}}); + double val = 0.0; + TLazyGauge* g = registry.LazyGauge({{"my", "lazyGauge"}}, [&val](){return val;}); + + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 0.0, 1E-6); + val = 12.34; + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 12.34, 1E-6); + + val += 1.2; + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 13.54, 1E-6); + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), val, 1E-6); + + val += -3.47; + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), 10.07, 1E-6); + UNIT_ASSERT_DOUBLES_EQUAL(g->Get(), val, 1E-6); + } + Y_UNIT_TEST(IntGauge) { TMetricRegistry registry(TLabels{{"common", "label"}}); TIntGauge* g = registry.IntGauge({{"my", "gauge"}}); @@ -104,24 +104,24 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); } - Y_UNIT_TEST(LazyIntGauge) { - TMetricRegistry registry(TLabels{{"common", "label"}}); - i64 val = 0; - TLazyIntGauge* g = registry.LazyIntGauge({{"my", "gauge"}}, [&val](){return val;}); - - UNIT_ASSERT_VALUES_EQUAL(g->Get(), 0); - val += 1; - UNIT_ASSERT_VALUES_EQUAL(g->Get(), 1); - UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); - - val -= 1; - UNIT_ASSERT_VALUES_EQUAL(g->Get(), 0); - UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); - - val = 42; - UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); - } - + Y_UNIT_TEST(LazyIntGauge) { + TMetricRegistry registry(TLabels{{"common", "label"}}); + i64 val = 0; + TLazyIntGauge* g = registry.LazyIntGauge({{"my", "gauge"}}, [&val](){return val;}); + + UNIT_ASSERT_VALUES_EQUAL(g->Get(), 0); + val += 1; + UNIT_ASSERT_VALUES_EQUAL(g->Get(), 1); + UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); + + val -= 1; + UNIT_ASSERT_VALUES_EQUAL(g->Get(), 0); + UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); + + val = 42; + UNIT_ASSERT_VALUES_EQUAL(g->Get(), val); + } + Y_UNIT_TEST(Counter) { TMetricRegistry registry(TLabels{{"common", "label"}}); TCounter* c = registry.Counter({{"my", "counter"}}); @@ -133,28 +133,28 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { UNIT_ASSERT_VALUES_EQUAL(c->Get(), 11); } - Y_UNIT_TEST(LazyCounter) { - TMetricRegistry registry(TLabels{{"common", "label"}}); - ui64 val = 0; - - TLazyCounter* c = registry.LazyCounter({{"my", "counter"}}, [&val](){return val;}); - - UNIT_ASSERT_VALUES_EQUAL(c->Get(), 0); - val = 42; - UNIT_ASSERT_VALUES_EQUAL(c->Get(), 42); - } - - Y_UNIT_TEST(LazyRate) { - TMetricRegistry registry(TLabels{{"common", "label"}}); - ui64 val = 0; - - TLazyRate* r = registry.LazyRate({{"my", "rate"}}, [&val](){return val;}); - - UNIT_ASSERT_VALUES_EQUAL(r->Get(), 0); - val = 42; - UNIT_ASSERT_VALUES_EQUAL(r->Get(), 42); - } - + Y_UNIT_TEST(LazyCounter) { + TMetricRegistry registry(TLabels{{"common", "label"}}); + ui64 val = 0; + + TLazyCounter* c = registry.LazyCounter({{"my", "counter"}}, [&val](){return val;}); + + UNIT_ASSERT_VALUES_EQUAL(c->Get(), 0); + val = 42; + UNIT_ASSERT_VALUES_EQUAL(c->Get(), 42); + } + + Y_UNIT_TEST(LazyRate) { + TMetricRegistry registry(TLabels{{"common", "label"}}); + ui64 val = 0; + + TLazyRate* r = registry.LazyRate({{"my", "rate"}}, [&val](){return val;}); + + UNIT_ASSERT_VALUES_EQUAL(r->Get(), 0); + val = 42; + UNIT_ASSERT_VALUES_EQUAL(r->Get(), 42); + } + Y_UNIT_TEST(DoubleCounter) { TMetricRegistry registry(TLabels{{"common", "label"}}); diff --git a/library/cpp/monlib/metrics/metric_type.h b/library/cpp/monlib/metrics/metric_type.h index 1984c42c1e..7849aab721 100644 --- a/library/cpp/monlib/metrics/metric_type.h +++ b/library/cpp/monlib/metrics/metric_type.h @@ -15,8 +15,8 @@ namespace NMonitoring { HIST = 5, HIST_RATE = 6, DSUMMARY = 7, - // ISUMMARY = 8, reserved - LOGHIST = 9, + // ISUMMARY = 8, reserved + LOGHIST = 9, }; TStringBuf MetricTypeToStr(EMetricType type); |