-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NLog Elastic Target supports EcsIndexChannel with IndexFormat (#429)
- Loading branch information
Showing
3 changed files
with
158 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests-integration/Elastic.NLog.Targets.IntegrationTests/LoggingToIndexIngestionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Elastic.Channels.Diagnostics; | ||
using Elastic.Clients.Elasticsearch.IndexManagement; | ||
using Elastic.CommonSchema; | ||
using Elastic.Ingest.Elasticsearch; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NLog.Targets.Elastic.IntegrationTests | ||
{ | ||
public class LoggingToIndexIngestionTests : TestBase | ||
{ | ||
public LoggingToIndexIngestionTests(LoggingCluster cluster, ITestOutputHelper output) : base(cluster, output) { } | ||
|
||
[Fact] | ||
public async Task EnsureDocumentsEndUpInIndex() | ||
{ | ||
var indexPrefix = "catalog-data-"; | ||
var indexFormat = indexPrefix + "{0:yyyy.MM.dd}"; | ||
|
||
using var _ = CreateLogger(out var logger, out var provider, out var @namespace, out var waitHandle, out var listener, (cfg) => | ||
{ | ||
cfg.IndexFormat = indexFormat; | ||
cfg.DataStreamType = "x"; | ||
cfg.DataStreamSet = "dotnet"; | ||
var nodesUris = string.Join(",", Client.ElasticsearchClientSettings.NodePool.Nodes.Select(n => n.Uri.ToString()).ToArray()); | ||
cfg.NodeUris = nodesUris; | ||
cfg.NodePoolType = ElasticPoolType.Static; | ||
}); | ||
|
||
var date = DateTimeOffset.Now; | ||
var indexName = string.Format(indexFormat, date); | ||
|
||
var index = await Client.Indices.GetAsync(new GetIndexRequest(indexName)); | ||
index.Indices.Should().BeNullOrEmpty(); | ||
|
||
logger.Error("an error occurred!"); | ||
|
||
if (!waitHandle.WaitOne(TimeSpan.FromSeconds(10))) | ||
throw new Exception($"No flush occurred in 10 seconds: {listener}", listener.ObservedException); | ||
|
||
listener.PublishSuccess.Should().BeTrue("{0}", listener); | ||
listener.ObservedException.Should().BeNull(); | ||
|
||
var refreshResult = await Client.Indices.RefreshAsync(indexName); | ||
refreshResult.IsValidResponse.Should().BeTrue("{0}", refreshResult.DebugInformation); | ||
var searchResult = await Client.SearchAsync<EcsDocument>(s => s.Indices(indexName)); | ||
searchResult.Total.Should().Be(1); | ||
|
||
var storedDocument = searchResult.Documents.First(); | ||
storedDocument.Message.Should().Be("an error occurred!"); | ||
|
||
var hit = searchResult.Hits.First(); | ||
hit.Index.Should().Be(indexName); | ||
} | ||
} | ||
} |