Skip to content

Commit 4d1ccf4

Browse files
authored
[log_backend] write tenant & cluster for UnifiedAgent log backend (#10666)
1 parent 7a1e697 commit 4d1ccf4

File tree

8 files changed

+56
-5
lines changed

8 files changed

+56
-5
lines changed

ydb/core/driver_lib/run/run.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,8 @@ void TKikimrRunner::InitializeLogSettings(const TKikimrRunConfig& runConfig)
12331233
);
12341234

12351235
LogSettings->ClusterName = logConfig.HasClusterName() ? logConfig.GetClusterName() : "";
1236+
LogSettings->TenantName = runConfig.TenantName;
1237+
LogSettings->NodeId = runConfig.NodeId;
12361238

12371239
if (logConfig.GetFormat() == "full") {
12381240
LogSettings->Format = NLog::TSettings::PLAIN_FULL_FORMAT;

ydb/core/log_backend/log_backend.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ TAutoPtr<TLogBackend> CreateLogBackendWithUnifiedAgent(
1515
const auto& uaClientConfig = logConfig.GetUAClientConfig();
1616
auto uaCounters = GetServiceCounters(counters, "utils")->GetSubgroup("subsystem", "ua_client");
1717
auto logName = uaClientConfig.GetLogName();
18-
TAutoPtr<TLogBackend> uaLogBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(uaClientConfig, uaCounters, logName);
18+
TAutoPtr<TLogBackend> uaLogBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(
19+
uaClientConfig,
20+
uaCounters,
21+
logName,
22+
runConfig.TenantName == "" ? "static" : "slot",
23+
runConfig.TenantName,
24+
runConfig.ClusterName
25+
);
1926
logBackend = logBackend ? NActors::CreateCompositeLogBackend({logBackend, uaLogBackend}) : uaLogBackend;
2027
}
2128
if (logBackend) {
@@ -52,7 +59,14 @@ TAutoPtr<TLogBackend> CreateMeteringLogBackendWithUnifiedAgent(
5259
auto logName = meteringConfig.HasLogName()
5360
? meteringConfig.GetLogName()
5461
: uaClientConfig.GetLogName();
55-
TAutoPtr<TLogBackend> uaLogBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(uaClientConfig, uaCounters, logName);
62+
TAutoPtr<TLogBackend> uaLogBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(
63+
uaClientConfig,
64+
uaCounters,
65+
logName,
66+
runConfig.TenantName == "" ? "static" : "slot",
67+
runConfig.TenantName,
68+
runConfig.ClusterName
69+
);
5670
logBackend = logBackend ? NActors::CreateCompositeLogBackend({logBackend, uaLogBackend}) : uaLogBackend;
5771
}
5872

@@ -100,7 +114,14 @@ TAutoPtr<TLogBackend> CreateAuditLogUnifiedAgentBackend(
100114
auto logName = runConfig.AppConfig.GetAuditConfig().GetUnifiedAgentBackend().HasLogName()
101115
? runConfig.AppConfig.GetAuditConfig().GetUnifiedAgentBackend().GetLogName()
102116
: uaClientConfig.GetLogName();
103-
logBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(uaClientConfig, uaCounters, logName);
117+
logBackend = TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(
118+
uaClientConfig,
119+
uaCounters,
120+
logName,
121+
runConfig.TenantName == "" ? "static" : "slot",
122+
runConfig.TenantName,
123+
runConfig.ClusterName
124+
);
104125
}
105126

106127
return logBackend;

ydb/core/log_backend/log_backend_build.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ TAutoPtr<TLogBackend> TLogBackendBuildHelper::CreateLogBackendFromLogConfig(cons
2222
return logBackend;
2323
}
2424

25-
TAutoPtr<TLogBackend> TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(const NKikimrConfig::TUAClientConfig& uaClientConfig, NMonitoring::TDynamicCounterPtr uaCounters, const TString& logName) {
25+
TAutoPtr<TLogBackend> TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig(const NKikimrConfig::TUAClientConfig& uaClientConfig,
26+
NMonitoring::TDynamicCounterPtr uaCounters,
27+
const TString& logName, const TString& nodeType = "static",
28+
const TString& tenant = "",
29+
const TString& clusterName = "") {
2630
auto parameters = NUnifiedAgent::TClientParameters(uaClientConfig.GetUri())
2731
.SetCounters(uaCounters)
2832
.SetMaxInflightBytes(uaClientConfig.GetMaxInflightBytes());
@@ -51,6 +55,18 @@ TAutoPtr<TLogBackend> TLogBackendBuildHelper::CreateLogBackendFromUAClientConfig
5155
(*sessionParameters.Meta)["_log_name"] = logName;
5256
}
5357

58+
if (nodeType) {
59+
(*sessionParameters.Meta)["node_type"] = nodeType;
60+
}
61+
62+
if (tenant) {
63+
(*sessionParameters.Meta)["database"] = tenant;
64+
}
65+
66+
if (clusterName) {
67+
(*sessionParameters.Meta)["cluster"] = clusterName;
68+
}
69+
5470
TAutoPtr<TLogBackend> uaLogBackend = MakeLogBackend(parameters, sessionParameters).Release();
5571
return uaLogBackend;
5672
}

ydb/core/log_backend/log_backend_build.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class TLogBackendBuildHelper {
1616
static TAutoPtr<TLogBackend> CreateLogBackendFromUAClientConfig(
1717
const NKikimrConfig::TUAClientConfig& uaClientConfig,
1818
NMonitoring::TDynamicCounterPtr uaCounters,
19-
const TString& logName);
19+
const TString& logName,
20+
const TString& nodeType,
21+
const TString& tenant,
22+
const TString& clusterName);
2023
};
2124
}

ydb/core/protos/config.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ message TLogConfig {
385385
optional TUAClientConfig UAClientConfig = 13;
386386
optional uint64 TimeThresholdMs = 14 [default = 1000];
387387
optional bool IgnoreUnknownComponents = 15 [default = true];
388+
optional string TenantName = 16;
388389
}
389390

390391
message TInterconnectConfig {

ydb/library/actors/core/log.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ namespace NActors {
492492
.WriteString(Settings->ShortHostName)
493493
.WriteKey("cluster")
494494
.WriteString(Settings->ClusterName)
495+
.WriteKey("database")
496+
.WriteString(Settings->TenantName ? Settings->TenantName : "static")
497+
.WriteKey("node_id")
498+
.WriteInt(Settings->NodeId)
495499
.WriteKey("priority")
496500
.WriteString(PriorityToString(priority))
497501
.WriteKey("npriority")

ydb/library/actors/core/log_settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace NActors {
2424
, Format(PLAIN_FULL_FORMAT)
2525
, ShortHostName("")
2626
, ClusterName("")
27+
, TenantName("")
2728
{
2829
Append(minVal, maxVal, func);
2930
}
@@ -47,6 +48,7 @@ namespace NActors {
4748
, Format(PLAIN_FULL_FORMAT)
4849
, ShortHostName("")
4950
, ClusterName("")
51+
, TenantName("")
5052
{
5153
}
5254

ydb/library/actors/core/log_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ namespace NActors {
9191
ELogFormat Format;
9292
TString ShortHostName;
9393
TString ClusterName;
94+
TString TenantName;
9495
TString MessagePrefix;
96+
ui32 NodeId;
9597

9698
// The best way to provide minVal, maxVal and func is to have
9799
// protobuf enumeration of components. In this case protoc

0 commit comments

Comments
 (0)