@@ -30,6 +30,7 @@ package elasticsearch
30
30
import (
31
31
"context"
32
32
"encoding/json"
33
+ "errors"
33
34
"fmt"
34
35
"strings"
35
36
"sync/atomic"
@@ -93,10 +94,7 @@ type (
93
94
var _ Processor = (* processorImpl )(nil )
94
95
95
96
const (
96
- // retry configs for es bulk processor
97
- esProcessorInitialRetryInterval = 200 * time .Millisecond
98
- esProcessorMaxRetryInterval = 20 * time .Second
99
- visibilityProcessorName = "visibility-processor"
97
+ visibilityProcessorName = "visibility-processor"
100
98
)
101
99
102
100
// NewProcessor create new processorImpl
@@ -119,7 +117,6 @@ func NewProcessor(
119
117
BulkActions : cfg .ESProcessorBulkActions (),
120
118
BulkSize : cfg .ESProcessorBulkSize (),
121
119
FlushInterval : cfg .ESProcessorFlushInterval (),
122
- Backoff : elastic .NewExponentialBackoff (esProcessorInitialRetryInterval , esProcessorMaxRetryInterval ),
123
120
},
124
121
}
125
122
p .bulkProcessorParameters .AfterFunc = p .bulkAfterAction
@@ -220,25 +217,26 @@ func (p *processorImpl) bulkBeforeAction(_ int64, requests []elastic.BulkableReq
220
217
func (p * processorImpl ) bulkAfterAction (_ int64 , requests []elastic.BulkableRequest , response * elastic.BulkResponse , err error ) {
221
218
if err != nil {
222
219
const logFirstNRequests = 5
223
- httpStatus := client .HttpStatus (err )
224
- isRetryable := client .IsRetryableStatus (httpStatus )
220
+ var httpStatus int
221
+ var esErr * elastic.Error
222
+ if errors .As (err , & esErr ) {
223
+ httpStatus = esErr .Status
224
+ }
225
+
225
226
var logRequests strings.Builder
226
227
for i , request := range requests {
227
228
if i < logFirstNRequests {
228
229
logRequests .WriteString (request .String ())
229
230
logRequests .WriteRune ('\n' )
230
231
}
231
232
p .metricsHandler .Counter (metrics .ElasticsearchBulkProcessorFailures .GetMetricName ()).Record (1 , metrics .HttpStatusTag (httpStatus ))
232
-
233
- if ! isRetryable {
234
- visibilityTaskKey := p .extractVisibilityTaskKey (request )
235
- if visibilityTaskKey == "" {
236
- continue
237
- }
238
- p .notifyResult (visibilityTaskKey , false )
233
+ visibilityTaskKey := p .extractVisibilityTaskKey (request )
234
+ if visibilityTaskKey == "" {
235
+ continue
239
236
}
237
+ p .notifyResult (visibilityTaskKey , false )
240
238
}
241
- p .logger .Error ("Unable to commit bulk ES request." , tag .Error (err ), tag .IsRetryable ( isRetryable ), tag . RequestCount (len (requests )), tag .ESRequest (logRequests .String ()))
239
+ p .logger .Error ("Unable to commit bulk ES request." , tag .Error (err ), tag .RequestCount (len (requests )), tag .ESRequest (logRequests .String ()))
242
240
return
243
241
}
244
242
@@ -262,10 +260,7 @@ func (p *processorImpl) bulkAfterAction(_ int64, requests []elastic.BulkableRequ
262
260
continue
263
261
}
264
262
265
- switch {
266
- case isSuccess (responseItem ):
267
- p .notifyResult (visibilityTaskKey , true )
268
- case ! client .IsRetryableStatus (responseItem .Status ):
263
+ if ! isSuccess (responseItem ) {
269
264
p .logger .Error ("ES request failed." ,
270
265
tag .ESResponseStatus (responseItem .Status ),
271
266
tag .ESResponseError (extractErrorReason (responseItem )),
@@ -274,15 +269,10 @@ func (p *processorImpl) bulkAfterAction(_ int64, requests []elastic.BulkableRequ
274
269
tag .ESRequest (request .String ()))
275
270
p .metricsHandler .Counter (metrics .ElasticsearchBulkProcessorFailures .GetMetricName ()).Record (1 , metrics .HttpStatusTag (responseItem .Status ))
276
271
p .notifyResult (visibilityTaskKey , false )
277
- default : // bulk processor will retry
278
- p .logger .Warn ("ES request retried." ,
279
- tag .ESResponseStatus (responseItem .Status ),
280
- tag .ESResponseError (extractErrorReason (responseItem )),
281
- tag .Key (visibilityTaskKey ),
282
- tag .ESDocID (docID ),
283
- tag .ESRequest (request .String ()))
284
- p .metricsHandler .Counter (metrics .ElasticsearchBulkProcessorRetries .GetMetricName ()).Record (1 , metrics .HttpStatusTag (responseItem .Status ))
272
+ continue
285
273
}
274
+
275
+ p .notifyResult (visibilityTaskKey , true )
286
276
}
287
277
288
278
// Record how many documents are waiting to be flushed to Elasticsearch after this bulk is committed.
0 commit comments