From 0a01453d03a81c89aec72c34bf8e2eddfbfb01f7 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 23 Dec 2024 11:22:11 -0600 Subject: [PATCH] Make actor start / stop telemetry descriptors overrideable (#7434) Designed to support https://github.com/petabridge/phobos-issues/issues/82 --- ...CoreAPISpec.ApproveCore.DotNet.verified.txt | 2 ++ .../CoreAPISpec.ApproveCore.Net.verified.txt | 2 ++ .../Akka/Actor/ActorCell.DefaultMessages.cs | 18 +++++++++++++++++- src/core/Akka/Actor/ActorCell.FaultHandling.cs | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt index 5c67a933868..797ac2a1bb0 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt @@ -94,6 +94,8 @@ namespace Akka.Actor public void CheckReceiveTimeout(bool reschedule = True) { } protected void ClearActor(Akka.Actor.ActorBase actor) { } protected void ClearActorCell() { } + protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { } + protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { } protected virtual Akka.Actor.ActorBase CreateNewActorInstance() { } [System.ObsoleteAttribute("Use TryGetChildStatsByName [0.7.1]", true)] public Akka.Actor.IInternalActorRef GetChildByName(string name) { } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt index 58d759a4813..a77ae1f67f0 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt @@ -94,6 +94,8 @@ namespace Akka.Actor public void CheckReceiveTimeout(bool reschedule = True) { } protected void ClearActor(Akka.Actor.ActorBase actor) { } protected void ClearActorCell() { } + protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { } + protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { } protected virtual Akka.Actor.ActorBase CreateNewActorInstance() { } [System.ObsoleteAttribute("Use TryGetChildStatsByName [0.7.1]", true)] public Akka.Actor.IInternalActorRef GetChildByName(string name) { } diff --git a/src/core/Akka/Actor/ActorCell.DefaultMessages.cs b/src/core/Akka/Actor/ActorCell.DefaultMessages.cs index 22cdd011687..c20d36da61f 100644 --- a/src/core/Akka/Actor/ActorCell.DefaultMessages.cs +++ b/src/core/Akka/Actor/ActorCell.DefaultMessages.cs @@ -429,6 +429,22 @@ public void Restart(Exception cause) SendSystemMessage(new Recreate(cause)); } + /// + /// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82 + /// + protected virtual ActorStarted CreateActorStartedEvent() + { + return new ActorStarted(Self, Props.Type); + } + + /// + /// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82 + /// + protected virtual ActorStopped CreateActorStoppedEvent() + { + return new ActorStopped(Self, Props.Type); + } + private void Create(Exception failure) { if (failure != null) @@ -442,7 +458,7 @@ private void Create(Exception failure) if (System.Settings.DebugLifecycle) Publish(new Debug(Self.Path.ToString(), created.GetType(), "Started (" + created + ")")); if(System.Settings.EmitActorTelemetry) - System.EventStream.Publish(new ActorStarted(Self, Props.Type)); + System.EventStream.Publish(CreateActorStartedEvent()); } catch (Exception e) { diff --git a/src/core/Akka/Actor/ActorCell.FaultHandling.cs b/src/core/Akka/Actor/ActorCell.FaultHandling.cs index bfba2f84f5b..f8e98412524 100644 --- a/src/core/Akka/Actor/ActorCell.FaultHandling.cs +++ b/src/core/Akka/Actor/ActorCell.FaultHandling.cs @@ -290,7 +290,7 @@ private void FinishTerminate() } if(System.Settings.EmitActorTelemetry) - System.EventStream.Publish(new ActorStopped(Self, Props.Type)); + System.EventStream.Publish(CreateActorStoppedEvent()); } catch (Exception x) {