From 16b9eaafae08c14fa92ff6521b716de91489f60d Mon Sep 17 00:00:00 2001 From: Kirill Pleshivtsev Date: Mon, 11 Mar 2024 18:03:53 +0700 Subject: [PATCH 1/3] Write all crit events to cerr --- cloud/storage/core/libs/diagnostics/critical_events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/storage/core/libs/diagnostics/critical_events.cpp b/cloud/storage/core/libs/diagnostics/critical_events.cpp index 0714858302d..d595cdcab1d 100644 --- a/cloud/storage/core/libs/diagnostics/critical_events.cpp +++ b/cloud/storage/core/libs/diagnostics/critical_events.cpp @@ -50,8 +50,8 @@ TString ReportCriticalEvent( fullMessage << "CRITICAL_EVENT:" << sensorName; if (message) { fullMessage << ":" << message; - Cerr << fullMessage << Endl; } + Cerr << fullMessage << Endl; return fullMessage; } From 80cb5e3464a4c402061c39102697dd282ccf1bb7 Mon Sep 17 00:00:00 2001 From: Kirill Pleshivtsev Date: Thu, 14 Mar 2024 14:28:28 +0700 Subject: [PATCH 2/3] Make writing almost atomic --- cloud/storage/core/libs/diagnostics/critical_events.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cloud/storage/core/libs/diagnostics/critical_events.cpp b/cloud/storage/core/libs/diagnostics/critical_events.cpp index d595cdcab1d..facf61b5c2d 100644 --- a/cloud/storage/core/libs/diagnostics/critical_events.cpp +++ b/cloud/storage/core/libs/diagnostics/critical_events.cpp @@ -51,7 +51,13 @@ TString ReportCriticalEvent( if (message) { fullMessage << ":" << message; } - Cerr << fullMessage << Endl; + + if (!verifyDebug || message) { + // Write message and \n in one call. This will reduce the chance of + // shuffling with writings of other threads. + Cerr << fullMessage + '\n'; + Cerr.Flush(); + } return fullMessage; } From 1c2d520b00e2cdf8477f28e5379d5f3cd758e623 Mon Sep 17 00:00:00 2001 From: Kirill Pleshivtsev Date: Thu, 28 Mar 2024 15:43:09 +0700 Subject: [PATCH 3/3] Use global logger --- cloud/blockstore/libs/daemon/common/bootstrap.cpp | 1 + cloud/filestore/libs/daemon/common/bootstrap.cpp | 3 ++- .../core/libs/diagnostics/critical_events.cpp | 12 ++++++++++-- .../storage/core/libs/diagnostics/critical_events.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cloud/blockstore/libs/daemon/common/bootstrap.cpp b/cloud/blockstore/libs/daemon/common/bootstrap.cpp index beb1692108c..ca6d13c75df 100644 --- a/cloud/blockstore/libs/daemon/common/bootstrap.cpp +++ b/cloud/blockstore/libs/daemon/common/bootstrap.cpp @@ -199,6 +199,7 @@ void TBootstrapBase::Init() BootstrapLogging = CreateLoggingService("console", logSettings); Log = BootstrapLogging->CreateLog("BLOCKSTORE_SERVER"); + SetCriticalEventsLog(Log); Configs->Log = Log; STORAGE_INFO("NBS server version: " << GetFullVersionString()); diff --git a/cloud/filestore/libs/daemon/common/bootstrap.cpp b/cloud/filestore/libs/daemon/common/bootstrap.cpp index fb5918ce7f2..e189d0c9be9 100644 --- a/cloud/filestore/libs/daemon/common/bootstrap.cpp +++ b/cloud/filestore/libs/daemon/common/bootstrap.cpp @@ -11,13 +11,13 @@ #include #include #include - #include #include #include #include #include #include +#include #include #include #include @@ -99,6 +99,7 @@ TBootstrapCommon::TBootstrapCommon( BootstrapLogging->Start(); Log = BootstrapLogging->CreateLog(logComponent); + SetCriticalEventsLog(Log); } TBootstrapCommon::~TBootstrapCommon() diff --git a/cloud/storage/core/libs/diagnostics/critical_events.cpp b/cloud/storage/core/libs/diagnostics/critical_events.cpp index facf61b5c2d..40d245e93a6 100644 --- a/cloud/storage/core/libs/diagnostics/critical_events.cpp +++ b/cloud/storage/core/libs/diagnostics/critical_events.cpp @@ -1,7 +1,7 @@ #include "critical_events.h" - #include "public.h" +#include #include #include @@ -13,11 +13,17 @@ using namespace NMonitoring; namespace { NMonitoring::TDynamicCountersPtr CriticalEvents; +TLog Log; } // namespace //////////////////////////////////////////////////////////////////////////////// +void SetCriticalEventsLog(TLog log) +{ + Log = std::move(log); +} + void InitCriticalEventsCounter(NMonitoring::TDynamicCountersPtr counters) { CriticalEvents = std::move(counters); @@ -52,7 +58,9 @@ TString ReportCriticalEvent( fullMessage << ":" << message; } - if (!verifyDebug || message) { + if (Log.IsNotNullLog()) { + Log.AddLog("%s", fullMessage.c_str()); + } else { // Write message and \n in one call. This will reduce the chance of // shuffling with writings of other threads. Cerr << fullMessage + '\n'; diff --git a/cloud/storage/core/libs/diagnostics/critical_events.h b/cloud/storage/core/libs/diagnostics/critical_events.h index 9777a7b38b6..2754c38bde5 100644 --- a/cloud/storage/core/libs/diagnostics/critical_events.h +++ b/cloud/storage/core/libs/diagnostics/critical_events.h @@ -15,6 +15,7 @@ namespace NCloud { //////////////////////////////////////////////////////////////////////////////// +void SetCriticalEventsLog(TLog log); void InitCriticalEventsCounter(NMonitoring::TDynamicCountersPtr counters); TString ReportCriticalEvent(