Skip to content

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented May 12, 2025

Changes

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 #7631

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

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
Copy link
Member Author

@Aaronontheweb Aaronontheweb left a 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
Copy link
Member Author

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 { }
Copy link
Member Author

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
Copy link
Member Author

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()
Copy link
Member Author

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

Copy link
Member Author

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);
Copy link
Member Author

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++;
Copy link
Member Author

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);
Copy link
Member Author

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++;
Copy link
Member Author

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++;
Copy link
Member Author

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

@Aaronontheweb Aaronontheweb marked this pull request as ready for review May 12, 2025 19:00
var metrics = await probe.ExpectMsgAsync<Tcp.TcpListenerStatistics>();

Assert.Equal(1, metrics.AcceptedIncomingConnections);
//
Copy link
Member Author

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

Copy link
Contributor

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Arkatufus Arkatufus enabled auto-merge (squash) May 12, 2025 19:15
@Aaronontheweb Aaronontheweb disabled auto-merge May 12, 2025 20:18
@Aaronontheweb Aaronontheweb merged commit 2af5a35 into akkadotnet:dev May 12, 2025
7 of 11 checks passed
@Aaronontheweb Aaronontheweb deleted the akka-io-metrics branch May 12, 2025 20:18
@Arkatufus Arkatufus added this to the 1.5.42 milestone May 21, 2025
This was referenced Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Akka.IO: enable optional metrics subscriptions for TcpListener / TcpConnection actors

2 participants