aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarum <tarum@yandex-team.com>2023-08-08 19:19:22 +0300
committertarum <tarum@yandex-team.com>2023-08-08 20:15:30 +0300
commitc1852ff797428c5f31b5f69d74d96b79fa79e8a7 (patch)
tree67947479aa572737e25e4be44e7f06be4ac5ba39
parentf5e11e4e5841f5e6dbb9d0c29e958ff024bca4ab (diff)
downloadydb-c1852ff797428c5f31b5f69d74d96b79fa79e8a7.tar.gz
Add logging of actor names and events to test actor system
-rw-r--r--ydb/core/blobstorage/ut_blobstorage/lib/env.h6
-rw-r--r--ydb/core/util/testactorsys.cpp38
-rw-r--r--ydb/core/util/testactorsys.h20
3 files changed, 63 insertions, 1 deletions
diff --git a/ydb/core/blobstorage/ut_blobstorage/lib/env.h b/ydb/core/blobstorage/ut_blobstorage/lib/env.h
index 50f65260ea7..247411a1a25 100644
--- a/ydb/core/blobstorage/ut_blobstorage/lib/env.h
+++ b/ydb/core/blobstorage/ut_blobstorage/lib/env.h
@@ -259,6 +259,12 @@ struct TEnvironmentSetup {
for (const auto& comp : debug) {
Runtime->SetLogPriority(comp, NLog::PRI_DEBUG);
}
+
+ // toggle the flag to enable logging of actor names and events
+ bool printActorNamesAndEvents = false;
+ if (printActorNamesAndEvents) {
+ Runtime->SetOwnLogPriority(NActors::NLog::EPrio::Info);
+ }
}
void SetupStaticStorage() {
diff --git a/ydb/core/util/testactorsys.cpp b/ydb/core/util/testactorsys.cpp
index 6dd2760001d..7facff689dd 100644
--- a/ydb/core/util/testactorsys.cpp
+++ b/ydb/core/util/testactorsys.cpp
@@ -6,8 +6,46 @@
#include <ydb/core/base/tablet_resolver.h>
#include <library/cpp/actors/interconnect/interconnect.h>
+#include <util/generic/singleton.h>
+
namespace NKikimr {
+class TActorNameTracker {
+public:
+ static TActorNameTracker& GetInstance() {
+ auto* instance = Singleton<TActorNameTracker>();
+ return *instance;
+ }
+
+ void Register(const TActorId& actorId, const TString& name) {
+ TGuard<TMutex> guard{Mutex};
+ NameByActorIdString[actorId] = name + actorId.ToString();
+ }
+
+ TString GetName(const TActorId& actorId) const {
+ TGuard<TMutex> guard{Mutex};
+ auto it = NameByActorIdString.find(actorId);
+ if (it == NameByActorIdString.end()) {
+ return "[unknown_actor]" + actorId.ToString();
+ }
+
+ return it->second;
+ }
+
+private:
+ THashMap<TActorId, TString> NameByActorIdString;
+ TMutex Mutex;
+
+};
+
+void RegisterActorName(const TActorId& actorId, const TString& name) {
+ TActorNameTracker::GetInstance().Register(actorId, name);
+}
+
+TString GetRegisteredActorName(const TActorId& actorId) {
+ return TActorNameTracker::GetInstance().GetName(actorId);
+}
+
class TTestExecutorPool : public IExecutorPool {
TTestActorSystem *Context;
const ui32 NodeId;
diff --git a/ydb/core/util/testactorsys.h b/ydb/core/util/testactorsys.h
index 3ff3d41dfd7..0d18c739328 100644
--- a/ydb/core/util/testactorsys.h
+++ b/ydb/core/util/testactorsys.h
@@ -17,6 +17,9 @@
namespace NKikimr {
+void RegisterActorName(const TActorId& actorId, const TString& name);
+TString GetRegisteredActorName(const TActorId& actorId);
+
class TTestExecutorPool;
class TTestActorSystem {
@@ -106,6 +109,7 @@ class TTestActorSystem {
TProgramShouldContinue ProgramShouldContinue;
TAppData AppData;
TIntrusivePtr<NLog::TSettings> LoggerSettings_;
+ NActors::NLog::EPrio OwnLogPriority = NActors::NLog::EPrio::Error;
TActorId CurrentRecipient;
ui32 CurrentNodeId = 0;
ui64 EventsProcessed = 0;
@@ -365,6 +369,10 @@ public:
Y_VERIFY(!res, "failed to set log level: %s", explanation.data());
}
+ void SetOwnLogPriority(NActors::NLog::EPrio priority) {
+ OwnLogPriority = priority;
+ }
+
bool Send(TAutoPtr<IEventHandle> ev, ui32 nodeId = 0) {
if (!ev) {
return false;
@@ -388,6 +396,12 @@ public:
nodeId = nodeId ? nodeId : CurrentNodeId;
Y_VERIFY(nodeId);
+ if (OwnLogPriority >= NActors::NLog::EPrio::Info) {
+ auto actor = GetActor(TransformEvent(ev.Get(), nodeId));
+ const auto targetActorId = actor ? (actor->SelfId()) : TActorId{0, 0};
+ *LogStream << "[TestActorSystem] Send event from " << GetRegisteredActorName(ev->Sender) << " to " << GetRegisteredActorName(targetActorId) << ": " << ev->ToString() << Endl;
+ }
+
// check if the target actor exists; we have to transform the event recipient early to keep behaviour of real
// actor system here
if (GetActor(TransformEvent(ev.Get(), nodeId))) {
@@ -436,7 +450,7 @@ public:
// count stats
TString name = TypeName(*actor);
++ActorStats[name].Created;
- const bool inserted = ActorName.emplace(actor, std::move(name)).second;
+ const bool inserted = ActorName.emplace(actor, name).second;
Y_VERIFY(inserted);
// specify node id if not provided
@@ -457,6 +471,10 @@ public:
// generate actor id
const TActorId actorId(nodeId, poolId, mbox.ActorLocalId, mboxId);
++mbox.ActorLocalId;
+ if (OwnLogPriority >= NActors::NLog::EPrio::Info) {
+ *LogStream << "[TestActorSystem] Register actor \"" << name << "\" with id " << actorId.ToString() << Endl;
+ RegisterActorName(actorId, name);
+ }
// initialize actor in actor system
DoActorInit(info->ActorSystem.get(), actor, actorId, parentId ? parentId : CurrentRecipient);