-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Akka.IO: added TcpListenerStatistics
and subscription methods
#7633
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
Conversation
This enables the `Akka.IO.TcpListener` to periodically publish connectivity statistics to subscribers on `10s` intervals - designed to help create telemetry for servers built on top of Akka.IO. close akkadotnet#7631
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.
Detailed my changes
|
||
[!code-csharp[Main](../../../src/core/Akka.Docs.Tests/Networking/IO/EchoConnection.cs?name=echoConnection)] | ||
|
||
### TCP Listener Statistics |
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.
Added documentation along with a small example on how to use this
{ | ||
public Event() { } | ||
} | ||
public interface ITcpQuery : Akka.Actor.INoSerializationVerificationNeeded { } |
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.
I hate that Message
is the base class for all of these TCP messages. They really just should implement an interface, so I did it that way for these new query types.
// </echoServer> | ||
|
||
// <echoServerWithStats> | ||
public class EchoServerWithStats : UntypedActor |
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.
Sample for the documentation
} | ||
|
||
[Fact] | ||
public async Task A_TCP_Listener_must_provide_metrics() |
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.
Quick integration test
public class Message : INoSerializationVerificationNeeded { } | ||
|
||
#region user commands | ||
|
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.
The new message types we added - pretty self-explanatory
|
||
default: | ||
return false; | ||
return HandleStatsMessages(message); |
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.
Handle the stats at the end
switch (saea.SocketError) | ||
{ | ||
case SocketError.Success: | ||
_acceptCount++; |
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.
Increment when we successfully accept
.WithDeploy(Deploy.Local)); | ||
|
||
// set up the watch for monitoring purposes | ||
Context.WatchWith(incomingConnection, ConnectionTerminated.Instance); |
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.
Create notification for detecting disconnect
case SocketError.TryAgain: | ||
case SocketError.TimedOut: | ||
case SocketError.WouldBlock: | ||
_retryCount++; |
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.
Increment retry count - if this is high then we might have some problems that can be adjusted via config tuning (i.e. TCP backlog)
new RetryAccept(saea), ActorRefs.NoSender); | ||
break; | ||
default: | ||
_failedCount++; |
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.
If we get fatal errors while trying to accept connections then we die to maybe this metric is kind of pointless, but I'm keeping it so we can refine later
var metrics = await probe.ExpectMsgAsync<Tcp.TcpListenerStatistics>(); | ||
|
||
Assert.Equal(1, metrics.AcceptedIncomingConnections); | ||
// |
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.
Had to comment out all of this code due to #7634
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.
LGTM
Changes
This enables the
Akka.IO.TcpListener
to periodically publish connectivity statistics to subscribers on10s
intervals - designed to help create telemetry for servers built on top of Akka.IO.close #7631
Checklist
For significant changes, please ensure that the following have been completed (delete if not relevant):
TcpListener
/TcpConnection
actors #7631