Skip to content

Commit 5e3ce13

Browse files
committed
cloud/amazon: renaming cloud.Config to cloud.HTTPClientConfig.
Renaming cloud.Config to cloud.HTTPClientConfig to be more specific. Added InjectTestingRetryMaxAttempts to limit number of request retries during testing. Release note: None
1 parent 8447ed9 commit 5e3ce13

File tree

9 files changed

+53
-26
lines changed

9 files changed

+53
-26
lines changed

pkg/cloud/amazon/aws_kms.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func MakeAWSKMS(ctx context.Context, uri string, env cloud.KMSEnv) (cloud.KMS, e
145145
"custom endpoints disallowed for aws kms due to --aws-kms-disable-http flag")
146146
}
147147
client, err := cloud.MakeHTTPClient(env.ClusterSettings(), cloud.NilMetrics,
148-
cloud.Config{
148+
cloud.HTTPClientConfig{
149149
Bucket: "KMS",
150150
Cloud: "aws",
151151
})

pkg/cloud/amazon/s3_storage.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ const (
8989
scheme = "s3"
9090

9191
checksumAlgorithm = types.ChecksumAlgorithmSha256
92+
93+
// TODO(yevgeniy): Revisit retry logic. Retrying 10 times seems arbitrary.
94+
defaultRetryMaxAttempts = 10
9295
)
9396

9497
// NightlyEnvVarS3Params maps param keys that get added to an S3
@@ -122,6 +125,16 @@ type s3Storage struct {
122125
cached *s3Client
123126
}
124127

128+
// retryMaxAttempts defines how many times we will retry a
129+
// S3 request on a retriable error.
130+
var retryMaxAttempts = defaultRetryMaxAttempts
131+
132+
// InjectTestingRetryMaxAttempts is used to change the
133+
// default retries for tests that need quick fail.
134+
func InjectTestingRetryMaxAttempts(maxAttempts int) {
135+
retryMaxAttempts = maxAttempts
136+
}
137+
125138
// customRetryer implements the `request.Retryer` interface and allows for
126139
// customization of the retry behaviour of an AWS client.
127140
type customRetryer struct{}
@@ -587,7 +600,7 @@ func (s *s3Storage) newClient(ctx context.Context) (s3Client, string, error) {
587600
}
588601

589602
client, err := cloud.MakeHTTPClient(s.settings, s.metrics,
590-
cloud.Config{
603+
cloud.HTTPClientConfig{
591604
Bucket: s.opts.bucket,
592605
Client: s.storageOptions.ClientName,
593606
Cloud: "aws",
@@ -598,15 +611,12 @@ func (s *s3Storage) newClient(ctx context.Context) (s3Client, string, error) {
598611
}
599612
addLoadOption(config.WithHTTPClient(client))
600613

601-
// TODO(yevgeniy): Revisit retry logic. Retrying 10 times seems arbitrary.
602-
retryMaxAttempts := 10
603614
addLoadOption(config.WithRetryMaxAttempts(retryMaxAttempts))
604615

605616
addLoadOption(config.WithLogger(newLogAdapter(ctx)))
606617
if s.opts.verbose {
607618
addLoadOption(config.WithClientLogMode(awsVerboseLogging))
608619
}
609-
610620
config.WithRetryer(func() aws.Retryer {
611621
return retry.NewStandard(func(opts *retry.StandardOptions) {
612622
opts.MaxAttempts = retryMaxAttempts

pkg/cloud/amazon/s3_storage_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,8 @@ func TestPutS3Endpoint(t *testing.T) {
455455
q.Add(AWSSecretParam, "secret")
456456
q.Add(S3RegionParam, "region")
457457
q.Add(AWSUsePathStyle, "true")
458-
// Set AWSSkipTLSVerify to use with HTTPS Server with self signed certificates.
459-
q.Add(AWSSkipTLSVerify, "true")
460458

459+
// Verify that it fails without the flag.
461460
u := url.URL{
462461
Scheme: "s3",
463462
Host: "bucket",
@@ -476,15 +475,33 @@ func TestPutS3Endpoint(t *testing.T) {
476475
// Setup a sink for the given args.
477476
testSettings := cluster.MakeTestingClusterSettings()
478477
clientFactory := blobs.TestBlobServiceClient("")
479-
478+
// Force to fail quickly.
479+
InjectTestingRetryMaxAttempts(1)
480480
storage, err := cloud.MakeExternalStorage(ctx, conf, ioConf, testSettings, clientFactory,
481481
nil, nil, cloud.NilMetrics)
482482
if err != nil {
483483
t.Fatal(err)
484484
}
485485
defer storage.Close()
486-
require.True(t, storage.Conf().S3Config.SkipTLSVerify)
487486
_, _, err = storage.ReadFile(ctx, "test file", cloud.ReadOptions{NoFileSize: true})
487+
require.Error(t, err)
488+
489+
// Set AWSSkipTLSVerify to use with HTTPS Server with self signed certificates.
490+
q.Add(AWSSkipTLSVerify, "true")
491+
u.RawQuery = q.Encode()
492+
493+
confWithSkipVerify, err := cloud.ExternalStorageConfFromURI(u.String(), user)
494+
if err != nil {
495+
t.Fatal(err)
496+
}
497+
storageWithSkipVerify, err := cloud.MakeExternalStorage(ctx, confWithSkipVerify, ioConf, testSettings, clientFactory,
498+
nil, nil, cloud.NilMetrics)
499+
if err != nil {
500+
t.Fatal(err)
501+
}
502+
defer storageWithSkipVerify.Close()
503+
require.True(t, storageWithSkipVerify.Conf().S3Config.SkipTLSVerify)
504+
_, _, err = storageWithSkipVerify.ReadFile(ctx, "another test file", cloud.ReadOptions{NoFileSize: true})
488505
if err != nil {
489506
t.Fatal(err)
490507
}

pkg/cloud/azure/azure_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func makeAzureStorage(
222222

223223
options := args.ExternalStorageOptions()
224224
t, err := cloud.MakeHTTPClient(args.Settings, args.MetricsRecorder,
225-
cloud.Config{
225+
cloud.HTTPClientConfig{
226226
Bucket: dest.AzureConfig.Container,
227227
Client: options.ClientName,
228228
Cloud: "azure",

pkg/cloud/cloud_io.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/cockroachdb/errors"
2929
)
3030

31-
// Config defines the settings for building the underlying transport.
32-
type Config struct {
31+
// HTTPClientConfig defines the settings for building the underlying transport.
32+
type HTTPClientConfig struct {
3333
// Bucket is name of the bucket. Used to label metrics.
3434
Bucket string
3535
// Client type (e.g. CDC vs backup). Used to label metrics.
@@ -92,7 +92,7 @@ var httpMetrics = settings.RegisterBoolSetting(
9292
// MakeHTTPClient makes an http client configured with the common settings used
9393
// for interacting with cloud storage (timeouts, retries, CA certs, etc).
9494
func MakeHTTPClient(
95-
settings *cluster.Settings, metrics *Metrics, config Config,
95+
settings *cluster.Settings, metrics *Metrics, config HTTPClientConfig,
9696
) (*http.Client, error) {
9797
t, err := MakeTransport(settings, metrics, config)
9898
if err != nil {
@@ -114,7 +114,7 @@ func MakeHTTPClientForTransport(t http.RoundTripper) (*http.Client, error) {
114114
// used for interacting with cloud storage (timeouts, retries, CA certs, etc).
115115
// Prefer MakeHTTPClient where possible.
116116
func MakeTransport(
117-
settings *cluster.Settings, metrics *Metrics, config Config,
117+
settings *cluster.Settings, metrics *Metrics, config HTTPClientConfig,
118118
) (*http.Transport, error) {
119119
var tlsConf *tls.Config
120120
if config.InsecureSkipVerify {

pkg/cloud/gcp/gcs_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func makeGCSStorage(
186186
}
187187

188188
clientName := args.ExternalStorageOptions().ClientName
189-
baseTransport, err := cloud.MakeTransport(args.Settings, args.MetricsRecorder, cloud.Config{
189+
baseTransport, err := cloud.MakeTransport(args.Settings, args.MetricsRecorder, cloud.HTTPClientConfig{
190190
Bucket: conf.Bucket,
191191
Client: clientName,
192192
Cloud: "gcs",

pkg/cloud/httpsink/http_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func MakeHTTPStorage(
6868

6969
clientName := args.ExternalStorageOptions().ClientName
7070
client, err := cloud.MakeHTTPClient(args.Settings, args.MetricsRecorder,
71-
cloud.Config{
71+
cloud.HTTPClientConfig{
7272
Cloud: "http",
7373
Bucket: "base",
7474
Client: clientName,

pkg/cmd/roachtest/tests/s3_clone_backup_restore.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ import (
2727
type s3CloneSecureOption int
2828

2929
const (
30-
s3ClonePlain s3CloneSecureOption = iota // Use HTTP
31-
s3CloneRequireTLS // Use HTTPS, but skip certification verification.
32-
s3CloneVerifyTLS // Use HTTPS and verify certificates.
30+
s3ClonePlain s3CloneSecureOption = iota // Use HTTP
31+
s3CloneTLSWithSkipVerify // Use HTTPS, but skip certification verification.
32+
s3CloneTLS // Use HTTPS and verify certificates.
3333
)
3434

35-
var s3CloneSecureOptions = []s3CloneSecureOption{s3ClonePlain, s3CloneRequireTLS, s3CloneVerifyTLS}
35+
var s3CloneSecureOptions = []s3CloneSecureOption{s3ClonePlain, s3CloneTLSWithSkipVerify, s3CloneTLS}
3636

3737
func (o s3CloneSecureOption) String() string {
3838
switch o {
3939
case s3ClonePlain:
4040
return "plain"
41-
case s3CloneRequireTLS:
42-
return "require"
43-
case s3CloneVerifyTLS:
44-
return "verify"
41+
case s3CloneTLSWithSkipVerify:
42+
return "tlsSkipVerify"
43+
case s3CloneTLS:
44+
return "tls"
4545
default:
4646
panic("invalid option")
4747
}

pkg/cmd/roachtest/tests/s3_microceph.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (m cephManager) getBackupURI(ctx context.Context, dest string) (string, err
8787
// Region is required in the URL, but not used in Ceph.
8888
q.Add(amazon.S3RegionParam, "dummy")
8989
q.Add(amazon.AWSEndpointParam, endpointURL)
90-
if m.secure == s3CloneRequireTLS {
90+
if m.secure == s3CloneTLSWithSkipVerify {
9191
q.Add(amazon.AWSSkipTLSVerify, "true")
9292
}
9393
uri := fmt.Sprintf("s3://%s/%s?%s", m.bucket, dest, q.Encode())
@@ -145,7 +145,7 @@ func (m cephManager) install(ctx context.Context) {
145145

146146
// maybeInstallCa adds a custom ca in the CockroachDB cluster.
147147
func (m cephManager) maybeInstallCa(ctx context.Context) error {
148-
if m.secure != s3CloneVerifyTLS {
148+
if m.secure != s3CloneTLS {
149149
return nil
150150
}
151151
return installCa(ctx, m.t, m.c)

0 commit comments

Comments
 (0)