Skip to content
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

made IActorTelemetry events nullable #7478

Merged
merged 1 commit into from
Jan 22, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace Akka.Actor
public void CheckReceiveTimeout(bool reschedule = True) { }
protected void ClearActor(Akka.Actor.ActorBase actor) { }
protected void ClearActorCell() { }
[return: System.Runtime.CompilerServices.NullableAttribute(2)]
protected virtual Akka.Actor.ActorRestarted CreateActorRestartedEvent(System.Exception cause) { }
protected virtual Akka.Actor.ActorStarted CreateActorStartedEvent() { }
protected virtual Akka.Actor.ActorStopped CreateActorStoppedEvent() { }
Expand Down
6 changes: 2 additions & 4 deletions src/core/Akka/Actor/ActorCell.Children.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ private string GetRandomActorName(string prefix = "$")
/// <param name="child">The child.</param>
public void Stop(IActorRef child)
{
ChildRestartStats stats;
if (ChildrenContainer.TryGetByRef(child, out stats))
if (ChildrenContainer.TryGetByRef(child, out _))
{
var repointableActorRef = child as RepointableActorRef;
if (repointableActorRef == null || repointableActorRef.IsStarted)
if (child is not RepointableActorRef repointableActorRef || repointableActorRef.IsStarted)
{
while (true)
{
Expand Down
13 changes: 9 additions & 4 deletions src/core/Akka/Actor/ActorCell.DefaultMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ public void Restart(Exception cause)
/// <summary>
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
/// </summary>
protected virtual ActorStarted CreateActorStartedEvent()
protected virtual ActorStarted? CreateActorStartedEvent()
{
return new ActorStarted(Self, Props.Type);
}

/// <summary>
/// Overrideable in order to support issues such as https://github.com/petabridge/phobos-issues/issues/82
/// </summary>
protected virtual ActorStopped CreateActorStoppedEvent()
protected virtual ActorStopped? CreateActorStoppedEvent()
{
return new ActorStopped(Self, Props.Type);
}
Expand All @@ -466,8 +466,13 @@ private void Create(Exception? failure)
CheckReceiveTimeout();
if (System.Settings.DebugLifecycle)
Publish(new Debug(Self.Path.ToString(), created.GetType(), "Started (" + created + ")"));
if(System.Settings.EmitActorTelemetry)
System.EventStream.Publish(CreateActorStartedEvent());
if (System.Settings.EmitActorTelemetry)
{
var actorStarted = CreateActorStartedEvent();
if(actorStarted != null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't emit ActorStarted events if they're null

System.EventStream.Publish(actorStarted);
}

}
catch (Exception e)
{
Expand Down
20 changes: 14 additions & 6 deletions src/core/Akka/Actor/ActorCell.FaultHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,13 @@ private void FinishTerminate()
var pipeline = SystemImpl.ActorPipelineResolver.ResolvePipeline(a.GetType());
pipeline.BeforeActorIncarnated(a, this);
}

if(System.Settings.EmitActorTelemetry)
System.EventStream.Publish(CreateActorStoppedEvent());

if (System.Settings.EmitActorTelemetry)
{
var stopEvent = CreateActorStoppedEvent();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't emit ActorStopped events if they're null

if (stopEvent is not null)
System.EventStream.Publish(stopEvent);
}
}
catch (Exception x)
{
Expand Down Expand Up @@ -350,8 +354,12 @@ 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(CreateActorRestartedEvent(cause));
if (System.Settings.EmitActorTelemetry)
{
var restartEvent = CreateActorRestartedEvent(cause);
if (restartEvent is not null)
System.EventStream.Publish(restartEvent);
}

// only after parent is up and running again do restart the children which were not stopped
foreach (var survivingChild in survivors)
Expand All @@ -378,7 +386,7 @@ 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)
protected virtual ActorRestarted? CreateActorRestartedEvent(Exception cause)
{
return new ActorRestarted(Self, Props.Type, cause);
}
Expand Down
Loading