From d3a95d13616a4e6bd230af106d7abfb2f68a0aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=83=E4=B9=99?= Date: Tue, 24 Sep 2019 21:58:43 +0800 Subject: [PATCH] [add] more log for send fail [fix] crash if call empty GetReservedAttempts --- producer/io_worker.go | 8 +++++--- producer/result.go | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/producer/io_worker.go b/producer/io_worker.go index 8b737bc0..4de2613c 100644 --- a/producer/io_worker.go +++ b/producer/io_worker.go @@ -1,13 +1,14 @@ package producer import ( - "github.com/aliyun/aliyun-log-go-sdk" - "github.com/go-kit/kit/log" - "github.com/go-kit/kit/log/level" "math" "sync" "sync/atomic" "time" + + sls "github.com/aliyun/aliyun-log-go-sdk" + "github.com/go-kit/kit/log" + "github.com/go-kit/kit/log/level" ) type CallBack interface { @@ -70,6 +71,7 @@ func (ioWorker *IoWorker) sendToServer(producerBatch *ProducerBatch, ioWorkerWai } return } + level.Info(ioWorker.logger).Log("msg", "sendToServer failed", "error", err) if slsError, ok := err.(*sls.Error); ok { if _, ok := ioWorker.noRetryStatusCodeMap[int(slsError.HTTPCode)]; ok { ioWorker.excuteFailedCallback(producerBatch) diff --git a/producer/result.go b/producer/result.go index d1c23b91..89c92e95 100644 --- a/producer/result.go +++ b/producer/result.go @@ -40,16 +40,25 @@ func (result *Result) GetErrorCode() string { } func (result *Result) GetErrorMessage() string { + if len(result.attemptList) == 0 { + return "" + } cursor := len(result.attemptList) - 1 return result.attemptList[cursor].ErrorMessage } func (result *Result) GetRequestId() string { + if len(result.attemptList) == 0 { + return "" + } cursor := len(result.attemptList) - 1 return result.attemptList[cursor].RequestId } func (result *Result) GetTimeStampMs() int64 { + if len(result.attemptList) == 0 { + return 0 + } cursor := len(result.attemptList) - 1 return result.attemptList[cursor].TimeStampMs }