aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-10-20 17:04:47 +0300
committerbabenko <babenko@yandex-team.com>2024-10-20 17:19:01 +0300
commite36aa48cf1a20abbfa2a921748f3f1a32b7000be (patch)
tree834cd5cfd04a4c8a80ea24626fa280f420ae5126 /library/cpp
parent849246505c7f71dc743ab87a18a4d9a8da1cd1bf (diff)
downloadydb-e36aa48cf1a20abbfa2a921748f3f1a32b7000be.tar.gz
Introduce message_level_overrides to tune log message levels at runtime
* Changelog entry Type: feature Add message_level_overrides option to logging config for better run-time tuning. commit_hash:07e9563fd111c437edf7ac0e5dd190781878d8fa
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/logging/backends/stream/stream_log_manager.cpp6
-rw-r--r--library/cpp/yt/logging/logger-inl.h15
-rw-r--r--library/cpp/yt/logging/logger.h34
3 files changed, 35 insertions, 20 deletions
diff --git a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp
index 62269dc0c0..62fa3e91d0 100644
--- a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp
+++ b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp
@@ -28,10 +28,8 @@ public:
anchor->Registered = true;
}
- virtual void UpdateAnchor(TLoggingAnchor* anchor) override
- {
- anchor->Enabled = true;
- }
+ virtual void UpdateAnchor(TLoggingAnchor* /*anchor*/) override
+ { }
virtual void Enqueue(TLogEvent&& event) override
{
diff --git a/library/cpp/yt/logging/logger-inl.h b/library/cpp/yt/logging/logger-inl.h
index f3993a4c48..f1be10827f 100644
--- a/library/cpp/yt/logging/logger-inl.h
+++ b/library/cpp/yt/logging/logger-inl.h
@@ -14,11 +14,11 @@ namespace NYT::NLogging {
////////////////////////////////////////////////////////////////////////////////
-inline bool TLogger::IsAnchorUpToDate(const TLoggingAnchor& position) const
+inline bool TLogger::IsAnchorUpToDate(const TLoggingAnchor& anchor) const
{
return
!Category_ ||
- position.CurrentVersion == Category_->ActualVersion->load(std::memory_order::relaxed);
+ anchor.CurrentVersion == Category_->ActualVersion->load(std::memory_order::relaxed);
}
template <class... TArgs>
@@ -49,6 +49,17 @@ TLogger TLogger::WithStructuredTag(TStringBuf key, TType value) const
return result;
}
+Y_FORCE_INLINE ELogLevel TLogger::GetEffectiveLoggingLevel(ELogLevel level, const TLoggingAnchor& anchor)
+{
+ // Check if anchor is suppressed.
+ if (anchor.Suppressed.load(std::memory_order::relaxed)) {
+ return ELogLevel::Minimum;
+ }
+
+ // Compute the actual level taking anchor override into account.
+ return anchor.LevelOverride.load(std::memory_order::relaxed).value_or(level);
+}
+
Y_FORCE_INLINE bool TLogger::IsLevelEnabled(ELogLevel level) const
{
// This is the first check which is intended to be inlined next to
diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h
index 4f0ed44ab7..35aba4eb4c 100644
--- a/library/cpp/yt/logging/logger.h
+++ b/library/cpp/yt/logging/logger.h
@@ -47,12 +47,17 @@ struct TLoggingCategory
struct TLoggingAnchor
{
std::atomic<bool> Registered = false;
+ TLoggingAnchor* NextAnchor = nullptr;
+
::TSourceLocation SourceLocation = {TStringBuf{}, 0};
TString AnchorMessage;
- TLoggingAnchor* NextAnchor = nullptr;
std::atomic<int> CurrentVersion = 0;
- std::atomic<bool> Enabled = false;
+
+ std::atomic<bool> Suppressed = false;
+
+ std::atomic<std::optional<ELogLevel>> LevelOverride;
+ static_assert(decltype(LevelOverride)::is_always_lock_free);
struct TCounter
{
@@ -189,6 +194,9 @@ public:
const TLoggingCategory* GetCategory() const;
+ //! Combines given #level and the override from #anchor.
+ static ELogLevel GetEffectiveLoggingLevel(ELogLevel level, const TLoggingAnchor& anchor);
+
//! Validate that level is admitted by logger's own min level
//! and by category's min level.
bool IsLevelEnabled(ELogLevel level) const;
@@ -300,40 +308,38 @@ void LogStructuredEvent(
do { \
const auto& logger__ = (logger)(); \
auto level__ = (level); \
- \
- if (!logger__.IsLevelEnabled(level__)) { \
- break; \
- } \
- \
auto location__ = __LOCATION__; \
\
::NYT::NLogging::TLoggingAnchor* anchor__ = (anchor); \
- if (!anchor__) { \
+ [[unlikely]] if (!anchor__) { \
static ::NYT::TLeakyStorage<::NYT::NLogging::TLoggingAnchor> staticAnchor__; \
anchor__ = staticAnchor__.Get(); \
} \
\
bool anchorUpToDate__ = logger__.IsAnchorUpToDate(*anchor__); \
- if (anchorUpToDate__ && !anchor__->Enabled.load(std::memory_order::relaxed)) { \
- break; \
+ [[likely]] if (anchorUpToDate__) { \
+ auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \
+ if (!logger__.IsLevelEnabled(effectiveLevel__)) { \
+ break; \
+ } \
} \
\
auto loggingContext__ = ::NYT::NLogging::GetLoggingContext(); \
auto message__ = ::NYT::NLogging::NDetail::BuildLogMessage(loggingContext__, logger__, __VA_ARGS__); \
\
- if (!anchorUpToDate__) { \
+ [[unlikely]] if (!anchorUpToDate__) { \
logger__.RegisterStaticAnchor(anchor__, location__, message__.Anchor); \
- logger__.UpdateAnchor(anchor__); \
} \
\
- if (!anchor__->Enabled.load(std::memory_order::relaxed)) { \
+ auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \
+ if (!logger__.IsLevelEnabled(effectiveLevel__)) { \
break; \
} \
\
::NYT::NLogging::NDetail::LogEventImpl( \
loggingContext__, \
logger__, \
- level__, \
+ effectiveLevel__, \
location__, \
anchor__, \
std::move(message__.MessageRef)); \