Skip to content

Commit

Permalink
Improve actor telemetry types (#7439)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkatufus authored Dec 30, 2024
1 parent 400e7cb commit 90e60c6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
protected virtual Akka.Actor.ActorBase CreateNewActorInstance() { }
Expand Down Expand Up @@ -320,9 +321,12 @@ namespace Akka.Actor
public static readonly Akka.Actor.IActorRef NoSender;
public static readonly Akka.Actor.Nobody Nobody;
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorRestarted : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorRestarted(Akka.Actor.IActorRef subject, System.Type actorType, System.Exception reason, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public System.Exception Reason { get; }
public Akka.Actor.IActorRef Subject { get; }
}
Expand Down Expand Up @@ -352,9 +356,12 @@ namespace Akka.Actor
public Akka.Actor.ActorSelectionMessage Copy(object message = null, Akka.Actor.SelectionPathElement[] elements = null, System.Nullable<bool> wildCardFanOut = null) { }
public override string ToString() { }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorStarted : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorStarted(Akka.Actor.IActorRef subject, System.Type actorType, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public Akka.Actor.IActorRef Subject { get; }
}
public class ActorStashPlugin : Akka.Actor.ActorProducerPluginBase
Expand All @@ -364,9 +371,12 @@ namespace Akka.Actor
public override void BeforeIncarnated(Akka.Actor.ActorBase actor, Akka.Actor.IActorContext context) { }
public override bool CanBeAppliedTo(System.Type actorType) { }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorStopped : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorStopped(Akka.Actor.IActorRef subject, System.Type actorType, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public Akka.Actor.IActorRef Subject { get; }
}
public abstract class ActorSystem : Akka.Actor.IActorRefFactory, System.IDisposable
Expand Down Expand Up @@ -1025,6 +1035,7 @@ namespace Akka.Actor
public interface IActorTelemetryEvent : Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
System.Type ActorType { get; }
string ActorTypeOverride { get; }
Akka.Actor.IActorRef Subject { get; }
}
public interface IAdvancedScheduler : Akka.Actor.IActionScheduler, Akka.Actor.IRunnableScheduler { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
protected virtual Akka.Actor.ActorBase CreateNewActorInstance() { }
Expand Down Expand Up @@ -320,9 +321,12 @@ namespace Akka.Actor
public static readonly Akka.Actor.IActorRef NoSender;
public static readonly Akka.Actor.Nobody Nobody;
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorRestarted : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorRestarted(Akka.Actor.IActorRef subject, System.Type actorType, System.Exception reason, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public System.Exception Reason { get; }
public Akka.Actor.IActorRef Subject { get; }
}
Expand Down Expand Up @@ -352,9 +356,12 @@ namespace Akka.Actor
public Akka.Actor.ActorSelectionMessage Copy(object message = null, Akka.Actor.SelectionPathElement[] elements = null, System.Nullable<bool> wildCardFanOut = null) { }
public override string ToString() { }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorStarted : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorStarted(Akka.Actor.IActorRef subject, System.Type actorType, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public Akka.Actor.IActorRef Subject { get; }
}
public class ActorStashPlugin : Akka.Actor.ActorProducerPluginBase
Expand All @@ -364,9 +371,12 @@ namespace Akka.Actor
public override void BeforeIncarnated(Akka.Actor.ActorBase actor, Akka.Actor.IActorContext context) { }
public override bool CanBeAppliedTo(System.Type actorType) { }
}
[System.Runtime.CompilerServices.NullableAttribute(0)]
public sealed class ActorStopped : Akka.Actor.IActorTelemetryEvent, Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
public ActorStopped(Akka.Actor.IActorRef subject, System.Type actorType, [System.Runtime.CompilerServices.NullableAttribute(2)] string actorTypeOverride = null) { }
public System.Type ActorType { get; }
public string ActorTypeOverride { get; }
public Akka.Actor.IActorRef Subject { get; }
}
public abstract class ActorSystem : Akka.Actor.IActorRefFactory, System.IDisposable
Expand Down Expand Up @@ -1023,6 +1033,7 @@ namespace Akka.Actor
public interface IActorTelemetryEvent : Akka.Actor.INoSerializationVerificationNeeded, Akka.Actor.INotInfluenceReceiveTimeout
{
System.Type ActorType { get; }
string ActorTypeOverride { get; }
Akka.Actor.IActorRef Subject { get; }
}
public interface IAdvancedScheduler : Akka.Actor.IActionScheduler, Akka.Actor.IRunnableScheduler { }
Expand Down
9 changes: 8 additions & 1 deletion src/core/Akka/Actor/ActorCell.FaultHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void FinishRecreate(Exception cause, ActorBase failedActor)
if (System.Settings.DebugLifecycle)
Publish(new Debug(_self.Path.ToString(), freshActor.GetType(), "Restarted (" + freshActor + ")"));
if(System.Settings.EmitActorTelemetry)
System.EventStream.Publish(new ActorRestarted(Self, Props.Type, cause));
System.EventStream.Publish(CreateActorRestartedEvent(cause));

// only after parent is up and running again do restart the children which were not stopped
foreach (var survivingChild in survivors)
Expand All @@ -373,6 +373,13 @@ private void FinishRecreate(Exception cause, ActorBase failedActor)

}

/// <summary>
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
/// </summary>
protected virtual ActorRestarted CreateActorRestartedEvent(Exception cause)
{
return new ActorRestarted(Self, Props.Type, cause);
}

private void HandleFailed(Failed f) //Called handleFailure in Akka JVM
{
Expand Down
24 changes: 21 additions & 3 deletions src/core/Akka/Actor/ActorTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using Akka.Event;

#nullable enable
namespace Akka.Actor
{
/// <summary>
Expand All @@ -30,50 +31,67 @@ public interface IActorTelemetryEvent : INoSerializationVerificationNeeded, INot
/// The implementation type for this actor.
/// </summary>
Type ActorType { get; }

/// <summary>
/// A type name override for the actor
/// </summary>
public string ActorTypeOverride { get; }
}

// Create ActorTelemetryEvent messages for the following events: starting an actor, stopping an actor, restarting an actor
public sealed class ActorStarted : IActorTelemetryEvent
{
internal ActorStarted(IActorRef subject, Type actorType)
public ActorStarted(IActorRef subject, Type actorType, string? actorTypeOverride = null)
{
Subject = subject;
ActorType = actorType;

if(actorTypeOverride is not null)
ActorTypeOverride = actorTypeOverride;
}

public IActorRef Subject { get; }
public Type ActorType { get; }
public string ActorTypeOverride { get; } = string.Empty;
}

/// <summary>
/// Event emitted when actor shuts down.
/// </summary>
public sealed class ActorStopped : IActorTelemetryEvent
{
internal ActorStopped(IActorRef subject, Type actorType)
public ActorStopped(IActorRef subject, Type actorType, string? actorTypeOverride = null)
{
Subject = subject;
ActorType = actorType;

if(actorTypeOverride is not null)
ActorTypeOverride = actorTypeOverride;
}

public IActorRef Subject { get; }
public Type ActorType { get; }
public string ActorTypeOverride { get; } = string.Empty;
}

/// <summary>
/// Emitted when an actor restarts.
/// </summary>
public sealed class ActorRestarted : IActorTelemetryEvent
{
internal ActorRestarted(IActorRef subject, Type actorType, Exception reason)
public ActorRestarted(IActorRef subject, Type actorType, Exception reason, string? actorTypeOverride = null)
{
Subject = subject;
ActorType = actorType;
Reason = reason;

if(actorTypeOverride is not null)
ActorTypeOverride = actorTypeOverride;
}

public IActorRef Subject { get; }
public Type ActorType { get; }
public string ActorTypeOverride { get; } = string.Empty;

public Exception Reason { get; }
}
Expand Down

0 comments on commit 90e60c6

Please sign in to comment.