diff --git a/ydb/core/audit/audit_log.h b/ydb/core/audit/audit_log.h index 23c100c31a4c..520d8bf8ff3b 100644 --- a/ydb/core/audit/audit_log.h +++ b/ydb/core/audit/audit_log.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -40,10 +41,40 @@ namespace NKikimr::NAudit { extern std::atomic AUDIT_LOG_ENABLED; +struct TEvAuditLog { + // + // Events declaration + // + + enum EEvents { + EvBegin = EventSpaceBegin(TKikimrEvents::ES_YDB_AUDIT_LOG), + + // Request actors + EvWriteAuditLog = EvBegin + 0, + + EvEnd + }; + + static_assert(EvEnd <= EventSpaceEnd(TKikimrEvents::ES_YDB_AUDIT_LOG), + "expected EvEnd <= EventSpaceEnd(TKikimrEvents::ES_YDB_AUDIT_LOG)" + ); + + struct TEvWriteAuditLog : public NActors::TEventLocal { + TInstant Time; + TVector> Parts; + + TEvWriteAuditLog(TInstant time, TVector>&& parts) + : Time(time) + , Parts(std::move(parts)) + {} + }; +}; + +using TAuditLogItemBuilder = TString(*)(const TEvAuditLog::TEvWriteAuditLog*); + void SendAuditLog(const NActors::TActorSystem* sys, TVector>&& parts); // Registration of a function for converting audit events to a string in a specified format -template -void RegisterAuditLogItemBuilder(NKikimrConfig::TAuditConfig::EFormat format, TString(*)(const T*)); +void RegisterAuditLogItemBuilder(NKikimrConfig::TAuditConfig::EFormat format, TAuditLogItemBuilder builder); } // namespace NKikimr::NAudit diff --git a/ydb/core/audit/audit_log_impl.cpp b/ydb/core/audit/audit_log_impl.cpp index a296ac3f6bfc..f6674abd3cf5 100644 --- a/ydb/core/audit/audit_log_impl.cpp +++ b/ydb/core/audit/audit_log_impl.cpp @@ -9,8 +9,6 @@ #include #include -#include - #include "audit_log_service.h" #include "audit_log.h" @@ -32,38 +30,6 @@ namespace NKikimr::NAudit { -// TAuditLogActor -// - -struct TEvAuditLog { - // - // Events declaration - // - - enum EEvents { - EvBegin = EventSpaceBegin(TKikimrEvents::ES_YDB_AUDIT_LOG), - - // Request actors - EvWriteAuditLog = EvBegin + 0, - - EvEnd - }; - - static_assert(EvEnd <= EventSpaceEnd(TKikimrEvents::ES_YDB_AUDIT_LOG), - "expected EvEnd <= EventSpaceEnd(TKikimrEvents::ES_YDB_AUDIT_LOG)" - ); - - struct TEvWriteAuditLog : public NActors::TEventLocal { - TInstant Time; - TVector> Parts; - - TEvWriteAuditLog(TInstant time, TVector>&& parts) - : Time(time) - , Parts(std::move(parts)) - {} - }; -}; - void WriteLog(const TString& log, const TVector>& logBackends) { for (auto& logBackend : logBackends) { try { @@ -122,18 +88,15 @@ TString GetTxtLog(const TEvAuditLog::TEvWriteAuditLog* ev) { return ss.Str(); } - -using TAuditLogItemBuilder = TString(*)(const TEvAuditLog::TEvWriteAuditLog*); - // Array of functions for converting TEvAuditLog::TEvWriteAuditLog events to a string. // Indexing in the array occurs by the value of the NKikimrConfig::TAuditConfig::EFormat enumeration. +// The size of AuditLogItemBuilders must be equal to the maximum value of the NKikimrConfig::TAuditConfig::EFormat enumeration. static std::vector AuditLogItemBuilders = { GetJsonLog, GetTxtLog, GetJsonLogCompatibleLog, nullptr }; -// numbering enumeration starts with one +// numbering enumeration starts from one static constexpr size_t DefaultAuditLogItemBuilder = static_cast(NKikimrConfig::TAuditConfig::JSON) - 1; -template<> -void RegisterAuditLogItemBuilder(NKikimrConfig::TAuditConfig::EFormat format, TAuditLogItemBuilder builder) { +void RegisterAuditLogItemBuilder(NKikimrConfig::TAuditConfig::EFormat format, TAuditLogItemBuilder builder) { size_t index = static_cast(format); if (index < AuditLogItemBuilders.size()) { AuditLogItemBuilders[index] = builder;