diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/monlib/metrics/metric_sub_registry_ut.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/monlib/metrics/metric_sub_registry_ut.cpp')
-rw-r--r-- | library/cpp/monlib/metrics/metric_sub_registry_ut.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/library/cpp/monlib/metrics/metric_sub_registry_ut.cpp b/library/cpp/monlib/metrics/metric_sub_registry_ut.cpp new file mode 100644 index 0000000000..0c5d48b876 --- /dev/null +++ b/library/cpp/monlib/metrics/metric_sub_registry_ut.cpp @@ -0,0 +1,65 @@ +#include "metric_sub_registry.h" + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NMonitoring; + +Y_UNIT_TEST_SUITE(TMetricSubRegistryTest) { + Y_UNIT_TEST(WrapRegistry) { + TMetricRegistry registry; + + { + TMetricSubRegistry subRegistry{{{"common", "label"}}, ®istry}; + IIntGauge* g = subRegistry.IntGauge(MakeLabels({{"my", "gauge"}})); + UNIT_ASSERT(g); + g->Set(42); + } + + TIntGauge* g = registry.IntGauge({{"my", "gauge"}, {"common", "label"}}); + UNIT_ASSERT(g); + UNIT_ASSERT_VALUES_EQUAL(g->Get(), 42); + } + + Y_UNIT_TEST(CommonLabelsDoNotOverrideGeneralLabel) { + TMetricRegistry registry; + + { + TMetricSubRegistry subRegistry{{{"common", "label"}, {"my", "notOverride"}}, ®istry}; + IIntGauge* g = subRegistry.IntGauge(MakeLabels({{"my", "gauge"}})); + UNIT_ASSERT(g); + g->Set(1234); + } + + TIntGauge* knownGauge = registry.IntGauge({{"my", "gauge"}, {"common", "label"}}); + UNIT_ASSERT(knownGauge); + UNIT_ASSERT_VALUES_EQUAL(knownGauge->Get(), 1234); + + TIntGauge* newGauge = registry.IntGauge({{"common", "label"}, {"my", "notOverride"}}); + UNIT_ASSERT(newGauge); + UNIT_ASSERT_VALUES_EQUAL(newGauge->Get(), 0); + } + + Y_UNIT_TEST(RemoveMetric) { + TMetricRegistry registry; + + { + TMetricSubRegistry subRegistry{{{"common", "label"}}, ®istry}; + IIntGauge* g = subRegistry.IntGauge(MakeLabels({{"my", "gauge"}})); + UNIT_ASSERT(g); + g->Set(1234); + } + + IIntGauge* g1 = registry.IntGauge({{"my", "gauge"}, {"common", "label"}}); + UNIT_ASSERT(g1); + UNIT_ASSERT_VALUES_EQUAL(g1->Get(), 1234); + + { + TMetricSubRegistry subRegistry{{{"common", "label"}}, ®istry}; + subRegistry.RemoveMetric(TLabels{{"my", "gauge"}}); + } + + IIntGauge* g2 = registry.IntGauge({{"my", "gauge"}, {"common", "label"}}); + UNIT_ASSERT(g2); + UNIT_ASSERT_VALUES_EQUAL(g2->Get(), 0); + } +} |