aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unified_agent_client/backend_creator.cpp
blob: 825e3ebd2bd5d35902260bc5c9e8baee1f201e9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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);
    }

}