diff options
author | babenko <babenko@yandex-team.com> | 2024-07-15 01:31:21 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-07-15 02:02:40 +0300 |
commit | 7adf3c8baaf911476724452934b94f91111e6bb9 (patch) | |
tree | eacac3aae997f3c7486c8cb1feba3645426bad1c | |
parent | 2059b14708ae359a6f6a5fccff4fd833cd2e7ecf (diff) | |
download | ydb-7adf3c8baaf911476724452934b94f91111e6bb9.tar.gz |
Polish error code profiling
4c72bfd49c9b76d724300c8e13f051816ec09e86
-rw-r--r-- | yt/yt/core/rpc/config.cpp | 11 | ||||
-rw-r--r-- | yt/yt/core/rpc/config.h | 6 | ||||
-rw-r--r-- | yt/yt/core/rpc/server_detail.cpp | 2 | ||||
-rw-r--r-- | yt/yt/core/rpc/service_detail.cpp | 21 | ||||
-rw-r--r-- | yt/yt/core/rpc/service_detail.h | 23 |
5 files changed, 37 insertions, 26 deletions
diff --git a/yt/yt/core/rpc/config.cpp b/yt/yt/core/rpc/config.cpp index 83b7e6835a..a44dd1f55c 100644 --- a/yt/yt/core/rpc/config.cpp +++ b/yt/yt/core/rpc/config.cpp @@ -30,7 +30,8 @@ void TServiceCommonConfig::Register(TRegistrar registrar) .Default(false); registrar.Parameter("histogram_timer_profiling", &TThis::HistogramTimerProfiling) .Default(); - registrar.Parameter("code_counting", &TThis::EnableErrorCodeCounting) + registrar.Parameter("enable_error_code_counter", &TThis::EnableErrorCodeCounter) + .Alias("code_counting") .Default(false); registrar.Parameter("tracing_mode", &TThis::TracingMode) .Default(ERequestTracingMode::Enable); @@ -44,8 +45,9 @@ void TServiceCommonDynamicConfig::Register(TRegistrar registrar) .Default(); registrar.Parameter("histogram_timer_profiling", &TThis::HistogramTimerProfiling) .Default(); - registrar.Parameter("code_counting", &TThis::EnableErrorCodeCounting) - .Default(); + registrar.Parameter("enable_error_code_counter", &TThis::EnableErrorCodeCounter) + .Alias("code_counting") + .Default(false); registrar.Parameter("tracing_mode", &TThis::TracingMode) .Default(); } @@ -72,7 +74,8 @@ void TServiceConfig::Register(TRegistrar registrar) { registrar.Parameter("enable_per_user_profiling", &TThis::EnablePerUserProfiling) .Optional(); - registrar.Parameter("code_counting", &TThis::EnableErrorCodeCounting) + registrar.Parameter("enable_error_code_counter", &TThis::EnableErrorCodeCounter) + .Alias("code_counting") .Optional(); registrar.Parameter("histogram_timer_profiling", &TThis::HistogramTimerProfiling) .Default(); diff --git a/yt/yt/core/rpc/config.h b/yt/yt/core/rpc/config.h index 824d238132..0b1643da5b 100644 --- a/yt/yt/core/rpc/config.h +++ b/yt/yt/core/rpc/config.h @@ -63,7 +63,7 @@ class TServiceCommonConfig public: bool EnablePerUserProfiling; THistogramConfigPtr HistogramTimerProfiling; - bool EnableErrorCodeCounting; + bool EnableErrorCodeCounter; ERequestTracingMode TracingMode; REGISTER_YSON_STRUCT(TServiceCommonConfig); @@ -97,7 +97,7 @@ class TServiceCommonDynamicConfig public: std::optional<bool> EnablePerUserProfiling; std::optional<THistogramConfigPtr> HistogramTimerProfiling; - std::optional<bool> EnableErrorCodeCounting; + std::optional<bool> EnableErrorCodeCounter; std::optional<ERequestTracingMode> TracingMode; REGISTER_YSON_STRUCT(TServiceCommonDynamicConfig); @@ -129,7 +129,7 @@ class TServiceConfig { public: std::optional<bool> EnablePerUserProfiling; - std::optional<bool> EnableErrorCodeCounting; + std::optional<bool> EnableErrorCodeCounter; std::optional<ERequestTracingMode> TracingMode; THistogramConfigPtr HistogramTimerProfiling; THashMap<TString, TMethodConfigPtr> Methods; diff --git a/yt/yt/core/rpc/server_detail.cpp b/yt/yt/core/rpc/server_detail.cpp index 323c0724af..93ed975f72 100644 --- a/yt/yt/core/rpc/server_detail.cpp +++ b/yt/yt/core/rpc/server_detail.cpp @@ -913,7 +913,7 @@ void TServerBase::ApplyConfig() VERIFY_SPINLOCK_AFFINITY(ServicesLock_); auto newAppliedConfig = New<TServerConfig>(); - newAppliedConfig->EnableErrorCodeCounting = DynamicConfig_->EnableErrorCodeCounting.value_or(StaticConfig_->EnableErrorCodeCounting); + newAppliedConfig->EnableErrorCodeCounter = DynamicConfig_->EnableErrorCodeCounter.value_or(StaticConfig_->EnableErrorCodeCounter); newAppliedConfig->EnablePerUserProfiling = DynamicConfig_->EnablePerUserProfiling.value_or(StaticConfig_->EnablePerUserProfiling); newAppliedConfig->HistogramTimerProfiling = DynamicConfig_->HistogramTimerProfiling.value_or(StaticConfig_->HistogramTimerProfiling); newAppliedConfig->TracingMode = DynamicConfig_->TracingMode.value_or(StaticConfig_->TracingMode); diff --git a/yt/yt/core/rpc/service_detail.cpp b/yt/yt/core/rpc/service_detail.cpp index f3734d03ef..214a11e917 100644 --- a/yt/yt/core/rpc/service_detail.cpp +++ b/yt/yt/core/rpc/service_detail.cpp @@ -262,6 +262,19 @@ auto TServiceBase::TMethodDescriptor::SetHandleMethodError(bool value) const -> //////////////////////////////////////////////////////////////////////////////// +TServiceBase::TErrorCodeCounter::TErrorCodeCounter(NProfiling::TProfiler profiler) + : Profiler_(std::move(profiler)) +{ } + +void TServiceBase::TErrorCodeCounter::Increment(TErrorCode code) +{ + CodeToCounter_.FindOrInsert(code, [&] { + return Profiler_.WithTag("code", ToString(code)).Counter("/code_count"); + }).first->Increment(); +} + +//////////////////////////////////////////////////////////////////////////////// + TServiceBase::TMethodPerformanceCounters::TMethodPerformanceCounters( const NProfiling::TProfiler& profiler, const THistogramConfigPtr& histogramConfig) @@ -274,7 +287,7 @@ TServiceBase::TMethodPerformanceCounters::TMethodPerformanceCounters( , RequestMessageAttachmentSizeCounter(profiler.Counter("/request_message_attachment_bytes")) , ResponseMessageBodySizeCounter(profiler.Counter("/response_message_body_bytes")) , ResponseMessageAttachmentSizeCounter(profiler.Counter("/response_message_attachment_bytes")) - , ErrorCodes(profiler) + , ErrorCodeCounter(profiler) { if (histogramConfig && histogramConfig->CustomBounds) { const auto &customBounds = *histogramConfig->CustomBounds; @@ -1008,8 +1021,8 @@ private: MethodPerformanceCounters_->ExecutionTimeCounter.Record(*ExecutionTime_); MethodPerformanceCounters_->TotalTimeCounter.Record(*TotalTime_); if (!Error_.IsOK()) { - if (Service_->EnableErrorCodeCounting.load()) { - MethodPerformanceCounters_->ErrorCodes.RegisterCode(Error_.GetNonTrivialCode()); + if (Service_->EnableErrorCodeCounter_.load()) { + MethodPerformanceCounters_->ErrorCodeCounter.Increment(Error_.GetNonTrivialCode()); } else { MethodPerformanceCounters_->FailedRequestCounter.Increment(); } @@ -2601,7 +2614,7 @@ void TServiceBase::DoConfigure( EnablePerUserProfiling_.store(config->EnablePerUserProfiling.value_or(configDefaults->EnablePerUserProfiling)); AuthenticationQueueSizeLimit_.store(config->AuthenticationQueueSizeLimit.value_or(DefaultAuthenticationQueueSizeLimit)); PendingPayloadsTimeout_.store(config->PendingPayloadsTimeout.value_or(DefaultPendingPayloadsTimeout)); - EnableErrorCodeCounting.store(config->EnableErrorCodeCounting.value_or(configDefaults->EnableErrorCodeCounting)); + EnableErrorCodeCounter_.store(config->EnableErrorCodeCounter.value_or(configDefaults->EnableErrorCodeCounter)); DoConfigureHistogramTimer(configDefaults, config); diff --git a/yt/yt/core/rpc/service_detail.h b/yt/yt/core/rpc/service_detail.h index f1f77e71f7..a1f7b3c54f 100644 --- a/yt/yt/core/rpc/service_detail.h +++ b/yt/yt/core/rpc/service_detail.h @@ -649,22 +649,16 @@ protected: TMethodDescriptor SetHandleMethodError(bool value) const; }; - struct TErrorCodesCounter + struct TErrorCodeCounter { - TErrorCodesCounter(const NProfiling::TProfiler& profiler) - : Profiler_(profiler) - { } + explicit TErrorCodeCounter(NProfiling::TProfiler profiler); - void RegisterCode(TErrorCode code) - { - ErrorCodes_.FindOrInsert(code, [&] () { - return Profiler_.WithTag("code", ToString(code)).Counter("/code_count"); - }).first->Increment(); - } + void Increment(TErrorCode code); private: - NYT::NConcurrency::TSyncMap<TErrorCode, NProfiling::TCounter> ErrorCodes_; - NProfiling::TProfiler Profiler_; + const NProfiling::TProfiler Profiler_; + + NConcurrency::TSyncMap<TErrorCode, NProfiling::TCounter> CodeToCounter_; }; //! Per-user and per-method profiling counters. @@ -712,7 +706,8 @@ protected: //! Counts the number of bytes in response message attachment. NProfiling::TCounter ResponseMessageAttachmentSizeCounter; - TErrorCodesCounter ErrorCodes; + //! Counts the number of errors, per error code. + TErrorCodeCounter ErrorCodeCounter; }; using TMethodPerformanceCountersPtr = TIntrusivePtr<TMethodPerformanceCounters>; @@ -978,7 +973,7 @@ private: YT_DECLARE_SPIN_LOCK(NThreading::TSpinLock, HistogramConfigLock_); THistogramConfigPtr HistogramTimerProfiling{}; - std::atomic<bool> EnableErrorCodeCounting = false; + std::atomic<bool> EnableErrorCodeCounter_ = false; const NConcurrency::TPeriodicExecutorPtr ServiceLivenessChecker_; |