Repository navigation
Migrate to AWS SDK for Go v2 - #15
Merged
Merged
Conversation
- Replace firehoseiface.FirehoseAPI with FirehoseAPI, an interface that has only PutRecordBatch of *firehose.Client (v2). - Use types.Record (value) in place of *firehose.Record for Enqueue and ErrorHandler. - Rewrite isRetryable with smithy error types. It keeps the set of retryable errors of v1 (request.IsErrorRetryable, IsErrorThrottle, HTTP 429/500/502/503/504, and "read: connection reset by peer"). - Set the go directive to 1.24 (the minimum of aws-sdk-go-v2) and drop github.com/aws/aws-sdk-go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Khu7nnDtvrt5NV5H7kvCn6
mash
marked this pull request as ready for review
October 27, 2026 16:04
soh335
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目的
firequeue の AWS SDK for Go を v1 (
github.com/aws/aws-sdk-go) から v2 (github.com/aws/aws-sdk-go-v2) に移す。外向きの挙動、ログ、既存テストの期待値は変えない。retry する応答と retry しない応答の組も v1 と同じにする。
公開 API の旧→新対応
New(fh firehoseiface.FirehoseAPI, ...)New(fh FirehoseAPI, ...)firehoseiface.FirehoseAPIFirehoseAPI(*firehose.ClientのPutRecordBatchだけを持つ interface)(*Queue).Enqueue(r *firehose.Record)(*Queue).Enqueue(r types.Record)ErrorHandler(fn func(error, []*firehose.Record))ErrorHandler(fn func(error, []types.Record))types.Recordは値型にした。v2 のPutRecordBatchInput.Recordsが[]types.Recordなので、firequeue は変換せずにそのまま渡せる。Dataの[]byteは v1 と同じく呼び出し元と共有する。retry 判定の新旧対応
isRetryableは v1 のrequest.IsErrorRetryable・request.IsErrorThrottle・HTTP status の判定を v2 のエラー型で書き直した。awserr.RequestFailureの status 429/500/502/503/504*smithyhttp.ResponseErrorの status 429/500/502/503/504smithy.APIErrorの同じエラーコード (retryableErrorCodes)InvalidArgumentException, 501)smithy.APIErrorRequestCanceled*smithy.CanceledError,*aws.RequestCanceledError,context.CanceledRequestError(cause をshouldRetryErrorで判定)*smithyhttp.RequestSendError(cause を同じ規則で判定)SerializationError(cause を判定、cause が無ければ retry しない)*smithy.DeserializationError(同じ規則)*smithy.InvalidParamsErrorなどread: connection reset by peerを含むエラーv2 の client が retry を使い切ったときに返す
*retry.MaxAttemptsErrorは、包んだエラーで判定する。aws-sdk-go v1.35.33 で旧
isRetryableに 24 ケースのエラーを渡し、retry_test.goのTestIsRetryableで対応するケースの期待値と一致することを確かめた。呼び出し元への注意
SDK 内部の retry 回数
v1 の
DefaultRetryerは MaxRetries=3 で、1 回の PutRecordBatch に最大 4 回の attempt を使う。v2 の標準 retryer は最大 3 回の attempt を使う。firequeue は client を受け取るだけなので、この回数は client を作る呼び出し元が揃える(例:retry.AddWithMaxAttempts(retry.NewStandard(), 4))。SDK 内部の retry quota
v2 の標準 retryer は token bucket で retry の回数を制限する。容量は 500 token である。retry 1 回に 5 token(timeout のときは 10 token)を使い、1 回目の attempt で成功すると 1 token を戻す。token が尽きると、client は retry をやめて、すぐに
*retry.QuotaExceededErrorを返す。v1 にはこの制限が無い。firequeue は
QuotaExceededErrorが包んだエラーで判定し、retry 対象なら自分の backoff で送り直す。このため、レコードは失わない。ただし、throttle が続く間は、client の中の retry が v1 より早く止まる。v1 と揃えるには、呼び出し元が client の retryer にRateLimiter = ratelimit.Noneを設定する。エラー文の形式
v2 の client が返すエラーは、v1 と文の形式が違う。
ErrorHandlerを渡さないとき、firequeue はこのエラーを log に出すので、log の文も変わる。InvalidArgumentException: ...\n\tstatus code: 400, request id: ...operation error Firehose: PutRecordBatch, https response error StatusCode: 400, RequestID: ..., InvalidArgumentException: ...呼び出し元は次の 2 点を確かめる。
ErrorHandlerの中で、エラーを v1 の型(awserr.Errorなど)に変換していないか。v2 のエラーはこの型に当たらないので、判定が常に外れる。go directive
godirective を 1.14 から 1.24 にした。1.24 は aws-sdk-go-v2・service/firehose・smithy-go が要求する最小の版である。既知の問題(範囲外)
attemptToSendBatchは、PutRecordBatchがerr == nilでFailedPutCount > 0を返したとき、失敗したレコードを retry しない。retry するのは err が retry 対象のときだけである。v1 のときから同じ挙動なので、この PR では直さない。テスト
go build ./...、go vet ./...、gofmt -l .が通ることを手元で確かめた。go testは CI (GitHub Actions の test ワークフロー) で確かめる。