-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Convert SignalR EventSource usage to new pattern #11130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee8c2e2
wip
BrennanConroy 35497d9
stash
BrennanConroy 1ca9ea9
Convert SignalR EventSource usage to new pattern
BrennanConroy 7b14f1a
always increment counters
BrennanConroy 6efe390
naming
BrennanConroy 420dc3d
fix name
BrennanConroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Diagnostics.Tracing; | ||
|
||
namespace Microsoft.AspNetCore.Internal | ||
{ | ||
internal class TestEventListener : EventListener | ||
{ | ||
private readonly int _eventId; | ||
|
||
public TestEventListener(int eventId) | ||
{ | ||
_eventId = eventId; | ||
} | ||
|
||
public EventWrittenEventArgs EventData { get; private set; } | ||
|
||
protected override void OnEventWritten(EventWrittenEventArgs eventData) | ||
{ | ||
// The tests here run in parallel, capture the EventData that a test is explicitly | ||
// looking for and not give back other tests' data. | ||
if (eventData.EventId == _eventId) | ||
{ | ||
EventData = eventData; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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
112 changes: 112 additions & 0 deletions
112
src/SignalR/common/Http.Connections/test/Internal/HttpConnectionsEventSourceTests.cs
This file contains hidden or 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,112 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics.Tracing; | ||
using Microsoft.AspNetCore.Internal; | ||
using Microsoft.Extensions.Internal; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Http.Connections.Internal | ||
{ | ||
public class HttpConnectionsEventSourceTests | ||
{ | ||
[Fact] | ||
public void MatchesNameAndGuid() | ||
{ | ||
// Arrange & Act | ||
var eventSource = new HttpConnectionsEventSource(); | ||
|
||
// Assert | ||
Assert.Equal("Microsoft-AspNetCore-Http-Connections", eventSource.Name); | ||
Assert.Equal(Guid.Parse("a81dd8b5-9721-5e7a-d465-d5b9caa864dc"), eventSource.Guid); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionStart() | ||
{ | ||
// Arrange | ||
var expectedEventId = 1; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
httpConnectionsEventSource.ConnectionStart("1"); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionStart", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Started connection '{0}'.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionStop() | ||
{ | ||
// Arrange | ||
var expectedEventId = 2; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
var stopWatch = ValueStopwatch.StartNew(); | ||
httpConnectionsEventSource.ConnectionStop("1", stopWatch); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionStop", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Stopped connection '{0}'.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void ConnectionTimedOut() | ||
{ | ||
// Arrange | ||
var expectedEventId = 3; | ||
var eventListener = new TestEventListener(expectedEventId); | ||
var httpConnectionsEventSource = GetHttpConnectionEventSource(); | ||
eventListener.EnableEvents(httpConnectionsEventSource, EventLevel.Informational); | ||
|
||
// Act | ||
httpConnectionsEventSource.ConnectionTimedOut("1"); | ||
|
||
// Assert | ||
var eventData = eventListener.EventData; | ||
Assert.NotNull(eventData); | ||
Assert.Equal(expectedEventId, eventData.EventId); | ||
Assert.Equal("ConnectionTimedOut", eventData.EventName); | ||
Assert.Equal(EventLevel.Informational, eventData.Level); | ||
Assert.Same(httpConnectionsEventSource, eventData.EventSource); | ||
Assert.Equal("Connection '{0}' timed out.", eventData.Message); | ||
Assert.Collection(eventData.Payload, | ||
arg => | ||
{ | ||
Assert.Equal("1", arg); | ||
}); | ||
} | ||
|
||
private static HttpConnectionsEventSource GetHttpConnectionEventSource() | ||
{ | ||
return new HttpConnectionsEventSource(Guid.NewGuid().ToString()); | ||
} | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to
Microsoft.AspNetCore.Http.Connections
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also normalize the counter names? The hosting ones follow the pattern of "current-requests", and we currently use "CurrentConnections".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, lets unify the patterns.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventSource names have always been
Microsoft-Things-Separated-By-Dashes
, why would we change that?Also, we should update the hosting ones since these have already shipped with these names. Plus
snake-case
is so un-.NET ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/dotnet/coreclr/blob/e2b3130f4d0c9f1b759a769f4d344ee72a55b771/src/System.Private.CoreLib/src/System/Diagnostics/Eventing/RuntimeEventSource.cs#L12
Inconsistent AF. This is something we should resolve as part of preview7 (Hosting is updated BTW).
cc @noahfalk
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's unfortunate that corefx didn't follow our completely undocumented design pattern from 2.2 here 😝. Hard to fix corefx now though. I'm OK with establishing
snake-case
as the convention if that's the case.If we do that we have two options:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one option, use the new pattern.