Akka.IO: added TcpListenerStatistics and subscription methods#7633
Akka.IO: added TcpListenerStatistics and subscription methods#7633Aaronontheweb merged 4 commits intoakkadotnet:devfrom
TcpListenerStatistics and subscription methods#7633Conversation
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
Aaronontheweb
left a comment
There was a problem hiding this comment.
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.
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.
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.
Sample for the documentation
| } | ||
|
|
||
| [Fact] | ||
| public async Task A_TCP_Listener_must_provide_metrics() |
There was a problem hiding this comment.
Quick integration test
| public class Message : INoSerializationVerificationNeeded { } | ||
|
|
||
| #region user commands | ||
|
|
There was a problem hiding this comment.
The new message types we added - pretty self-explanatory
|
|
||
| default: | ||
| return false; | ||
| return HandleStatsMessages(message); |
There was a problem hiding this comment.
Handle the stats at the end
| switch (saea.SocketError) | ||
| { | ||
| case SocketError.Success: | ||
| _acceptCount++; |
There was a problem hiding this comment.
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.
Create notification for detecting disconnect
| case SocketError.TryAgain: | ||
| case SocketError.TimedOut: | ||
| case SocketError.WouldBlock: | ||
| _retryCount++; |
There was a problem hiding this comment.
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.
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.
Had to comment out all of this code due to #7634
Changes
This enables the
Akka.IO.TcpListenerto periodically publish connectivity statistics to subscribers on10sintervals - 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/TcpConnectionactors #7631