Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
949a67e
Add multi-targeting (netstandard2.0 + net10.0) and initial metrics in…
Copilot Apr 24, 2026
950d97b
Add per-connection metrics with peer ID tags and observable gauge for…
Copilot Apr 24, 2026
543866e
Tag MessagesReceived metric with sender peer ID for per-connection co…
Copilot Apr 24, 2026
e04af38
Track bus metrics per instance using a stable Interlocked-incremented ID
Copilot Apr 28, 2026
e1e006b
Split ZebusMetrics into per-service classes and remove bus active metric
Copilot Apr 28, 2026
4c7958d
Remove trailing newlines from new metric files
Copilot Apr 28, 2026
c3c154c
Restructure #ifdef so metric classes are declared but empty on netsta…
Copilot Apr 28, 2026
4dd924d
Add byte count per message metrics (zebus.transport.bytes.sent/received)
Copilot Apr 30, 2026
40f6833
Keep serialization constructors in all targets, suppress SYSLIB0051 l…
Copilot Aug 18, 2026
c078976
Replace NETCOREAPP with NET in conditional compilation symbols
Copilot Aug 18, 2026
4d4d16a
Move NET guards inside Metrics classes; make call sites unconditional
Copilot Aug 18, 2026
61f531c
Move all Metrics types into Monitoring namespace; fix formatting
Copilot Aug 18, 2026
4d43fa6
Add ConnectionStateGauge wrapper type and fix ZmqTransport formatting
Copilot Aug 18, 2026
f8d2dc3
Extract RaisePeerUpdated helper in PeerDirectoryClient
Copilot Aug 18, 2026
08dca49
Restore missing if guard for PeerSubscriptionsUpdated in PeerDirector…
Copilot Aug 18, 2026
3295fc1
Add gated feature that replace peerid trailing guid by ".Client".
Kuinox Sep 23, 2026
8f47cdb
Remove peer directory metrics
ocoanet Oct 16, 2026
e5ed6d6
Make metric publication non-static
ocoanet Oct 19, 2026
bff19e4
Pass metric publisher to outbound sockets
ocoanet Oct 19, 2026
6bb8268
Report sent messages in socket instead of transport
ocoanet Oct 19, 2026
c9ed40c
Adjust connected socket metric publication
ocoanet Oct 19, 2026
e18c89e
Rename method in IZebusMetricPublisher
ocoanet Oct 21, 2026
ad34ae7
Metrics will go through the interface and we wont double target for now.
Kuinox Nov 11, 2026
e7b6388
Remove unused method from ZmqTransport
ocoanet Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Abc.Zebus/Initialization/ZebusRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public ZebusRegistry()
ForSingletonOf<IStoppingStrategy>().Use<DefaultStoppingStrategy>();

ForSingletonOf<IZmqOutboundSocketErrorHandler>().Use<DefaultZmqOutboundSocketErrorHandler>();
ForSingletonOf<IZebusMetricPublisher>().Use<NoopZebusMetricPublisher>();
}
}
14 changes: 14 additions & 0 deletions src/Abc.Zebus/Monitoring/IZebusMetricPublisher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Abc.Zebus.Monitoring;

public interface IZebusMetricPublisher
{
void AddMessagesSent(long delta, PeerId peerId);
void AddMessagesReceived(long delta, PeerId peerId);
void AddBytesSent(long delta, PeerId peerId);
void AddBytesReceived(long delta, PeerId peerId);
void AddMessageSendFailures(long delta, PeerId peerId);
void AddPeerConnections(long delta, PeerId peerId);
void AddPeerDisconnections(long delta, PeerId peerId);
void AddPeerConnectionFailures(long delta, PeerId peerId);
void UpdateConnectionStatus(bool isConnected, PeerId peerId);
}
40 changes: 40 additions & 0 deletions src/Abc.Zebus/Monitoring/NoopZebusMetricPublisher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Abc.Zebus.Monitoring;

public class NoopZebusMetricPublisher : IZebusMetricPublisher
{
public void AddMessagesSent(long delta, PeerId peerId)
{
}

public void AddMessagesReceived(long delta, PeerId peerId)
{
}

public void AddBytesSent(long delta, PeerId peerId)
{
}

public void AddBytesReceived(long delta, PeerId peerId)
{
}

public void AddMessageSendFailures(long delta, PeerId peerId)
{
}

public void AddPeerConnections(long delta, PeerId peerId)
{
}

public void AddPeerDisconnections(long delta, PeerId peerId)
{
}

public void AddPeerConnectionFailures(long delta, PeerId peerId)
{
}

public void UpdateConnectionStatus(bool isConnected, PeerId peerId)
{
}
}
31 changes: 30 additions & 1 deletion src/Abc.Zebus/Transport/ZmqOutboundSocket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using Abc.Zebus.Monitoring;
using Abc.Zebus.Transport.Zmq;
using Microsoft.Extensions.Logging;

Expand All @@ -13,22 +14,44 @@ internal class ZmqOutboundSocket
private readonly ZmqContext _context;
private readonly ZmqSocketOptions _options;
private readonly IZmqOutboundSocketErrorHandler _errorHandler;
private readonly IZebusMetricPublisher _metricPublisher;
private ZmqSocket? _socket;
private int _failedSendCount;
private bool _isInClosedState;
private TimeSpan _closedStateDuration;
private bool _isConnected;

public ZmqOutboundSocket(ZmqContext context, PeerId peerId, string endPoint, ZmqSocketOptions options, IZmqOutboundSocketErrorHandler errorHandler)
: this(context, peerId, endPoint, options, errorHandler, new NoopZebusMetricPublisher())
{

}

public ZmqOutboundSocket(ZmqContext context, PeerId peerId, string endPoint, ZmqSocketOptions options, IZmqOutboundSocketErrorHandler errorHandler, IZebusMetricPublisher metricPublisher)
{
_context = context;
_options = options;
_errorHandler = errorHandler;
_metricPublisher = metricPublisher;
PeerId = peerId;
EndPoint = endPoint;
}

public PeerId PeerId { get; }
public bool IsConnected { get; private set; }

public bool IsConnected
{
get => _isConnected;
private set
{
if (_isConnected == value)
return;

_isConnected = value;
_metricPublisher.UpdateConnectionStatus(value, PeerId);
}
}

public string EndPoint { get; private set; }

public void ConnectFor(TransportMessage message)
Expand All @@ -42,6 +65,7 @@ public void ConnectFor(TransportMessage message)
_socket.Connect(EndPoint);

IsConnected = true;
_metricPublisher.AddPeerConnections(1, PeerId);

_logger.LogInformation($"Socket connected, Peer: {PeerId}, EndPoint: {EndPoint}");
}
Expand All @@ -53,6 +77,7 @@ public void ConnectFor(TransportMessage message)

_logger.LogError(ex, $"Unable to connect socket, Peer: {PeerId}, EndPoint: {EndPoint}");
_errorHandler.OnConnectException(PeerId, EndPoint, ex);
_metricPublisher.AddPeerConnectionFailures(1, PeerId);

SwitchToClosedState(_options.ClosedStateDurationAfterConnectFailure);
}
Expand Down Expand Up @@ -95,6 +120,7 @@ public void Disconnect()
{
_socket!.SetOption(ZmqSocketOption.LINGER, 0);
_socket!.Dispose();
_metricPublisher.AddPeerDisconnections(1, PeerId);

_logger.LogInformation($"Socket disconnected, Peer: {PeerId}");
}
Expand All @@ -115,6 +141,8 @@ public void Send(byte[] buffer, int length, TransportMessage message)
if (_socket!.TrySend(buffer, 0, length, out var error))
{
_failedSendCount = 0;
_metricPublisher.AddMessagesSent(1, PeerId);
_metricPublisher.AddBytesSent(length, PeerId);
return;
}

Expand All @@ -123,6 +151,7 @@ public void Send(byte[] buffer, int length, TransportMessage message)

_logger.LogError($"Unable to send message, destination peer: {PeerId}, MessageTypeId: {message.MessageTypeId}, MessageId: {message.Id}, Error: {errorMessage}");
_errorHandler.OnSendFailed(PeerId, EndPoint, message.MessageTypeId, message.Id);
_metricPublisher.AddMessageSendFailures(1, PeerId);

if (_failedSendCount >= _options.SendRetriesBeforeSwitchingToClosedState)
SwitchToClosedState(_options.ClosedStateDurationAfterSendFailure);
Expand Down
16 changes: 14 additions & 2 deletions src/Abc.Zebus/Transport/ZmqTransport.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Abc.Zebus.Directory;
using Abc.Zebus.Monitoring;
using Abc.Zebus.Serialization.Protobuf;
using Abc.Zebus.Transport.Zmq;
using Abc.Zebus.Util;
Expand All @@ -17,6 +17,7 @@ public class ZmqTransport : ITransport
private readonly IZmqTransportConfiguration _configuration;
private readonly ZmqSocketOptions _socketOptions;
private readonly IZmqOutboundSocketErrorHandler _errorHandler;
private readonly IZebusMetricPublisher _metricPublisher;
private readonly ZmqEndPoint _configuredInboundEndPoint;
private ILogger _logger = ZebusLogManager.GetLogger(typeof(ZmqTransport));
private ConcurrentDictionary<PeerId, ZmqOutboundSocket> _outboundSockets = new();
Expand All @@ -33,10 +34,16 @@ public class ZmqTransport : ITransport
private bool _isRunning;

public ZmqTransport(IZmqTransportConfiguration configuration, ZmqSocketOptions socketOptions, IZmqOutboundSocketErrorHandler errorHandler)
: this(configuration, socketOptions, errorHandler, new NoopZebusMetricPublisher())
{
}

public ZmqTransport(IZmqTransportConfiguration configuration, ZmqSocketOptions socketOptions, IZmqOutboundSocketErrorHandler errorHandler, IZebusMetricPublisher metricPublisher)
{
_configuration = configuration;
_socketOptions = socketOptions;
_errorHandler = errorHandler;
_metricPublisher = metricPublisher;
_configuredInboundEndPoint = new ZmqEndPoint(configuration.InboundEndPoint);
}

Expand Down Expand Up @@ -265,7 +272,12 @@ private void DeserializeAndForwardTransportMessage(ProtoBufferReader bufferReade
}

if (_isListening)
{
MessageReceived?.Invoke(transportMessage);
var senderId = transportMessage.Originator.SenderId;
_metricPublisher.AddMessagesReceived(1, senderId);
_metricPublisher.AddBytesReceived(bufferReader.Length, senderId);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -419,7 +431,7 @@ private ZmqOutboundSocket GetConnectedOutboundSocket(Peer peer, TransportMessage
{
if (!_outboundSockets.TryGetValue(peer.Id, out var outboundSocket))
{
outboundSocket = new ZmqOutboundSocket(_context!, peer.Id, peer.EndPoint, _socketOptions, _errorHandler);
outboundSocket = new ZmqOutboundSocket(_context!, peer.Id, peer.EndPoint, _socketOptions, _errorHandler, _metricPublisher);
outboundSocket.ConnectFor(transportMessage);

_outboundSockets.TryAdd(peer.Id, outboundSocket);
Expand Down
Loading