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

fix: fix deadletter count metric bug #634

Merged
merged 1 commit into from
Feb 23, 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
41 changes: 41 additions & 0 deletions actor/dead_letter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,47 @@ func TestDeadletter(t *testing.T) {
err = sys.Stop(ctx)
assert.NoError(t, err)
})
t.Run("With GetDeadlettersCount for a specific actor", func(t *testing.T) {
ctx := context.TODO()
sys, _ := NewActorSystem("testSys", WithLogger(log.DiscardLogger))

// start the actor system
err := sys.Start(ctx)
assert.NoError(t, err)

// wait for complete start
util.Pause(time.Second)

// create the black hole actor
actor := &mockUnhandledMessageActor{}
actorName := "actorName"
actorRef, err := sys.Spawn(ctx, actorName, actor)
assert.NoError(t, err)
assert.NotNil(t, actorRef)

// wait a while
util.Pause(time.Second)

// every message sent to the actor will result in deadletter
for i := 0; i < 5; i++ {
require.NoError(t, Tell(ctx, actorRef, new(testpb.TestSend)))
}

util.Pause(time.Second)

actorID := actorRef.ID()
reply, err := Ask(ctx, sys.getDeadletter(), &internalpb.GetDeadlettersCount{
ActorId: &actorID,
}, 500*time.Millisecond)
require.NoError(t, err)
require.NotNil(t, reply)
response, ok := reply.(*internalpb.DeadlettersCount)
require.True(t, ok)
require.EqualValues(t, 5, response.GetTotalCount())

err = sys.Stop(ctx)
assert.NoError(t, err)
})
t.Run("With GetDeadletters", func(t *testing.T) {
ctx := context.TODO()
sys, _ := NewActorSystem("testSys", WithLogger(log.DiscardLogger))
Expand Down
2 changes: 1 addition & 1 deletion actor/pid.go
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ func (pid *PID) suspend(reason string) {
// getDeadlettersCount gets deadletter
func (pid *PID) getDeadlettersCount(ctx context.Context) int64 {
var (
name = pid.Name()
name = pid.ID()
to = pid.ActorSystem().getDeadletter()
from = pid.ActorSystem().getSystemGuardian()
message = &internalpb.GetDeadlettersCount{
Expand Down
36 changes: 36 additions & 0 deletions actor/pid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3709,3 +3709,39 @@ func TestLogger(t *testing.T) {
buffer.Reset()
})
}
func TestDeadletterCountMetric(t *testing.T) {
ctx := context.TODO()
sys, _ := NewActorSystem("testSys", WithLogger(log.DiscardLogger))

// start the actor system
err := sys.Start(ctx)
assert.NoError(t, err)

// wait for complete start
util.Pause(time.Second)

// create the black hole actor
actor := &mockUnhandledMessageActor{}
actorName := "actorName"
actorRef, err := sys.Spawn(ctx, actorName, actor)
assert.NoError(t, err)
assert.NotNil(t, actorRef)

// wait a while
util.Pause(time.Second)

// every message sent to the actor will result in deadletter
for i := 0; i < 5; i++ {
require.NoError(t, Tell(ctx, actorRef, new(testpb.TestSend)))
}

util.Pause(time.Second)

metric := actorRef.Metric(ctx)
require.NotNil(t, metric)

require.EqualValues(t, 5, metric.DeadlettersCount())

err = sys.Stop(ctx)
assert.NoError(t, err)
}
Loading