Skip to content

Commit

Permalink
Update logging of empty 200 response for pub/sub messages to indicate…
Browse files Browse the repository at this point in the history
… success (dapr#7620)

Signed-off-by: Kun Chang <curtis@mail.ustc.edu.cn>
  • Loading branch information
ckcd authored Mar 13, 2024
1 parent 6c87b4b commit ed56f69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/runtime/processor/pubsub/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -139,7 +140,11 @@ func (p *pubsub) publishMessageHTTP(ctx context.Context, msg *subscribedMessage)
var appResponse contribpubsub.AppResponse
err := json.NewDecoder(resp.RawData()).Decode(&appResponse)
if err != nil {
log.Debugf("skipping status check due to error parsing result from pub/sub event %v: %s", cloudEvent[contribpubsub.IDField], err)
if errors.Is(err, io.EOF) {
log.Debugf("skipping status check due to empty response body from pub/sub event %v", cloudEvent[contribpubsub.IDField])
} else {
log.Debugf("skipping status check due to error parsing result from pub/sub event %v: %s", cloudEvent[contribpubsub.IDField], err)
}
diag.DefaultComponentMonitoring.PubsubIngressEvent(ctx, msg.pubsub, strings.ToLower(string(contribpubsub.Success)), msg.topic, elapsed)
return nil
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/runtime/processor/pubsub/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ func TestErrorPublishedNonCloudEventHTTP(t *testing.T) {
require.NoError(t, err)
})

t.Run("ok with empty body", func(t *testing.T) {
log.SetOutputLevel(logger.DebugLevel)
defer log.SetOutputLevel(logger.InfoLevel)

mockAppChannel := new(channelt.MockAppChannel)
ps.channels = new(channels.Channels).WithAppChannel(mockAppChannel)

fakeResp := invokev1.NewInvokeMethodResponse(200, "OK", nil).WithRawData(nil)
defer fakeResp.Close()

mockAppChannel.On("InvokeMethod", mock.Anything, fakeReq).Return(fakeResp, nil)

// act
err := ps.publishMessageHTTP(context.Background(), testPubSubMessage)

// assert
require.NoError(t, err)
})

t.Run("ok with retry", func(t *testing.T) {
mockAppChannel := new(channelt.MockAppChannel)
ps.channels = new(channels.Channels).WithAppChannel(mockAppChannel)
Expand Down

0 comments on commit ed56f69

Please sign in to comment.