aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unified_agent_client/backend_creator.cpp
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2023-03-31 10:54:08 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2023-03-31 12:28:07 +0300
commitfc1cffcfa7f0497a1f97b384a24bcbf23362f3be (patch)
treec15f7ab5b9e9b20fd0ef8fc07d598d28e8b32004 /library/cpp/unified_agent_client/backend_creator.cpp
parent8a749596d40e91c896a1907afcd108d9221fbde1 (diff)
downloadydb-fc1cffcfa7f0497a1f97b384a24bcbf23362f3be.tar.gz
Ydb stable 23-1-1923.1.19
x-stable-origin-commit: c5d5a396e89d0a72e0267a55e93d8404d4fb54fe
Diffstat (limited to 'library/cpp/unified_agent_client/backend_creator.cpp')
-rw-r--r--library/cpp/unified_agent_client/backend_creator.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/library/cpp/unified_agent_client/backend_creator.cpp b/library/cpp/unified_agent_client/backend_creator.cpp
new file mode 100644
index 0000000000..825e3ebd2b
--- /dev/null
+++ b/library/cpp/unified_agent_client/backend_creator.cpp
@@ -0,0 +1,63 @@
+#include "backend_creator.h"
+#include <library/cpp/logger/global/global.h>
+
+namespace NUnifiedAgent {
+
+
+ TLogBackendCreator::TLogBackendCreator()
+ : TLogBackendCreatorBase("unified_agent")
+ {}
+
+ bool TLogBackendCreator::Init(const IInitContext& ctx) {
+ if(TString socket = ctx.GetOrElse("Uri", TString())) {
+ ClientParams = MakeHolder<TClientParameters>(socket);
+ } else {
+ Cdbg << "Uri not set for unified_agent log backend" << Endl;
+ return false;
+ }
+ TString secretKey;
+ ctx.GetValue("SharedSecretKey", secretKey);
+ if (secretKey) {
+ ClientParams->SharedSecretKey = secretKey;
+ }
+ ctx.GetValue("MaxInflightBytes", ClientParams->MaxInflightBytes);
+ ctx.GetValue("GrpcSendDelay", ClientParams->GrpcSendDelay);
+ size_t rateLimit;
+ if (ctx.GetValue("LogRateLimit", rateLimit)) {
+ ClientParams->LogRateLimitBytes = rateLimit;
+ }
+ ctx.GetValue("GrpcReconnectDelay", ClientParams->GrpcReconnectDelay);
+ ctx.GetValue("GrpcMaxMessageSize", ClientParams->GrpcMaxMessageSize);
+ const auto ownLogger = ctx.GetChildren("OwnLogger");
+ if (!ownLogger.empty() && ownLogger.front()->GetOrElse("LoggerType", TString()) != "global") {
+ OwnLogger = ILogBackendCreator::Create(*ownLogger.front());
+ TLog log;
+ log.ResetBackend(OwnLogger->CreateLogBackend());
+ ClientParams->SetLog(log);
+ }
+ return true;
+ }
+
+
+ void TLogBackendCreator::DoToJson(NJson::TJsonValue& value) const {
+ value["Uri"] = ClientParams->Uri;
+ if (ClientParams->SharedSecretKey) {
+ value["SharedSecretKey"] = *ClientParams->SharedSecretKey;
+ }
+ value["MaxInflightBytes"] = ClientParams->MaxInflightBytes;
+ value["GrpcSendDelay"] = ClientParams->GrpcSendDelay.ToString();
+ if (ClientParams->LogRateLimitBytes) {
+ value["LogRateLimit"] = *ClientParams->LogRateLimitBytes;
+ }
+ value["GrpcReconnectDelay"] = ClientParams->GrpcReconnectDelay.ToString();
+ value["GrpcMaxMessageSize"] = ClientParams->GrpcMaxMessageSize;
+ if (OwnLogger) {
+ OwnLogger->ToJson(value["OwnLogger"].AppendValue(NJson::JSON_MAP));
+ }
+ }
+
+ THolder<TLogBackend> TLogBackendCreator::DoCreateLogBackend() const {
+ return MakeLogBackend(*ClientParams);
+ }
+
+}