From fdd604a7e32254dd8d227cd7c21a4e409ddda10a Mon Sep 17 00:00:00 2001 From: Vasily Gerasimov Date: Wed, 23 Oct 2024 09:11:42 +0300 Subject: Support pure json output for audit log (#10143) --- ydb/core/audit/audit_log_impl.cpp | 22 ++++++++++++++++++++++ ydb/core/protos/config.proto | 5 +++-- ydb/library/actors/core/log.cpp | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ydb/core/audit/audit_log_impl.cpp b/ydb/core/audit/audit_log_impl.cpp index e03e9ac7ff8..0a2ed1b9694 100644 --- a/ydb/core/audit/audit_log_impl.cpp +++ b/ydb/core/audit/audit_log_impl.cpp @@ -91,6 +91,25 @@ TString GetJsonLog(const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) { return ss.Str(); } +TString GetJsonLogCompatibleLog(const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) { + const auto* msg = ev->Get(); + NJsonWriter::TBuf json; + { + auto obj = json.BeginObject(); + obj + .WriteKey("@timestamp") + .WriteString(msg->Time.ToString().data()) + .WriteKey("@log_type") + .WriteString("audit"); + + for (auto& [k, v] : msg->Parts) { + obj.WriteKey(k).WriteString(v); + } + json.EndObject(); + } + return json.Str(); +} + TString GetTxtLog(const TEvAuditLog::TEvWriteAuditLog::TPtr& ev) { const auto* msg = ev->Get(); TStringStream ss; @@ -146,6 +165,9 @@ private: case NKikimrConfig::TAuditConfig::TXT: WriteLog(GetTxtLog(ev), logBackends.second); break; + case NKikimrConfig::TAuditConfig::JSON_LOG_COMPATIBLE: + WriteLog(GetJsonLogCompatibleLog(ev), logBackends.second); + break; default: WriteLog(GetJsonLog(ev), logBackends.second); break; diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto index b98e0f6671c..d5ae1c44405 100644 --- a/ydb/core/protos/config.proto +++ b/ydb/core/protos/config.proto @@ -1438,8 +1438,9 @@ message TMeteringConfig { message TAuditConfig { enum EFormat { - JSON = 1; - TXT = 2; + JSON = 1; // Outputs audit log in format: "