Self Diagnostics bug fixes (#2095)

* Self Diagnostics bug fixes

* Add comments

* Remove unnecesary trait

Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
This commit is contained in:
xiang17 2021-06-22 12:07:11 -07:00 committed by GitHub
parent 8948fcee13
commit db6dc757c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 27 deletions

View File

@ -274,10 +274,18 @@ namespace OpenTelemetry.Internal
this.cancellationTokenSource.Dispose();
}
// Dispose EventListner before files, because EventListner writes to files.
if (this.eventListener != null)
{
this.eventListener.Dispose();
}
// Ensure worker thread properly finishes.
// Or it might have created another MemoryMappedFile in that thread
// after the CloseLogFile() below is called.
this.CloseLogFile();
// Dispose ThreadLocal variables after the file handles are disposed.
this.viewStream.Dispose();
this.memoryMappedFileCache.Dispose();
}

View File

@ -67,6 +67,7 @@ namespace OpenTelemetry.Internal
public override void Dispose()
{
this.Dispose(true);
base.Dispose();
GC.SuppressFinalize(this);
}
@ -85,6 +86,11 @@ namespace OpenTelemetry.Internal
/// <returns>The position of the buffer after the last byte of the resulting sequence.</returns>
internal static int EncodeInBuffer(string str, bool isParameter, byte[] buffer, int position)
{
if (string.IsNullOrEmpty(str))
{
return position;
}
int charCount = str.Length;
int ellipses = isParameter ? "{...}\n".Length : "...\n".Length;
@ -338,9 +344,6 @@ namespace OpenTelemetry.Internal
}
this.disposedValue = true;
// Should call base.Dispose(disposing) here, but EventListener doesn't have Dispose(bool).
base.Dispose();
}
}
}

View File

@ -21,7 +21,6 @@ namespace OpenTelemetry.Internal.Tests
public class SelfDiagnosticsConfigParserTest
{
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseFilePath_Success()
{
string configJson = "{ \t \n "
@ -33,7 +32,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseFilePath_MissingField()
{
string configJson = @"{
@ -44,7 +42,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseFileSize()
{
string configJson = @"{
@ -56,7 +53,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseFileSize_CaseInsensitive()
{
string configJson = @"{
@ -69,7 +65,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseFileSize_MissingField()
{
string configJson = @"{
@ -80,7 +75,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigParser_TryParseLogLevel()
{
string configJson = @"{

View File

@ -36,7 +36,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigRefresher_OmitAsConfigured()
{
try
@ -63,7 +62,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsConfigRefresher_CaptureAsConfigured()
{
try

View File

@ -31,7 +31,6 @@ namespace OpenTelemetry.Internal.Tests
private const string EllipsesWithBrackets = "{...}\n";
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_constructor_Invalid_Input()
{
// no configRefresher object
@ -42,7 +41,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EventSourceSetup_LowerSeverity()
{
var configRefresherMock = new Mock<SelfDiagnosticsConfigRefresher>();
@ -54,7 +52,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EventSourceSetup_HigherSeverity()
{
var configRefresherMock = new Mock<SelfDiagnosticsConfigRefresher>();
@ -68,7 +65,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_WriteEvent()
{
// Arrange
@ -94,7 +90,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_DateTimeGetBytes()
{
var configRefresherMock = new Mock<SelfDiagnosticsConfigRefresher>();
@ -133,7 +128,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EmitEvent_OmitAsConfigured()
{
// Arrange
@ -159,7 +153,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EmitEvent_CaptureAsConfigured()
{
// Arrange
@ -183,7 +176,15 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_Null()
{
byte[] buffer = new byte[20];
int startPos = 0;
int endPos = SelfDiagnosticsEventListener.EncodeInBuffer(null, false, buffer, startPos);
Assert.Equal(startPos, endPos);
}
[Fact]
public void SelfDiagnosticsEventListener_EncodeInBuffer_Empty()
{
byte[] buffer = new byte[20];
@ -194,7 +195,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_EnoughSpace()
{
byte[] buffer = new byte[20];
@ -208,7 +208,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEnoughSpaceForFullString()
{
byte[] buffer = new byte[20];
@ -222,7 +221,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEvenSpaceForTruncatedString()
{
byte[] buffer = new byte[20];
@ -233,7 +231,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEvenSpaceForTruncationEllipses()
{
byte[] buffer = new byte[20];
@ -243,7 +240,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_EnoughSpace()
{
byte[] buffer = new byte[20];
@ -254,7 +250,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEnoughSpaceForFullString()
{
byte[] buffer = new byte[20];
@ -265,7 +260,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpaceForTruncatedString()
{
byte[] buffer = new byte[20];
@ -276,7 +270,6 @@ namespace OpenTelemetry.Internal.Tests
}
[Fact]
[Trait("Platform", "Any")]
public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpaceForTruncationEllipses()
{
byte[] buffer = new byte[20];