This repository was archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure the sink (and app) do not crash when the ES is unreachable …
…during the discovery of the version. (#359)
- Loading branch information
Showing
9 changed files
with
118 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "2.1.500" | ||
"version": "2.1.807" | ||
} | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
...ilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionHandlesUnavailableServerTests.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,45 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Serilog.Debugging; | ||
|
||
namespace Serilog.Sinks.Elasticsearch.Tests.Templating | ||
{ | ||
[Collection("isolation")] | ||
public class DiscoverVersionHandlesUnavailableServerTests : ElasticsearchSinkTestsBase | ||
{ | ||
[Fact] | ||
public void Should_not_crash_when_server_is_unavaiable() | ||
{ | ||
// If this crashes, the test will fail | ||
CreateLoggerThatCrashes(); | ||
} | ||
|
||
[Fact] | ||
public void Should_write_error_to_self_log() | ||
{ | ||
var selfLogMessages = new StringBuilder(); | ||
SelfLog.Enable(new StringWriter(selfLogMessages)); | ||
|
||
// Exception occurs on creation - should be logged | ||
CreateLoggerThatCrashes(); | ||
|
||
var selfLogContents = selfLogMessages.ToString(); | ||
selfLogContents.Should().Contain("Failed to discover the cluster version"); | ||
|
||
} | ||
|
||
private static ILogger CreateLoggerThatCrashes() | ||
{ | ||
var loggerConfig = new LoggerConfiguration() | ||
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9199")) | ||
{ | ||
DetectElasticsearchVersion = true | ||
}); | ||
|
||
return loggerConfig.CreateLogger(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
test/Serilog.Sinks.Elasticsearch.Tests/Templating/DiscoverVersionTests.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,39 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Serilog.Sinks.Elasticsearch.Tests.Templating | ||
{ | ||
public class DiscoverVersionTests : ElasticsearchSinkTestsBase | ||
{ | ||
private readonly Tuple<Uri,int> _templateGet; | ||
|
||
public DiscoverVersionTests() | ||
{ | ||
_options.DetectElasticsearchVersion = true; | ||
|
||
var loggerConfig = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.Enrich.WithMachineName() | ||
.WriteTo.ColoredConsole() | ||
.WriteTo.Elasticsearch(_options); | ||
|
||
var logger = loggerConfig.CreateLogger(); | ||
using ((IDisposable) logger) | ||
{ | ||
logger.Error("Test exception. Should not contain an embedded exception object."); | ||
} | ||
|
||
this._seenHttpGets.Should().NotBeNullOrEmpty().And.HaveCount(1); | ||
_templateGet = this._seenHttpGets[0]; | ||
} | ||
|
||
|
||
[Fact] | ||
public void TemplatePutToCorrectUrl() | ||
{ | ||
var uri = _templateGet.Item1; | ||
uri.AbsolutePath.Should().Be("/_cat/nodes"); | ||
} | ||
} | ||
} |
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