@@ -100,7 +100,7 @@ type dynamoDBStorageClient struct {
100
100
batchGetItemRequestFn func (ctx context.Context , input * dynamodb.BatchGetItemInput ) dynamoDBRequest
101
101
batchWriteItemRequestFn func (ctx context.Context , input * dynamodb.BatchWriteItemInput ) dynamoDBRequest
102
102
103
- metrics * metrics
103
+ metrics * dynamoDBMetrics
104
104
}
105
105
106
106
// NewDynamoDBIndexClient makes a new DynamoDB-backed IndexClient.
@@ -141,9 +141,9 @@ func (a dynamoDBStorageClient) NewWriteBatch() chunk.WriteBatch {
141
141
return dynamoDBWriteBatch (map [string ][]* dynamodb.WriteRequest {})
142
142
}
143
143
144
- func logWriteRetry (unprocessed dynamoDBWriteBatch , dynamoThrottled * prometheus. CounterVec ) {
144
+ func logWriteRetry (unprocessed dynamoDBWriteBatch , metrics * dynamoDBMetrics ) {
145
145
for table , reqs := range unprocessed {
146
- dynamoThrottled .WithLabelValues ("DynamoDB.BatchWriteItem" , table ).Add (float64 (len (reqs )))
146
+ metrics . dynamoThrottled .WithLabelValues ("DynamoDB.BatchWriteItem" , table ).Add (float64 (len (reqs )))
147
147
for _ , req := range reqs {
148
148
item := req .PutRequest .Item
149
149
var hash , rnge string
@@ -191,13 +191,13 @@ func (a dynamoDBStorageClient) BatchWrite(ctx context.Context, input chunk.Write
191
191
192
192
if err != nil {
193
193
for tableName := range requests {
194
- recordDynamoError (tableName , err , "DynamoDB.BatchWriteItem" , a .metrics . dynamoFailures )
194
+ recordDynamoError (tableName , err , "DynamoDB.BatchWriteItem" , a .metrics )
195
195
}
196
196
197
197
// If we get provisionedThroughputExceededException, then no items were processed,
198
198
// so back off and retry all.
199
199
if awsErr , ok := err .(awserr.Error ); ok && ((awsErr .Code () == dynamodb .ErrCodeProvisionedThroughputExceededException ) || request .Retryable ()) {
200
- logWriteRetry (requests , a .metrics . dynamoThrottled )
200
+ logWriteRetry (requests , a .metrics )
201
201
unprocessed .TakeReqs (requests , - 1 )
202
202
_ = a .writeThrottle .WaitN (ctx , len (requests ))
203
203
backoff .Wait ()
@@ -222,7 +222,7 @@ func (a dynamoDBStorageClient) BatchWrite(ctx context.Context, input chunk.Write
222
222
// If there are unprocessed items, retry those items.
223
223
unprocessedItems := dynamoDBWriteBatch (resp .UnprocessedItems )
224
224
if len (unprocessedItems ) > 0 {
225
- logWriteRetry (unprocessedItems , a .metrics . dynamoThrottled )
225
+ logWriteRetry (unprocessedItems , a .metrics )
226
226
_ = a .writeThrottle .WaitN (ctx , unprocessedItems .Len ())
227
227
unprocessed .TakeReqs (unprocessedItems , - 1 )
228
228
}
@@ -304,7 +304,7 @@ func (a dynamoDBStorageClient) query(ctx context.Context, query chunk.IndexQuery
304
304
}
305
305
306
306
return callback (query , & dynamoDBReadResponse {items : output .Items })
307
- }, retryer .withRetries , withErrorHandler (query .TableName , "DynamoDB.QueryPages" , a .metrics . dynamoFailures ))
307
+ }, retryer .withRetries , withErrorHandler (query .TableName , "DynamoDB.QueryPages" , a .metrics ))
308
308
})
309
309
if err != nil {
310
310
return errors .Wrapf (err , "QueryPages error: table=%v" , query .TableName )
@@ -447,7 +447,7 @@ func (a dynamoDBStorageClient) getDynamoDBChunks(ctx context.Context, chunks []c
447
447
448
448
if err != nil {
449
449
for tableName := range requests {
450
- recordDynamoError (tableName , err , "DynamoDB.BatchGetItemPages" , a .metrics . dynamoFailures )
450
+ recordDynamoError (tableName , err , "DynamoDB.BatchGetItemPages" , a .metrics )
451
451
}
452
452
453
453
// If we get provisionedThroughputExceededException, then no items were processed,
@@ -746,21 +746,21 @@ func (b dynamoDBReadRequest) TakeReqs(from dynamoDBReadRequest, max int) {
746
746
}
747
747
}
748
748
749
- func withErrorHandler (tableName , operation string , dynamoFailures * prometheus. CounterVec ) func (req * request.Request ) {
749
+ func withErrorHandler (tableName , operation string , metrics * dynamoDBMetrics ) func (req * request.Request ) {
750
750
return func (req * request.Request ) {
751
751
req .Handlers .CompleteAttempt .PushBack (func (req * request.Request ) {
752
752
if req .Error != nil {
753
- recordDynamoError (tableName , req .Error , operation , dynamoFailures )
753
+ recordDynamoError (tableName , req .Error , operation , metrics )
754
754
}
755
755
})
756
756
}
757
757
}
758
758
759
- func recordDynamoError (tableName string , err error , operation string , dynamoFailures * prometheus. CounterVec ) {
759
+ func recordDynamoError (tableName string , err error , operation string , metrics * dynamoDBMetrics ) {
760
760
if awsErr , ok := err .(awserr.Error ); ok {
761
- dynamoFailures .WithLabelValues (tableName , awsErr .Code (), operation ).Add (float64 (1 ))
761
+ metrics . dynamoFailures .WithLabelValues (tableName , awsErr .Code (), operation ).Add (float64 (1 ))
762
762
} else {
763
- dynamoFailures .WithLabelValues (tableName , otherError , operation ).Add (float64 (1 ))
763
+ metrics . dynamoFailures .WithLabelValues (tableName , otherError , operation ).Add (float64 (1 ))
764
764
}
765
765
}
766
766
0 commit comments