diff options
author | alexvru <alexvru@ydb.tech> | 2023-05-11 22:04:47 +0300 |
---|---|---|
committer | alexvru <alexvru@ydb.tech> | 2023-05-11 22:04:47 +0300 |
commit | 5e0a5156b18c5dcc21eb2aa3cd53274135de124f (patch) | |
tree | e046120984bec2f5c80ec1b2071973ffd280aaaa /library | |
parent | 7df1977a606ccd826561ecb88ee0f35ddf92e0f9 (diff) | |
download | ydb-5e0a5156b18c5dcc21eb2aa3cd53274135de124f.tar.gz |
Remove counters upon VDisk destruction
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/monlib/dynamic_counters/counters.cpp | 18 | ||||
-rw-r--r-- | library/cpp/monlib/dynamic_counters/counters.h | 5 |
2 files changed, 19 insertions, 4 deletions
diff --git a/library/cpp/monlib/dynamic_counters/counters.cpp b/library/cpp/monlib/dynamic_counters/counters.cpp index 3635d87d0d..8cc6f6e835 100644 --- a/library/cpp/monlib/dynamic_counters/counters.cpp +++ b/library/cpp/monlib/dynamic_counters/counters.cpp @@ -106,11 +106,24 @@ void TDynamicCounters::RemoveCounter(const TString &value) { RemoveNamedCounter("sensor", value); } -void TDynamicCounters::RemoveNamedCounter(const TString& name, const TString &value) { +bool TDynamicCounters::RemoveNamedCounter(const TString& name, const TString &value) { auto g = LockForUpdate("RemoveNamedCounter", name, value); if (const auto it = Counters.find({name, value}); it != Counters.end() && AsCounter(it->second)) { Counters.erase(it); } + return Counters.empty(); +} + +void TDynamicCounters::RemoveSubgroupChain(const std::vector<std::pair<TString, TString>>& chain) { + std::vector<TIntrusivePtr<TDynamicCounters>> basePointers; + basePointers.push_back(this); + for (size_t i = 0; i < chain.size() - 1; ++i) { + const auto& [name, value] = chain[i]; + auto& base = basePointers.back(); + basePointers.push_back(base->GetSubgroup(name, value)); + Y_VERIFY(basePointers.back()); + } + for (size_t i = chain.size(); i-- && basePointers[i]->RemoveSubgroup(chain[i].first, chain[i].second); ) {} } TIntrusivePtr<TDynamicCounters> TDynamicCounters::GetSubgroup(const TString& name, const TString& value) { @@ -134,11 +147,12 @@ TIntrusivePtr<TDynamicCounters> TDynamicCounters::FindSubgroup(const TString& na return it != Counters.end() ? AsDynamicCounters(it->second) : nullptr; } -void TDynamicCounters::RemoveSubgroup(const TString& name, const TString& value) { +bool TDynamicCounters::RemoveSubgroup(const TString& name, const TString& value) { auto g = LockForUpdate("RemoveSubgroup", name, value); if (const auto it = Counters.find({name, value}); it != Counters.end() && AsDynamicCounters(it->second)) { Counters.erase(it); } + return Counters.empty(); } void TDynamicCounters::ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup) { diff --git a/library/cpp/monlib/dynamic_counters/counters.h b/library/cpp/monlib/dynamic_counters/counters.h index 3bf89c5098..b15566c034 100644 --- a/library/cpp/monlib/dynamic_counters/counters.h +++ b/library/cpp/monlib/dynamic_counters/counters.h @@ -327,11 +327,12 @@ namespace NMonitoring { THistogramPtr FindNamedHistogram(const TString& name,const TString& value) const; void RemoveCounter(const TString &value); - void RemoveNamedCounter(const TString& name, const TString &value); + bool RemoveNamedCounter(const TString& name, const TString &value); + void RemoveSubgroupChain(const std::vector<std::pair<TString, TString>>& chain); TIntrusivePtr<TDynamicCounters> GetSubgroup(const TString& name, const TString& value); TIntrusivePtr<TDynamicCounters> FindSubgroup(const TString& name, const TString& value) const; - void RemoveSubgroup(const TString& name, const TString& value); + bool RemoveSubgroup(const TString& name, const TString& value); void ReplaceSubgroup(const TString& name, const TString& value, TIntrusivePtr<TDynamicCounters> subgroup); // Move all counters from specified subgroup and remove the subgroup. |