Skip to content

Commit 2a3bd2b

Browse files
authored
Upgrade aws-sdk-go-v2 (sourcegraph#19155)
This PR: - Migrates to the AWS v2 API in the codeintel s3 adapter - Upgrades the v2 package to the newest version
1 parent 28c8108 commit 2a3bd2b

File tree

16 files changed

+289
-242
lines changed

16 files changed

+289
-242
lines changed

cmd/server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ COPY --from=comby/comby:0.18.4@sha256:b47ce282778bfea7f80d45f5ef0cc546ba0d6347ba
5454
COPY --from=sourcegraph/syntect_server:331beda@sha256:6b8950b41993af3d10300b5a160fab1c06c337cb4614978f4fdb76e2588afbfe /syntect_server /usr/local/bin/
5555

5656
# install minio (keep this up to date with docker-images/minio/Dockerfile)
57-
ENV MINIO_VERSION=RELEASE.2020-10-18T21-54-12Z
57+
ENV MINIO_VERSION=RELEASE.2021-04-06T23-11-00Z
5858
RUN wget "https://dl.min.io/server/minio/release/linux-amd64/archive/minio.$MINIO_VERSION" && \
5959
chmod +x "minio.$MINIO_VERSION" && \
6060
mv "minio.$MINIO_VERSION" /usr/local/bin/minio

dev/go-mod-update.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ go get -u all
1414
## names. This is causing our use of our k8s client to panic.
1515
go get github.com/golang/[email protected]
1616

17-
## Newer versions removed some types in the endpoint package we relied on. Unsure how to fix yet, so punting.
18-
go get github.com/aws/[email protected]
19-
2017
# Cleanup and validate everything still works
2118
go mod tidy
2219
go test -short -failfast ./... >/dev/null

doc/dependency_decisions.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,10 @@
346346
:why: Internal module
347347
:versions: []
348348
:when: 2021-03-09 19:42:12.214862934 Z
349+
- - :license
350+
- github.com/aws/smithy-go
351+
- Apache 2.0
352+
- :who:
353+
:why: Inference broken, LICENSE file lives at https://github.com/aws/smithy-go/blob/main/LICENSE
354+
:versions: []
355+
:when: 2021-04-14 12:51:19.503802000 Z

docker-images/minio/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -ex
44
cd "$(dirname "${BASH_SOURCE[0]}")"
55

6-
# Retag the 2020-10-18 MinIO release
7-
MINIO_RELEASE="RELEASE.2020-10-18T21-54-12Z"
6+
# Retag the 2021-04-06 MinIO release
7+
MINIO_RELEASE="RELEASE.2021-04-06T23-11-00Z"
88
docker pull minio/minio:$MINIO_RELEASE
99
docker tag minio/minio:$MINIO_RELEASE "$IMAGE"

enterprise/cmd/precise-code-intel-worker/main.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/http"
99
"time"
1010

11-
"github.com/aws/aws-sdk-go/aws/awserr"
11+
smithyhttp "github.com/aws/smithy-go/transport/http"
1212
"github.com/inconshreveable/log15"
1313
"github.com/opentracing/opentracing-go"
1414
"github.com/prometheus/client_golang/prometheus"
@@ -199,15 +199,6 @@ func initializeUploadStore(ctx context.Context, uploadStore uploadstore.Store) e
199199
}
200200

201201
func isRequestError(err error) bool {
202-
for err != nil {
203-
if e, ok := err.(awserr.Error); ok {
204-
if e.Code() == "RequestError" {
205-
return true
206-
}
207-
}
208-
209-
err = errors.Unwrap(err)
210-
}
211-
212-
return false
202+
var rse *smithyhttp.RequestSendError
203+
return errors.As(err, &rse)
213204
}

enterprise/internal/codeintel/stores/uploadstore/config_test.go

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package uploadstore
22

33
import (
4+
"context"
45
"testing"
56
"time"
7+
8+
"github.com/aws/aws-sdk-go-v2/aws"
9+
"github.com/aws/aws-sdk-go-v2/service/s3"
10+
"github.com/google/go-cmp/cmp"
611
)
712

813
func TestConfigDefaults(t *testing.T) {
@@ -70,25 +75,44 @@ func TestConfigS3(t *testing.T) {
7075
}
7176
}
7277

73-
func TestConfigMinIOSessionOptions(t *testing.T) {
78+
func TestS3ClientOptions(t *testing.T) {
7479
config := Config{}
7580
config.SetMockGetter(mapGetter(nil))
7681
config.Load()
7782

78-
options := s3SessionOptions("minio", config.S3)
83+
// minIO
84+
{
85+
options := &s3.Options{}
86+
s3ClientOptions("minio", config.S3)(options)
7987

80-
if value := *options.Config.Region; value != "us-east-1" {
81-
t.Errorf("unexpected region. want=%s have=%s", "us-east-1", value)
82-
}
83-
if value := *options.Config.Endpoint; value != "http://minio:9000" {
84-
t.Errorf("unexpected endpoint. want=%s have=%s", "http://minio:9000", value)
88+
if options.EndpointResolver == nil {
89+
t.Fatalf("unexpected endpoint option")
90+
}
91+
endpoint, err := options.EndpointResolver.ResolveEndpoint("us-east-2", s3.EndpointResolverOptions{})
92+
if err != nil {
93+
t.Fatal(err)
94+
}
95+
if endpoint.URL != "http://minio:9000" {
96+
t.Errorf("unexpected endpoint. want=%s have=%s", "http://minio:9000", endpoint.URL)
97+
}
98+
99+
if !options.UsePathStyle {
100+
t.Errorf("invalid UsePathStyle setting for S3Options")
101+
}
85102
}
86-
if options.Config.S3ForcePathStyle == nil || !*options.Config.S3ForcePathStyle {
87-
t.Errorf("expected path style option")
103+
104+
// S3
105+
{
106+
options := &s3.Options{}
107+
s3ClientOptions("s3", config.S3)(options)
108+
109+
if diff := cmp.Diff(&s3.Options{}, options); diff != "" {
110+
t.Fatalf("invalid s3 options returned for S3: %s", diff)
111+
}
88112
}
89113
}
90114

91-
func TestConfigS3SessionOptions(t *testing.T) {
115+
func TestS3ClientConfig(t *testing.T) {
92116
env := map[string]string{
93117
"PRECISE_CODE_INTEL_UPLOAD_BACKEND": "S3",
94118
"PRECISE_CODE_INTEL_UPLOAD_BUCKET": "lsif-uploads",
@@ -104,16 +128,28 @@ func TestConfigS3SessionOptions(t *testing.T) {
104128
config.SetMockGetter(mapGetter(env))
105129
config.Load()
106130

107-
options := s3SessionOptions("s3", config.S3)
131+
cfg, err := s3ClientConfig(context.Background(), config.S3)
132+
if err != nil {
133+
t.Fatal(err)
134+
}
108135

109-
if value := *options.Config.Region; value != "us-east-2" {
136+
if value := cfg.Region; value != "us-east-2" {
110137
t.Errorf("unexpected region. want=%s have=%s", "us-east-2", value)
111138
}
112-
if options.Config.Endpoint != nil {
113-
t.Errorf("unexpected endpoint option")
139+
cred, err := cfg.Credentials.Retrieve(context.Background())
140+
if err != nil {
141+
t.Fatal(err)
142+
}
143+
if diff := cmp.Diff(aws.Credentials{
144+
AccessKeyID: config.S3.AccessKeyID,
145+
SecretAccessKey: config.S3.SecretAccessKey,
146+
SessionToken: config.S3.SessionToken,
147+
Source: "StaticCredentials",
148+
}, cred); diff != "" {
149+
t.Errorf("invalid credential returned: %s", diff)
114150
}
115-
if options.Config.S3ForcePathStyle != nil {
116-
t.Errorf("unexpected path style option")
151+
if cfg.EndpointResolver != nil {
152+
t.Errorf("unexpected endpoint option")
117153
}
118154
}
119155

enterprise/internal/codeintel/stores/uploadstore/mock_s3_api_test.go

Lines changed: 12 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/internal/codeintel/stores/uploadstore/s3_api.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package uploadstore
33
import (
44
"context"
55

6-
"github.com/aws/aws-sdk-go/service/s3"
7-
"github.com/aws/aws-sdk-go/service/s3/s3manager"
6+
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
7+
"github.com/aws/aws-sdk-go-v2/service/s3"
88
)
99

1010
type s3API interface {
@@ -20,52 +20,52 @@ type s3API interface {
2020
}
2121

2222
type s3Uploader interface {
23-
Upload(ctx context.Context, input *s3manager.UploadInput) error
23+
Upload(ctx context.Context, input *s3.PutObjectInput) error
2424
}
2525

26-
type s3APIShim struct{ *s3.S3 }
27-
type s3UploaderShim struct{ *s3manager.Uploader }
26+
type s3APIShim struct{ *s3.Client }
27+
type s3UploaderShim struct{ *manager.Uploader }
2828

2929
var _ s3API = &s3APIShim{}
3030
var _ s3Uploader = &s3UploaderShim{}
3131

3232
func (s *s3APIShim) CreateBucket(ctx context.Context, input *s3.CreateBucketInput) (*s3.CreateBucketOutput, error) {
33-
return s.S3.CreateBucketWithContext(ctx, input)
33+
return s.Client.CreateBucket(ctx, input)
3434
}
3535

3636
func (s *s3APIShim) PutBucketLifecycleConfiguration(ctx context.Context, input *s3.PutBucketLifecycleConfigurationInput) (*s3.PutBucketLifecycleConfigurationOutput, error) {
37-
return s.S3.PutBucketLifecycleConfigurationWithContext(ctx, input)
37+
return s.Client.PutBucketLifecycleConfiguration(ctx, input)
3838
}
3939

4040
func (s *s3APIShim) HeadObject(ctx context.Context, input *s3.HeadObjectInput) (*s3.HeadObjectOutput, error) {
41-
return s.S3.HeadObjectWithContext(ctx, input)
41+
return s.Client.HeadObject(ctx, input)
4242
}
4343

4444
func (s *s3APIShim) GetObject(ctx context.Context, input *s3.GetObjectInput) (*s3.GetObjectOutput, error) {
45-
return s.S3.GetObjectWithContext(ctx, input)
45+
return s.Client.GetObject(ctx, input)
4646
}
4747

4848
func (s *s3APIShim) DeleteObject(ctx context.Context, input *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error) {
49-
return s.S3.DeleteObjectWithContext(ctx, input)
49+
return s.Client.DeleteObject(ctx, input)
5050
}
5151

5252
func (s *s3APIShim) CreateMultipartUpload(ctx context.Context, input *s3.CreateMultipartUploadInput) (*s3.CreateMultipartUploadOutput, error) {
53-
return s.S3.CreateMultipartUploadWithContext(ctx, input)
53+
return s.Client.CreateMultipartUpload(ctx, input)
5454
}
5555

5656
func (s *s3APIShim) AbortMultipartUpload(ctx context.Context, input *s3.AbortMultipartUploadInput) (*s3.AbortMultipartUploadOutput, error) {
57-
return s.S3.AbortMultipartUploadWithContext(ctx, input)
57+
return s.Client.AbortMultipartUpload(ctx, input)
5858
}
5959

6060
func (s *s3APIShim) UploadPartCopy(ctx context.Context, input *s3.UploadPartCopyInput) (*s3.UploadPartCopyOutput, error) {
61-
return s.S3.UploadPartCopyWithContext(ctx, input)
61+
return s.Client.UploadPartCopy(ctx, input)
6262
}
6363

6464
func (s *s3APIShim) CompleteMultipartUpload(ctx context.Context, input *s3.CompleteMultipartUploadInput) (*s3.CompleteMultipartUploadOutput, error) {
65-
return s.S3.CompleteMultipartUploadWithContext(ctx, input)
65+
return s.Client.CompleteMultipartUpload(ctx, input)
6666
}
6767

68-
func (s *s3UploaderShim) Upload(ctx context.Context, input *s3manager.UploadInput) error {
69-
_, err := s.Uploader.UploadWithContext(ctx, input)
68+
func (s *s3UploaderShim) Upload(ctx context.Context, input *s3.PutObjectInput) error {
69+
_, err := s.Uploader.Upload(ctx, input)
7070
return err
7171
}

0 commit comments

Comments
 (0)