Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(aws): aws signer has cache and can be reused #886

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/roundtripper/roundtripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type AWSSigningTransport struct {
creds aws.CredentialsProvider
region string
log log.Logger
signer *v4.Signer
}

func NewAWSSigningTransport(transport http.RoundTripper, region string, roleArn string, log log.Logger) (*AWSSigningTransport, error) {
Expand Down Expand Up @@ -67,11 +68,11 @@ func NewAWSSigningTransport(transport http.RoundTripper, region string, roleArn
region: region,
creds: creds,
log: log,
signer: v4.NewSigner(),
}, err
}

func (a *AWSSigningTransport) RoundTrip(req *http.Request) (*http.Response, error) {
signer := v4.NewSigner()
payloadHash, newReader, err := hashPayload(req.Body)
if err != nil {
level.Error(a.log).Log("msg", "failed to hash request body", "err", err)
Expand All @@ -85,7 +86,7 @@ func (a *AWSSigningTransport) RoundTrip(req *http.Request) (*http.Response, erro
return nil, err
}

err = signer.SignHTTP(context.Background(), creds, req, payloadHash, service, a.region, time.Now())
err = a.signer.SignHTTP(context.Background(), creds, req, payloadHash, service, a.region, time.Now())
if err != nil {
level.Error(a.log).Log("msg", "failed to sign request body", "err", err)
return nil, err
Expand Down