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

Wrapping transport #149

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,19 @@ type BucketConfig struct {
Prefix string `yaml:"prefix" default:""`
}

/*
func(rt http.RoundTripper) http.RoundTripper {
if rt == nil {
rt = http.DefaultTransport
}

return wrapHedgedRoundtripper(rt)
}
*/

// NewBucket initializes and returns new object storage clients.
// NOTE: confContentYaml can contain secrets.
func NewBucket(logger log.Logger, confContentYaml []byte, component string, rt http.RoundTripper) (objstore.Bucket, error) {
func NewBucket(logger log.Logger, confContentYaml []byte, component string, wrapRoundtripper func(http.RoundTripper) http.RoundTripper) (objstore.Bucket, error) {
level.Info(logger).Log("msg", "loading bucket configuration")
bucketConf := &BucketConfig{}
if err := yaml.UnmarshalStrict(confContentYaml, bucketConf); err != nil {
Expand All @@ -67,7 +77,7 @@ func NewBucket(logger log.Logger, confContentYaml []byte, component string, rt h
case string(GCS):
bucket, err = gcs.NewBucket(context.Background(), logger, config, component, rt)
case string(S3):
bucket, err = s3.NewBucket(logger, config, component, rt)
bucket, err = s3.NewBucket(logger, config, component, wrapRoundtripper)
case string(AZURE):
bucket, err = azure.NewBucket(logger, config, component, rt)
case string(SWIFT):
Expand Down
8 changes: 3 additions & 5 deletions providers/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@
}

// NewBucket returns a new Bucket using the provided s3 config values.
func NewBucket(logger log.Logger, conf []byte, component string, rt http.RoundTripper) (*Bucket, error) {
func NewBucket(logger log.Logger, conf []byte, component string, wrapRoundtripper func(http.RoundTripper) http.RoundTripper) (*Bucket, error) {
config, err := parseConfig(conf)
if err != nil {
return nil, err
}

return NewBucketWithConfig(logger, config, component, rt)

Check failure on line 185 in providers/s3/s3.go

View workflow job for this annotation

GitHub Actions / Run tests

undefined: rt

Check failure on line 185 in providers/s3/s3.go

View workflow job for this annotation

GitHub Actions / Documentation check

undefined: rt

Check failure on line 185 in providers/s3/s3.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

undefined: rt
}

type overrideSignerType struct {
Expand All @@ -202,7 +202,7 @@
}

// NewBucketWithConfig returns a new Bucket using the provided s3 config values.
func NewBucketWithConfig(logger log.Logger, config Config, component string, rt http.RoundTripper) (*Bucket, error) {
func NewBucketWithConfig(logger log.Logger, config Config, component string, wrapRoundtripper func(http.RoundTripper) http.RoundTripper) (*Bucket, error) {
var chain []credentials.Provider

// TODO(bwplotka): Don't do flags as they won't scale, use actual params like v2, v4 instead
Expand Down Expand Up @@ -242,9 +242,6 @@
}),
}
}
if rt != nil {
config.HTTPConfig.Transport = rt
}
// Check if a roundtripper has been set in the config
// otherwise build the default transport.
var tpt http.RoundTripper
Expand All @@ -255,6 +252,7 @@
if config.HTTPConfig.Transport != nil {
tpt = config.HTTPConfig.Transport
}
tpt = wrapRoundtripper(tpt)

client, err := minio.New(config.Endpoint, &minio.Options{
Creds: credentials.NewChainCredentials(chain),
Expand Down
Loading