diff options
author | monster <monster@ydb.tech> | 2022-11-22 22:28:32 +0300 |
---|---|---|
committer | monster <monster@ydb.tech> | 2022-11-22 22:28:32 +0300 |
commit | 8ce89cc8436ea7052bbed327149cd6be12987f53 (patch) | |
tree | 9e592addcaffd4f964ba9a6e3712e52e86d8ec40 | |
parent | caf8bbcb03bda3879cf4ce405b587b813878196e (diff) | |
download | ydb-8ce89cc8436ea7052bbed327149cd6be12987f53.tar.gz |
fix grpc proxy RU-related counters
-rw-r--r-- | ydb/core/grpc_services/counters/proxy_counters.cpp | 25 | ||||
-rw-r--r-- | ydb/core/grpc_services/grpc_request_check_actor.h | 17 |
2 files changed, 23 insertions, 19 deletions
diff --git a/ydb/core/grpc_services/counters/proxy_counters.cpp b/ydb/core/grpc_services/counters/proxy_counters.cpp index 893a4c5f2b1..652dd265a69 100644 --- a/ydb/core/grpc_services/counters/proxy_counters.cpp +++ b/ydb/core/grpc_services/counters/proxy_counters.cpp @@ -12,6 +12,8 @@ namespace NGRpcService { class TGRpcProxyCounters : public IGRpcProxyCounters { protected: + ::NMonitoring::TDynamicCounterPtr Root_; + ::NMonitoring::TDynamicCounters::TCounterPtr DatabaseAccessDenyCounter_; ::NMonitoring::TDynamicCounters::TCounterPtr DatabaseSchemeErrorCounter_; ::NMonitoring::TDynamicCounters::TCounterPtr DatabaseUnavailableCounter_; @@ -22,12 +24,14 @@ protected: public: using TPtr = TIntrusivePtr<TGRpcProxyCounters>; - TGRpcProxyCounters(::NMonitoring::TDynamicCounterPtr counters, bool forDatabase) { + TGRpcProxyCounters(::NMonitoring::TDynamicCounterPtr root, bool forDatabase) + : Root_(root) + { ::NMonitoring::TDynamicCounterPtr group; if (forDatabase) { - group = counters; + group = Root_; } else { - group = GetServiceCounters(counters, "grpc"); + group = GetServiceCounters(Root_, "grpc"); } DatabaseAccessDenyCounter_ = group->GetCounter("databaseAccessDeny", true); @@ -126,6 +130,10 @@ class TGRpcProxyDbCounters : public TGRpcProxyCounters, public NSysView::IDbCoun public: using TPtr = TIntrusivePtr<TGRpcProxyDbCounters>; + TGRpcProxyDbCounters() + : TGRpcProxyCounters(new ::NMonitoring::TDynamicCounters, true) + {} + explicit TGRpcProxyDbCounters(::NMonitoring::TDynamicCounterPtr counters) : TGRpcProxyCounters(counters, true) {} @@ -183,7 +191,6 @@ public: class TGRpcProxyDbCountersRegistry { - ::NMonitoring::TDynamicCounterPtr Root; TConcurrentRWHashMap<TString, TGRpcProxyDbCounters::TPtr, 256> DbCounters; TActorSystem* ActorSystem = {}; TActorId DbWatcherActorId; @@ -196,10 +203,6 @@ class TGRpcProxyDbCountersRegistry { }; public: - TGRpcProxyDbCountersRegistry() - : Root(new ::NMonitoring::TDynamicCounters) - {} - void Initialize(TActorSystem* actorSystem) { if (Y_LIKELY(ActorSystem)) { return; @@ -217,7 +220,7 @@ public: } dbCounters = DbCounters.InsertIfAbsentWithInit(database, [&database, this] { - auto counters = MakeIntrusive<TGRpcProxyDbCounters>(Root); + auto counters = MakeIntrusive<TGRpcProxyDbCounters>(); if (ActorSystem) { auto evRegister = MakeHolder<NSysView::TEvSysView::TEvRegisterDbCounters>( @@ -245,14 +248,12 @@ public: class TGRpcProxyCountersWrapper : public IGRpcProxyCounters { IGRpcProxyCounters::TPtr Common; - ::NMonitoring::TDynamicCounterPtr Root; TGRpcProxyDbCounters::TPtr Db; public: explicit TGRpcProxyCountersWrapper(IGRpcProxyCounters::TPtr common) : Common(common) - , Root(new ::NMonitoring::TDynamicCounters) - , Db(new TGRpcProxyDbCounters(Root)) + , Db(new TGRpcProxyDbCounters()) {} void IncDatabaseAccessDenyCounter() override { diff --git a/ydb/core/grpc_services/grpc_request_check_actor.h b/ydb/core/grpc_services/grpc_request_check_actor.h index fe0902b4e43..e1cd950744e 100644 --- a/ydb/core/grpc_services/grpc_request_check_actor.h +++ b/ydb/core/grpc_services/grpc_request_check_actor.h @@ -105,6 +105,11 @@ public: GrpcRequestBaseCtx_->SetCounters(Counters_); + if (!CheckedDatabaseName_.empty()) { + GrpcRequestBaseCtx_->UseDatabase(CheckedDatabaseName_); + Counters_->UseDatabase(CheckedDatabaseName_); + } + { auto [error, issue] = CheckConnectRight(); if (error) { @@ -181,7 +186,7 @@ public: if (!RlConfig) { // No rate limit config for this request - return SetTokenAndDie(CheckedDatabaseName_); + return SetTokenAndDie(); } else { THashMap<TString, TString> attributes; for (const auto& [attrName, attrValue] : Attributes_) { @@ -191,11 +196,9 @@ public: } } - void SetTokenAndDie(const TString& database = {}) { + void SetTokenAndDie() { GrpcRequestBaseCtx_->UpdateAuthState(NGrpc::TAuthState::AS_OK); GrpcRequestBaseCtx_->SetInternalToken(TBase::GetSerializedToken()); - GrpcRequestBaseCtx_->UseDatabase(database); - Counters_->UseDatabase(database); ReplyBackAndDie(); } @@ -229,7 +232,7 @@ private: case Ydb::StatusIds::SUCCESS: Counters_->ReportThrottleDelay(delay); LOG_DEBUG_S(*TlsActivationContext, NKikimrServices::GRPC_SERVER, "Request delayed for " << delay << " by ratelimiter"); - SetTokenAndDie(CheckedDatabaseName_); + SetTokenAndDie(); break; case Ydb::StatusIds::TIMEOUT: Counters_->IncDatabaseRateLimitedCounter(); @@ -296,7 +299,7 @@ private: // Match rate limit config and database attributes auto rlPath = NRpcService::Match(*RlConfig, attributes); if (!rlPath) { - return SetTokenAndDie(CheckedDatabaseName_); + return SetTokenAndDie(); } else { auto actions = NRpcService::MakeRequests(*RlConfig, rlPath.GetRef()); GrpcRequestBaseCtx_->SetRlPath(std::move(rlPath)); @@ -318,7 +321,7 @@ private: if (hasOnReqAction) { return ProcessOnRequest(std::move(req), ctx); } else { - return SetTokenAndDie(CheckedDatabaseName_); + return SetTokenAndDie(); } } } |