diff options
author | hcpp <hcpp@ydb.tech> | 2022-10-03 15:05:11 +0300 |
---|---|---|
committer | hcpp <hcpp@ydb.tech> | 2022-10-03 15:05:11 +0300 |
commit | 5ff7dea50cb4e4fae89d588641dc282e21338d54 (patch) | |
tree | 9c33c0091148fe24fddcd611e7a2445dd8ee5e0a | |
parent | 13d4d93b54c59bbaac9b0b8bcac6d97ef591dcc8 (diff) | |
download | ydb-5ff7dea50cb4e4fae89d588641dc282e21338d54.tar.gz |
ttl for proxy metrics has been added
-rw-r--r-- | ydb/core/yq/libs/control_plane_proxy/control_plane_proxy.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/ydb/core/yq/libs/control_plane_proxy/control_plane_proxy.cpp b/ydb/core/yq/libs/control_plane_proxy/control_plane_proxy.cpp index 395a8dd4a67..b3bfbe54a81 100644 --- a/ydb/core/yq/libs/control_plane_proxy/control_plane_proxy.cpp +++ b/ydb/core/yq/libs/control_plane_proxy/control_plane_proxy.cpp @@ -497,6 +497,8 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane } }; + TDuration MetricsTtl = TDuration::Days(1); + using TScopeCounters = std::array<TRequestScopeCountersPtr, RTS_MAX>; using TScopeCountersPtr = std::shared_ptr<TScopeCounters>; @@ -525,7 +527,13 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane { MakeIntrusive<TRequestCommonCounters>("DeleteBinding") }, }); - TMap<TMetricsScope, TScopeCountersPtr> ScopeCounters; + struct TScopeValue { + TScopeCountersPtr Counters; + TInstant LastAccess; + }; + + TMap<TMetricsScope, TScopeValue> ScopeCounters; + TMap<TInstant, TSet<TMetricsScope>> LastAccess; ::NMonitoring::TDynamicCounterPtr Counters; public: @@ -537,6 +545,17 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane } } + void CleanupByTtl() { + auto now = TInstant::Now(); + auto it = LastAccess.begin(); + for (; it != LastAccess.end() && (now - it->first) > MetricsTtl; ++it) { + for (const auto& scope: it->second) { + ScopeCounters.erase(scope); + } + } + LastAccess.erase(LastAccess.begin(), it); + } + TRequestCounters GetCounters(const TString& cloudId, const TString& scope, ERequestTypeScope scopeType, ERequestTypeCommon commonType) { return {GetScopeCounters(cloudId, scope, scopeType), GetCommonCounters(commonType)}; } @@ -546,10 +565,19 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane } TRequestScopeCountersPtr GetScopeCounters(const TString& cloudId, const TString& scope, ERequestTypeScope type) { + CleanupByTtl(); TMetricsScope key{cloudId, scope}; auto it = ScopeCounters.find(key); if (it != ScopeCounters.end()) { - return (*it->second)[type]; + auto& value = it->second; + auto& l = LastAccess[value.LastAccess]; + l.erase(key); + if (l.empty()) { + LastAccess.erase(value.LastAccess); + } + value.LastAccess = TInstant::Now(); + LastAccess[value.LastAccess].insert(key); + return (*value.Counters)[type]; } auto scopeRequests = std::make_shared<TScopeCounters>(CreateArray<RTS_MAX, TRequestScopeCountersPtr>({ @@ -583,8 +611,9 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane for (auto& request: *scopeRequests) { request->Register(scopeCounters); } - - ScopeCounters[key] = scopeRequests; + auto now = TInstant::Now(); + LastAccess[now].insert(key); + ScopeCounters[key] = TScopeValue{scopeRequests, now}; return (*scopeRequests)[type]; } }; |