aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/log_ut.cpp
diff options
context:
space:
mode:
authorandrew-rykov <arykov@ydb.tech>2022-09-13 12:49:05 +0300
committerandrew-rykov <arykov@ydb.tech>2022-09-13 12:49:05 +0300
commitcee4a99ba93f21e3d30b5f1d58c84ab6ca41981b (patch)
treed75cbc3a1ad20a211c550d8f29634eff47f5e48d /library/cpp/actors/core/log_ut.cpp
parent8c1af103661148f5377e712cb2ac5623672522a1 (diff)
downloadydb-cee4a99ba93f21e3d30b5f1d58c84ab6ca41981b.tar.gz
add-log-buffer 2
add log buffer changed names added move changed details fixed released buffer procedure returned condition IgnoredCount > 0 default bufferSizeLimitBytes = 0 returned passedCount declaration returned Y_VERIFY removed passedcount changed buffer reducing no new line at the end of file added srcs in ya.make add log buffer
Diffstat (limited to 'library/cpp/actors/core/log_ut.cpp')
-rw-r--r--library/cpp/actors/core/log_ut.cpp68
1 files changed, 65 insertions, 3 deletions
diff --git a/library/cpp/actors/core/log_ut.cpp b/library/cpp/actors/core/log_ut.cpp
index 09b5f88ea2c..e6508738cca 100644
--- a/library/cpp/actors/core/log_ut.cpp
+++ b/library/cpp/actors/core/log_ut.cpp
@@ -30,11 +30,31 @@ namespace {
EPriority::PRI_TRACE,
EPriority::PRI_DEBUG,
(ui32)0,
- timeThresholdMs);
+ timeThresholdMs,
+ (ui64)0);
s->Append(0, 1, ServiceToString);
return s;
}
+ TIntrusivePtr<TSettings> BufferSettings(ui64 bufferSizeLimitBytes) {
+ auto loggerId = TActorId{0, "Logger"};
+ auto s = MakeIntrusive<TSettings>(
+ loggerId,
+ 0,
+ EPriority::PRI_TRACE,
+ EPriority::PRI_DEBUG,
+ (ui32)0,
+ (ui32)0,
+ bufferSizeLimitBytes);
+ s->Append(0, 1, ServiceToString);
+ s->SetAllowDrop(true);
+ return s;
+ }
+
+ TIntrusivePtr<TSettings> NoBufferSettings() {
+ return BufferSettings(0);
+ }
+
class TMockBackend: public TLogBackend {
public:
using TWriteImpl = std::function<void(const TLogRecord&)>;
@@ -88,8 +108,12 @@ namespace {
Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(TInstant::Zero(), TLevel{EPrio::Emerg}, 0, "foo")});
}
- void WriteLog(TInstant ts) {
- Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{EPrio::Emerg}, 0, "foo")});
+ void WriteLog(TInstant ts, EPrio prio = EPrio::Emerg) {
+ Runtime.Send(new IEventHandle{LoggerActor, {}, new TEvLog(ts, TLevel{prio}, 0, "foo")});
+ }
+
+ void ReleaseLogBuffer() {
+ Runtime.Send(new IEventHandle{LoggerActor, {}, new TReleaseLogBuffer()});
}
void Wakeup() {
@@ -182,4 +206,42 @@ Y_UNIT_TEST_SUITE(TLoggerActorTest) {
UNIT_ASSERT_VALUES_EQUAL(messages.size(), COUNT + 1);
}
+
+ int BufferTest(TFixture &test, const int COUNT) {
+ TVector<TString> messages;
+ auto acceptWrites = [&] (const TLogRecord& r) {
+ messages.emplace_back(r.Data, r.Len);
+ };
+
+ test.LogBackend->SetWriteImpl(acceptWrites);
+ test.Wakeup();
+ test.Runtime.AdvanceCurrentTime(TDuration::Days(1));
+ auto now = test.Runtime.GetCurrentTime();
+
+ for (auto i = 0; i < COUNT; ++i) {
+ test.WriteLog(now - TDuration::Seconds(10), EPrio::Debug);
+ }
+
+ for (auto i = 0; i < COUNT; ++i) {
+ test.ReleaseLogBuffer();
+ }
+
+ return messages.size();
+ }
+
+ Y_UNIT_TEST(ShouldUseLogBufferWhenOverloaded) {
+ TFixture test{BufferSettings(1024 * 1024 * 300)};
+ const auto LOG_COUNT = 500;
+ auto outputLogSize = BufferTest(test, LOG_COUNT);
+
+ UNIT_ASSERT_VALUES_EQUAL(outputLogSize, LOG_COUNT);
+ }
+
+ Y_UNIT_TEST(ShouldLoseLogsWithoutBuffer) {
+ TFixture test{NoBufferSettings()};
+ const auto LOG_COUNT = 500;
+ auto outputLogSize = BufferTest(test, LOG_COUNT);
+
+ UNIT_ASSERT(outputLogSize < LOG_COUNT);
+ }
}