Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write all crit events to cerr #696

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cloud/blockstore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
3 changes: 2 additions & 1 deletion cloud/filestore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#include <cloud/filestore/libs/server/server.h>
#include <cloud/filestore/libs/storage/core/config.h>
#include <cloud/filestore/libs/storage/init/actorsystem.h>

#include <cloud/storage/core/libs/common/scheduler.h>
#include <cloud/storage/core/libs/common/task_queue.h>
#include <cloud/storage/core/libs/common/thread_pool.h>
#include <cloud/storage/core/libs/common/timer.h>
#include <cloud/storage/core/libs/daemon/mlock.h>
#include <cloud/storage/core/libs/diagnostics/cgroup_stats_fetcher.h>
#include <cloud/storage/core/libs/diagnostics/critical_events.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>
#include <cloud/storage/core/libs/diagnostics/monitoring.h>
#include <cloud/storage/core/libs/diagnostics/stats_updater.h>
Expand Down Expand Up @@ -99,6 +99,7 @@ TBootstrapCommon::TBootstrapCommon(
BootstrapLogging->Start();

Log = BootstrapLogging->CreateLog(logComponent);
SetCriticalEventsLog(Log);
}

TBootstrapCommon::~TBootstrapCommon()
Expand Down
18 changes: 16 additions & 2 deletions cloud/storage/core/libs/diagnostics/critical_events.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "critical_events.h"

#include "public.h"

#include <library/cpp/logger/log.h>
#include <library/cpp/monlib/dynamic_counters/counters.h>

#include <util/string/builder.h>
Expand All @@ -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);
Expand Down Expand Up @@ -50,7 +56,15 @@ TString ReportCriticalEvent(
fullMessage << "CRITICAL_EVENT:" << sensorName;
if (message) {
fullMessage << ":" << message;
drbasic marked this conversation as resolved.
Show resolved Hide resolved
Cerr << fullMessage << Endl;
}

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';
drbasic marked this conversation as resolved.
Show resolved Hide resolved
Cerr.Flush();
}

return fullMessage;
Expand Down
1 change: 1 addition & 0 deletions cloud/storage/core/libs/diagnostics/critical_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace NCloud {

////////////////////////////////////////////////////////////////////////////////

void SetCriticalEventsLog(TLog log);
void InitCriticalEventsCounter(NMonitoring::TDynamicCountersPtr counters);

TString ReportCriticalEvent(
Expand Down