Skip to content

Commit

Permalink
update elasticsearch.net to include default memory streams to prevent…
Browse files Browse the repository at this point in the history
… extensive memory usage due to pooling.

Allow for insecure HTTPS connections, bypassing cert validation
  • Loading branch information
Alex McCool committed Nov 4, 2021
1 parent bf103c4 commit 95d09ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 3 additions & 1 deletion example/SampleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public Program()
.AddEventSourceLogger()
.AddElasticSearch(options =>
{
options.ElasticsearchEndpoint = new Uri(@"http://localhost:9200/");
//options.ElasticsearchEndpoint = new Uri(@"http://localhost:9200/");
//options.ElasticsearchEndpoint = new Uri(@"https://elasticsearch.mgmc.rauland/");
options.ElasticsearchEndpoint = new Uri(@"http://es.devint.dev-r5ead.net:9200/");
//options.IndexName = "trace";
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
<Authors>amccool</Authors>
<Product>AM.Extensions.Logging.ElasticSearch</Product>
<Description>Microsoft.Extensions.Logging posting to ElasticSearch</Description>
<Copyright>2029</Copyright>
<Copyright>2021</Copyright>
<PackageTags>ElasticSearch;ILogger;Monitoring;kibana;Microsoft.Extensions.Logging;logging;MEL</PackageTags>
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elasticsearch.Net" Version="[6.8.2,7.0)" />
<PackageReference Include="Elasticsearch.Net" Version="6.8.9" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Reactive.Linq" Version="3.1.0" />
<PackageReference Include="System.Reactive.Linq" Version="3.1.1" />
</ItemGroup>

</Project>
28 changes: 16 additions & 12 deletions src/ElasticSearch.Extensions.Logging/ElasticSearchLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Elasticsearch.Net;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -77,6 +78,7 @@ private ElasticLowLevelClient CreateNewElasticLowLevelClient(Uri elasticSearchEn
var singleNode = new SingleNodeConnectionPool(_optionsMonitor.CurrentValue.ElasticsearchEndpoint);

var cc = new ConnectionConfiguration(singleNode, new ElasticsearchJsonNetSerializer())
//.ServerCertificateValidationCallback((obj, cert, chain, policyerrors) => true)
.EnableHttpPipelining()
.EnableHttpCompression()
.ThrowExceptions();
Expand Down Expand Up @@ -137,18 +139,20 @@ private async Task WriteDirectlyToESAsBatch(IEnumerable<JObject> jos)
var bb = jos.Zip(indxC, (f, s) => new object[] { s, f });
var bbo = bb.SelectMany(a => a);

try
{
//await Client.BulkPutAsync<VoidResponse>(Index, DocumentType, bbo.ToArray(), br => br.Refresh(false));
await Client.BulkPutAsync<VoidResponse>(Index, DocumentType,
PostData.MultiJson(bbo.ToArray()),
new BulkRequestParameters { Refresh = Refresh.False });
}
catch (Exception)
{
//eat the exception, we cant really do much with it anyways
//Debug.WriteLine(ex.Message);
}
_ = Client.BulkPutAsync<VoidResponse>(Index, DocumentType,
PostData.MultiJson(bbo.ToArray()),
new BulkRequestParameters { Refresh = Refresh.False })
.ContinueWith(x =>
{
if (x.IsFaulted)
{
Debug.WriteLine(x.Exception);
}
},
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Current);

}

private void WriteToQueueForProcessing(JObject jo)
Expand Down

0 comments on commit 95d09ce

Please sign in to comment.