-
Notifications
You must be signed in to change notification settings - Fork 64
Add System.Diagnostics.Metrics for per-connection Zebus monitoring via net10.0 multi-targeting #120
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
base: master
Are you sure you want to change the base?
Changes from all commits
949a67e
950d97b
543866e
e04af38
e1e006b
4c7958d
c3c154c
4dd924d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,10 @@ public MessageProcessingException(string message, Exception? inner) | |
| { | ||
| } | ||
|
|
||
| #if !NETCOREAPP | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ltrzesniewski i suppose we want to keep this constructor ? |
||
| protected MessageProcessingException(SerializationInfo info, StreamingContext context) | ||
| : base(info, context) | ||
| { | ||
| } | ||
| #endif | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #if NET10_0_OR_GREATER | ||
| using System.Diagnostics.Metrics; | ||
| #endif | ||
|
|
||
| namespace Abc.Zebus.Monitoring; | ||
|
|
||
| /// <summary> | ||
| /// Provides <see cref="System.Diagnostics.Metrics"/> instruments for monitoring Zebus peer directory. | ||
| /// </summary> | ||
| internal static class DirectoryMetrics | ||
| { | ||
| #if NET10_0_OR_GREATER | ||
| internal static readonly UpDownCounter<int> KnownPeerCount = ZebusMetrics.Meter.CreateUpDownCounter<int>( | ||
| "zebus.directory.known_peers", | ||
| unit: "{peer}", | ||
| description: "Current number of known peers in the directory"); | ||
|
|
||
| internal static readonly Counter<long> PeerUpdates = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.directory.peer_updates", | ||
| unit: "{update}", | ||
| description: "Number of peer update events received"); | ||
| #endif | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #if NET10_0_OR_GREATER | ||
|
Kuinox marked this conversation as resolved.
|
||
| using System.Diagnostics.Metrics; | ||
| #endif | ||
|
|
||
| namespace Abc.Zebus.Monitoring; | ||
|
|
||
| /// <summary> | ||
| /// Provides <see cref="System.Diagnostics.Metrics"/> instruments for monitoring Zebus transport layer. | ||
| /// All per-connection metrics include a <c>zebus.peer.id</c> tag for filtering by individual peer. | ||
| /// </summary> | ||
| internal static class TransportMetrics | ||
| { | ||
| #if NET10_0_OR_GREATER | ||
| // Per-connection message counters | ||
| internal static readonly Counter<long> MessagesSent = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.messages.sent", | ||
| unit: "{message}", | ||
| description: "Number of transport messages sent to peers"); | ||
|
|
||
| internal static readonly Counter<long> MessagesReceived = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.messages.received", | ||
| unit: "{message}", | ||
| description: "Number of transport messages received"); | ||
|
|
||
| internal static readonly Counter<long> BytesSent = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.bytes.sent", | ||
| unit: "By", | ||
| description: "Number of bytes sent to peers"); | ||
|
|
||
| internal static readonly Counter<long> BytesReceived = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.bytes.received", | ||
| unit: "By", | ||
| description: "Number of bytes received from peers"); | ||
|
|
||
| internal static readonly Counter<long> MessageSendFailures = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.messages.send_failures", | ||
| unit: "{message}", | ||
| description: "Number of transport message send failures"); | ||
|
|
||
| // Per-connection state | ||
| internal static readonly Counter<long> PeerConnections = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.peer_connections", | ||
| unit: "{connection}", | ||
| description: "Number of outbound peer socket connections established"); | ||
|
|
||
| internal static readonly Counter<long> PeerDisconnections = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.peer_disconnections", | ||
| unit: "{disconnection}", | ||
| description: "Number of outbound peer socket disconnections"); | ||
|
|
||
| internal static readonly Counter<long> PeerConnectionFailures = ZebusMetrics.Meter.CreateCounter<long>( | ||
| "zebus.transport.peer_connection_failures", | ||
| unit: "{failure}", | ||
| description: "Number of outbound peer socket connection failures"); | ||
|
|
||
| // Aggregate outbound socket count | ||
| internal static readonly UpDownCounter<int> OutboundSocketCount = ZebusMetrics.Meter.CreateUpDownCounter<int>( | ||
| "zebus.transport.outbound_sockets", | ||
| unit: "{socket}", | ||
| description: "Current number of active outbound sockets"); | ||
| #endif | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #if NET10_0_OR_GREATER | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Metrics; | ||
| #endif | ||
|
|
||
| namespace Abc.Zebus.Monitoring; | ||
|
|
||
| /// <summary> | ||
| /// Shared <see cref="System.Diagnostics.Metrics.Meter"/> and tag helpers for Zebus metrics. | ||
| /// Service-specific instruments are defined in <see cref="TransportMetrics"/> and <see cref="DirectoryMetrics"/>. | ||
| /// </summary> | ||
| internal static class ZebusMetrics | ||
| { | ||
| #if NET10_0_OR_GREATER | ||
| internal static readonly Meter Meter = new("Abc.Zebus", typeof(ZebusMetrics).Assembly.GetName().Version?.ToString()); | ||
|
|
||
| private const string PeerIdTag = "zebus.peer.id"; | ||
|
|
||
| internal static KeyValuePair<string, object?> PeerTag(PeerId peerId) | ||
| => new(PeerIdTag, peerId.ToString()); | ||
| #endif | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,7 +114,8 @@ internal static BindingKey Create(Type messageType, IDictionary<string, string> | |
| var parts = new string[routingMembers.Length]; | ||
| for (var tokenIndex = 0; tokenIndex < routingMembers.Length; ++tokenIndex) | ||
| { | ||
| parts[tokenIndex] = fieldValues.GetValueOrDefault(routingMembers[tokenIndex].Member.Name, BindingKeyPart.StarToken); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copilot probably did that due to .NET double targeting. |
||
| var memberName = routingMembers[tokenIndex].Member.Name; | ||
| parts[tokenIndex] = fieldValues.TryGetValue(memberName, out var value) ? value : BindingKeyPart.StarToken; | ||
| } | ||
|
|
||
| return new BindingKey(parts); | ||
|
|
||
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.
Why this change ?
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.
RNGCryptoServiceProvideris obsolete on .NET Core (SYSLIB0023).RandomNumberGenerator.Fillis the recommended replacement and is available on all NETCOREAPP targets.