Skip to content

Commit 8fe088e

Browse files
dev: added structure log in Serverless Container
1 parent b9e2012 commit 8fe088e

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.Logging;
4+
using NLog.Extensions.Logging;
45
using Ydb.Sdk.Ado;
56
using Ydb.Sdk.Yc;
67

@@ -11,8 +12,9 @@
1112
.GetConnectionString("ServerlessYDB") ??
1213
throw new InvalidOperationException("ConnectionString.ServerlessYDB is empty.");
1314

14-
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information));
15+
var loggerFactory = LoggerFactory.Create(builder => builder.AddNLog());
1516
var logger = loggerFactory.CreateLogger<Program>();
17+
1618
var stopwatch = Stopwatch.StartNew();
1719
stopwatch.Start();
1820

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container.csproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="CommandLineParser" Version="2.8.0" />
13-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
14-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
15-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
16-
<PackageReference Include="Ydb.Sdk.Yc.Auth" Version="0.2.0" />
17-
<PackageReference Include="Ydb.Sdk" Version="0.18.0" />
12+
<PackageReference Include="CommandLineParser" Version="2.8.0"/>
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0"/>
14+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0"/>
15+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
16+
<PackageReference Include="NLog.Extensions.Logging" Version="5.5.0"/>
17+
<PackageReference Include="Ydb.Sdk.Yc.Auth" Version="0.2.0"/>
18+
<PackageReference Include="Ydb.Sdk" Version="0.18.0"/>
1819

1920
<None Update="appsettings.json">
2021
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2122
</None>
23+
<None Update="nlog.config">
24+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
25+
</None>
2226
</ItemGroup>
2327
</Project>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"ConnectionStrings": {
3-
"ServerlessYDB": "UseTls=true;Host=<host>;Port=2135;Database=<database>"
3+
"ServerlessYDB": "UseTls=true;Host=ydb.serverless.yandexcloud.net;Port=2135;Database=/ru-central1/b1g8skpblkos03malf3s/etnl7uv72neobbgiahii"
44
}
55
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
6+
<targets>
7+
<target xsi:type="Console" name="ConsoleTarget">
8+
<layout xsi:type="JsonLayout">
9+
<attribute name="time" layout="${longdate}" />
10+
<attribute name="level" layout="${level:upperCase=true}" />
11+
<attribute name="logger" layout="${logger}" />
12+
<attribute name="message" layout="${message}" />
13+
<attribute name='exception' layout='${exception:format=toString,StackTrace}' />
14+
</layout>
15+
</target>
16+
</targets>
17+
18+
<rules>
19+
<logger name="*" minlevel="Info" writeTo="ConsoleTarget" />
20+
</rules>
21+
</nlog>

src/Ydb.Sdk/src/Pool/ChannelPool.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Security.Cryptography.X509Certificates;
55
using Grpc.Core;
66
using Grpc.Net.Client;
7+
using Grpc.Net.Client.Configuration;
78
using Microsoft.Extensions.Logging;
89

910
namespace Ydb.Sdk.Pool;
@@ -97,7 +98,11 @@ public GrpcChannel CreateChannel(string endpoint)
9798
LoggerFactory = _loggerFactory,
9899
DisposeHttpClient = true,
99100
MaxSendMessageSize = _config.MaxSendMessageSize,
100-
MaxReceiveMessageSize = _config.MaxReceiveMessageSize
101+
MaxReceiveMessageSize = _config.MaxReceiveMessageSize,
102+
ServiceConfig = new ServiceConfig
103+
{
104+
LoadBalancingConfigs = { new RoundRobinConfig() }
105+
}
101106
};
102107

103108
var httpHandler = new SocketsHttpHandler
@@ -110,13 +115,13 @@ public GrpcChannel CreateChannel(string endpoint)
110115
};
111116

112117
// https://github.com/grpc/grpc-dotnet/issues/2312#issuecomment-1790661801
113-
httpHandler.Properties["__GrpcLoadBalancingDisabled"] = true;
118+
// httpHandler.Properties["__GrpcLoadBalancingDisabled"] = true;
114119

115120
channelOptions.HttpHandler = httpHandler;
116121

117122
if (ServerCertificates.Count == 0)
118123
{
119-
return GrpcChannel.ForAddress(endpoint, channelOptions);
124+
return GrpcChannel.ForAddress(new Uri(endpoint) { }, channelOptions);
120125
}
121126

122127
httpHandler.SslOptions.RemoteCertificateValidationCallback +=

0 commit comments

Comments
 (0)