diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-28 22:13:30 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-06-28 22:13:30 +0300 |
commit | 4a1a5df355bdd769225c8086601b4cdf5a651b00 (patch) | |
tree | df36db92a40b10f9c374f349a27e9b9ffe1dafee | |
parent | 04cb855dd32a856dab4ec1f0695c88b170c50d58 (diff) | |
download | ydb-4a1a5df355bdd769225c8086601b4cdf5a651b00.tar.gz |
intermediate changes
ref:08d0f6ebc75701201720c15ba8b41bfbdf780a37
-rw-r--r-- | build/ya.conf.json | 2 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/fake.cpp | 15 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/fake.h | 13 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry.cpp | 14 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry.h | 26 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_registry_ut.cpp | 14 | ||||
-rw-r--r-- | library/cpp/monlib/metrics/metric_sub_registry.h | 19 |
7 files changed, 53 insertions, 50 deletions
diff --git a/build/ya.conf.json b/build/ya.conf.json index d54ab82ffa..e4b34ed08b 100644 --- a/build/ya.conf.json +++ b/build/ya.conf.json @@ -7740,7 +7740,7 @@ }, "infractl": { "formula": { - "sandbox_id": 1352440693, + "sandbox_id": 1357821280, "match": "infractl" }, "executable": { diff --git a/library/cpp/monlib/metrics/fake.cpp b/library/cpp/monlib/metrics/fake.cpp index cbfa1dc031..c43fc647e4 100644 --- a/library/cpp/monlib/metrics/fake.cpp +++ b/library/cpp/monlib/metrics/fake.cpp @@ -43,16 +43,16 @@ namespace NMonitoring { return Metric<TFakeHistogram, EMetricType::HIST>(std::move(labels), false); } + IHistogram* TFakeMetricRegistry::HistogramCounter(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> collector) { + Y_UNUSED(collector); + return Metric<TFakeHistogram, EMetricType::HIST>(std::move(labels), false); + } + void TFakeMetricRegistry::RemoveMetric(const ILabels& labels) noexcept { TWriteGuard g{Lock_}; Metrics_.erase(labels); } - bool TFakeMetricRegistry::HasMetric(const ILabels &labels) noexcept { - TReadGuard g{Lock_}; - return Metrics_.contains(labels); - } - void TFakeMetricRegistry::Accept(TInstant time, IMetricConsumer* consumer) const { Y_UNUSED(time); consumer->OnStreamBegin(); @@ -64,6 +64,11 @@ namespace NMonitoring { return Metric<TFakeHistogram, EMetricType::HIST_RATE>(std::move(labels), true); } + IHistogram* TFakeMetricRegistry::HistogramRate(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> collector) { + Y_UNUSED(collector); + return Metric<TFakeHistogram, EMetricType::HIST_RATE>(std::move(labels), true); + } + void TFakeMetricRegistry::Append(TInstant time, IMetricConsumer* consumer) const { Y_UNUSED(time, consumer); } diff --git a/library/cpp/monlib/metrics/fake.h b/library/cpp/monlib/metrics/fake.h index a75117dece..b61f80fb41 100644 --- a/library/cpp/monlib/metrics/fake.h +++ b/library/cpp/monlib/metrics/fake.h @@ -26,18 +26,25 @@ namespace NMonitoring { ILazyRate* LazyRate(ILabelsPtr labels, std::function<ui64()> supplier) override; IHistogram* HistogramCounter( - ILabelsPtr labels, - IHistogramCollectorPtr collector) override; + ILabelsPtr labels, + IHistogramCollectorPtr collector) override; IHistogram* HistogramRate( ILabelsPtr labels, IHistogramCollectorPtr collector) override; + + IHistogram* HistogramCounter( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> collector) override; + + IHistogram* HistogramRate( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> collector) override; void Accept(TInstant time, IMetricConsumer* consumer) const override; void Append(TInstant time, IMetricConsumer* consumer) const override; const TLabels& CommonLabels() const noexcept override; void RemoveMetric(const ILabels& labels) noexcept override; - bool HasMetric(const ILabels &labels) noexcept override; private: TRWMutex Lock_; diff --git a/library/cpp/monlib/metrics/metric_registry.cpp b/library/cpp/monlib/metrics/metric_registry.cpp index 9a09a78d6b..b986f40249 100644 --- a/library/cpp/monlib/metrics/metric_registry.cpp +++ b/library/cpp/monlib/metrics/metric_registry.cpp @@ -128,8 +128,8 @@ namespace NMonitoring { return Metric<THistogram, EMetricType::HIST>(std::move(labels), std::move(supplier), false); } - THistogram* TMetricRegistry::HistogramCounter(TLabels labels, nullptr_t) { - return HistogramCounter(std::move(labels), IHistogramCollectorPtr(nullptr)); + THistogram* TMetricRegistry::HistogramCounter(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> supplier) { + return Metric<THistogram, EMetricType::HIST>(std::move(labels), std::move(supplier), false); } THistogram* TMetricRegistry::HistogramRate(TLabels labels, IHistogramCollectorPtr collector) { @@ -144,8 +144,8 @@ namespace NMonitoring { return Metric<THistogram, EMetricType::HIST_RATE>(std::move(labels), std::move(supplier), true); } - THistogram* TMetricRegistry::HistogramRate(TLabels labels, nullptr_t) { - return HistogramRate(std::move(labels), IHistogramCollectorPtr(nullptr)); + THistogram* TMetricRegistry::HistogramRate(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> supplier) { + return Metric<THistogram, EMetricType::HIST_RATE>(std::move(labels), std::move(supplier), true); } void TMetricRegistry::Reset() { @@ -216,12 +216,6 @@ namespace NMonitoring { Metrics_.erase(labels); } - bool TMetricRegistry::HasMetric(const ILabels &labels) noexcept { - TReadGuard g{*Lock_}; - - return Metrics_.contains(labels); - } - void TMetricRegistry::Accept(TInstant time, IMetricConsumer* consumer) const { consumer->OnStreamBegin(); diff --git a/library/cpp/monlib/metrics/metric_registry.h b/library/cpp/monlib/metrics/metric_registry.h index 4000ed6803..f61db6ce5f 100644 --- a/library/cpp/monlib/metrics/metric_registry.h +++ b/library/cpp/monlib/metrics/metric_registry.h @@ -30,6 +30,14 @@ namespace NMonitoring { virtual IHistogram* HistogramRate( ILabelsPtr labels, IHistogramCollectorPtr collector) = 0; + + virtual IHistogram* HistogramCounter( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> makeHistogramCollector) = 0; + + virtual IHistogram* HistogramRate( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> makeHistogramCollector) = 0; }; class IMetricSupplier { @@ -44,7 +52,6 @@ namespace NMonitoring { public: virtual const TLabels& CommonLabels() const noexcept = 0; virtual void RemoveMetric(const ILabels& labels) noexcept = 0; - virtual bool HasMetric(const ILabels& labels) noexcept = 0; }; @@ -94,14 +101,6 @@ namespace NMonitoring { TLabels labels, std::function<IHistogramCollectorPtr()> makeHistogramCollector); - THistogram* HistogramCounter( - TLabels labels, - nullptr_t); - - THistogram* HistogramRate( - TLabels labels, - nullptr_t); - /** * Set all registered metrics to zero */ @@ -119,7 +118,6 @@ namespace NMonitoring { } void RemoveMetric(const ILabels& labels) noexcept override; - bool HasMetric(const ILabels &labels) noexcept override; private: TGauge* Gauge(ILabelsPtr labels) override; @@ -139,6 +137,14 @@ namespace NMonitoring { ILabelsPtr labels, IHistogramCollectorPtr collector) override; + THistogram* HistogramCounter( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> makeHistogramCollector) override; + + THistogram* HistogramRate( + ILabelsPtr labels, + std::function<IHistogramCollectorPtr()> makeHistogramCollector) override; + private: THolder<TRWMutex> Lock_ = MakeHolder<TRWMutex>(); THashMap<ILabelsPtr, IMetricPtr> Metrics_; diff --git a/library/cpp/monlib/metrics/metric_registry_ut.cpp b/library/cpp/monlib/metrics/metric_registry_ut.cpp index 0f0dbf0e6e..22bb8f0fe2 100644 --- a/library/cpp/monlib/metrics/metric_registry_ut.cpp +++ b/library/cpp/monlib/metrics/metric_registry_ut.cpp @@ -304,8 +304,8 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { registry.Gauge({{"foo", "bar"}}); UNIT_ASSERT_EXCEPTION(registry.Counter({{"foo", "bar"}}), yexception); - registry.HistogramCounter({{"bar", "baz"}}, nullptr); - UNIT_ASSERT_EXCEPTION(registry.HistogramRate({{"bar", "baz"}}, nullptr), yexception); + registry.HistogramCounter({{"bar", "baz"}}, ExponentialHistogram(5, 2)); + UNIT_ASSERT_EXCEPTION(registry.HistogramRate({{"bar", "baz"}}, ExponentialHistogram(5, 2)), yexception); } Y_UNIT_TEST(EncodeRegistryWithCommonLabels) { @@ -382,14 +382,4 @@ Y_UNIT_TEST_SUITE(TMetricRegistryTest) { UNIT_ASSERT(commonLabels[0].GetName() == "common"); UNIT_ASSERT(commonLabels[0].GetValue() == "label"); } - - Y_UNIT_TEST(HasMetricTest) { - TMetricRegistry registry; - TLabels labels{{"some", "labels"}}; - TLabels anotherLabels{{"another", "label"}}; - - registry.Gauge(labels); - UNIT_ASSERT_EQUAL(registry.HasMetric(labels), true); - UNIT_ASSERT_EQUAL(registry.HasMetric(anotherLabels), false); - } } diff --git a/library/cpp/monlib/metrics/metric_sub_registry.h b/library/cpp/monlib/metrics/metric_sub_registry.h index 36f8e0e639..d1860c00a9 100644 --- a/library/cpp/monlib/metrics/metric_sub_registry.h +++ b/library/cpp/monlib/metrics/metric_sub_registry.h @@ -79,6 +79,16 @@ public: return DelegatePtr_->HistogramRate(std::move(labels), std::move(collector)); } + IHistogram* HistogramCounter(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> collector) override { + AddCommonLabels(labels.Get()); + return DelegatePtr_->HistogramCounter(std::move(labels), std::move(collector)); + } + + IHistogram* HistogramRate(ILabelsPtr labels, std::function<IHistogramCollectorPtr()> collector) override { + AddCommonLabels(labels.Get()); + return DelegatePtr_->HistogramRate(std::move(labels), std::move(collector)); + } + void Accept(TInstant time, IMetricConsumer* consumer) const override { DelegatePtr_->Accept(time, consumer); } @@ -100,15 +110,6 @@ public: DelegatePtr_->RemoveMetric(toRemove); } - bool HasMetric(const ILabels &labels) noexcept override { - TLabelsImpl<TStringBuf> toCheck; - for (auto& l: labels) { - toCheck.Add(l); - } - AddCommonLabels(&toCheck); - return DelegatePtr_->HasMetric(toCheck); - } - private: void AddCommonLabels(ILabels* labels) const { for (auto& label: CommonLabels_) { |