Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/Proto.Actor/ActorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ActorSystem(ActorSystemConfig config)
new Lazy<FutureFactory>(() => new FutureFactory(this, config.SharedFutures, config.SharedFutureSize));

Diagnostics.RegisterObject("ActorSystem", "Config", config);

Diagnostics.RegisterObject("ActorSystem", "Id", Id);
RunThreadPoolStats();
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public Task ShutdownAsync(string reason = "")
{
_logger.LogInformation("Shutting down actor system {Id} - Reason {Reason}", Id, reason);
Stopper.Stop(reason);
Diagnostics.RegisterEvent("ActorSystem", $"Stopped: {reason}");
Diagnostics.RegisterObject("ActorSystem", "Stopped", reason);
}
catch
{
Expand Down
26 changes: 26 additions & 0 deletions src/Proto.Actor/Diagnostics/DiagnosticsEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace Proto.Diagnostics;

[PublicAPI]
public record DiagnosticsEntry
{
// ReSharper disable once ConvertToPrimaryConstructor
public DiagnosticsEntry(string module, string? message, object? data)
{
Module = module;
Message = message;
Data = data;
}

public string Module { get; }


[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Message { get; }


[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Data { get; }
}
24 changes: 1 addition & 23 deletions src/Proto.Actor/Diagnostics/DiagnosticsStore.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -81,25 +80,4 @@ public async Task<DiagnosticsEntry[]> GetDiagnostics()

return entries.ToArray();
}
}

public record DiagnosticsEntry
{
// ReSharper disable once ConvertToPrimaryConstructor
public DiagnosticsEntry(string module, string? message, object? data)
{
Module = module;
Message = message;
Data = data;
}

public string Module { get; }


[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? Message { get; }


[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Data { get; }
}
}
2 changes: 1 addition & 1 deletion src/Proto.Actor/Diagnostics/IActorDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Proto.Diagnostics;

/// <summary>
/// Adds the ability to return a diagnostic string for an actor
/// Adds the ability to return a diagnostic string for an actor instance
/// </summary>
public interface IActorDiagnostics
{
Expand Down
11 changes: 11 additions & 0 deletions src/Proto.Actor/Diagnostics/IDiagnosticsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Proto.Diagnostics;

[PublicAPI]
public interface IDiagnosticsProvider
{
Task<DiagnosticsEntry[]> GetDiagnostics() => Task.FromResult(Array.Empty<DiagnosticsEntry>());
}
4 changes: 4 additions & 0 deletions src/Proto.Actor/Diagnostics/IDiagnosticsTypeName.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace Proto.Diagnostics;

/// <summary>
/// This interface allows specific message types to override what typename is returned for tracing and metrics.
/// e.g. MessageEnvelope can return the name of the inner message type instead of its own type name
/// </summary>
public interface IDiagnosticsTypeName
{
string GetTypeName();
Expand Down
3 changes: 1 addition & 2 deletions src/Proto.Actor/Extensions/IActorSystemExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ namespace Proto.Extensions;
/// <summary>
/// Marks a class as an actor system extension
/// </summary>
public interface IActorSystemExtension
public interface IActorSystemExtension : IDiagnosticsProvider
{
private static int _nextId;

internal static int GetNextId() => Interlocked.Increment(ref _nextId);
Task<DiagnosticsEntry[]> GetDiagnostics() => Task.FromResult(Array.Empty<DiagnosticsEntry>());
}

/// <summary>
Expand Down
19 changes: 16 additions & 3 deletions src/Proto.Cluster/Cluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,32 @@ public class Cluster : IActorSystemExtension<Cluster>

public async Task<DiagnosticsEntry[]> GetDiagnostics()
{
var now = new DiagnosticsEntry("Cluster", $"Local Time", DateTimeOffset.UtcNow);
var blocked = new DiagnosticsEntry("Cluster", "Blocked", System.Remote().BlockList.BlockedMembers.ToArray());
var res = new List<DiagnosticsEntry>();

var now = new DiagnosticsEntry("Cluster", "Local Time", DateTimeOffset.UtcNow);
res.Add(now);

var blocked = new DiagnosticsEntry("Cluster", "Blocked", System.Remote().BlockList.BlockedMembers.ToArray());
res.Add(blocked);

var t = await Gossip.GetState<ClusterTopology>(GossipKeys.Topology);

var topology = new DiagnosticsEntry("Cluster", "Topology", t);
res.Add(topology);

var h = await Gossip.GetStateEntry(GossipKeys.Heartbeat);
var heartbeats = h.Select(heartbeat => new DiagnosticsMemberHeartbeat(heartbeat.Key, heartbeat.Value.Value.Unpack<MemberHeartbeat>(), heartbeat.Value.LocalTimestamp)).ToArray();

var heartbeat = new DiagnosticsEntry("Cluster", "Heartbeat", heartbeats);
res.Add(heartbeat);

var idlookup = await IdentityLookup.GetDiagnostics();
res.AddRange(idlookup);

var provider = await Provider.GetDiagnostics();
res.AddRange(provider);

return new[] { now, blocked, topology, heartbeat };
return res.ToArray();
}

public Cluster(ActorSystem system, ClusterConfig config)
Expand Down
3 changes: 2 additions & 1 deletion src/Proto.Cluster/IClusterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System.Threading.Tasks;
using JetBrains.Annotations;
using Proto.Diagnostics;

namespace Proto.Cluster;

Expand All @@ -14,7 +15,7 @@ namespace Proto.Cluster;
/// The cluster provider updates the <see cref="MemberList" />
/// </summary>
[PublicAPI]
public interface IClusterProvider
public interface IClusterProvider : IDiagnosticsProvider
{
/// <summary>
/// Starts the cluster provider
Expand Down
3 changes: 2 additions & 1 deletion src/Proto.Cluster/Identity/IIdentityLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

using System.Threading;
using System.Threading.Tasks;
using Proto.Diagnostics;

namespace Proto.Cluster.Identity;

/// <summary>
/// Identity lookup is used to activate and locate virtual actor activations in the cluster.
/// See <a href="https://proto.actor/docs/cluster/identity-lookup-net/">Identity Lookup docs</a> for more details.
/// </summary>
public interface IIdentityLookup
public interface IIdentityLookup : IDiagnosticsProvider
{
/// <summary>
/// Activates or locates a virtual actor in the cluster.
Expand Down
6 changes: 3 additions & 3 deletions src/Proto.Remote/Endpoints/EndpointManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Proto.Remote;

public sealed class EndpointManager
public sealed class EndpointManager : IDiagnosticsProvider
{
public const string ActivatorActorName = "$activator";

Expand Down Expand Up @@ -272,10 +272,10 @@ private void StopActivator()
}
}

public async Task<DiagnosticsEntry[]> GetDiagnostics()
public Task<DiagnosticsEntry[]> GetDiagnostics()
{
var endpoints = new DiagnosticsEntry("Remote", "Endpoints", _serverEndpoints.Keys.ToArray());

return new[] { endpoints };
return Task.FromResult(new[] { endpoints });
}
}