Skip to content

Commit 99d6667

Browse files
committed
Swift: add HTTP_Config
Signed-off-by: btaani <[email protected]>
1 parent cd121fe commit 99d6667

File tree

3 files changed

+77
-26
lines changed

3 files changed

+77
-26
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
4040
- [#94](https://github.com/thanos-io/objstore/pull/94) Allow timingReadCloser to be seeker
4141
- [#96](https://github.com/thanos-io/objstore/pull/96) Allow nopCloserWithObjectSize to be seeker
4242
- [#86](https://github.com/thanos-io/objstore/pull/86) GCS: Add HTTP Config to GCS
43+
- [#99](https://github.com/thanos-io/objstore/pull/99) Swift: Add HTTP_Config
4344

4445
### Changed
4546
- [#38](https://github.com/thanos-io/objstore/pull/38) *: Upgrade minio-go version to `v7.0.45`.

providers/swift/swift.go

+46-26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"io"
11+
"net/http"
1112
"os"
1213
"strconv"
1314
"strings"
@@ -21,6 +22,7 @@ import (
2122
"github.com/pkg/errors"
2223
"github.com/prometheus/common/model"
2324
"github.com/thanos-io/objstore"
25+
"github.com/thanos-io/objstore/exthttp"
2426
"gopkg.in/yaml.v2"
2527
)
2628

@@ -37,33 +39,35 @@ var DefaultConfig = Config{
3739
Retries: 3,
3840
ConnectTimeout: model.Duration(10 * time.Second),
3941
Timeout: model.Duration(5 * time.Minute),
42+
HTTPConfig: exthttp.DefaultHTTPConfig,
4043
}
4144

4245
type Config struct {
43-
AuthVersion int `yaml:"auth_version"`
44-
AuthUrl string `yaml:"auth_url"`
45-
Username string `yaml:"username"`
46-
UserDomainName string `yaml:"user_domain_name"`
47-
UserDomainID string `yaml:"user_domain_id"`
48-
UserId string `yaml:"user_id"`
49-
Password string `yaml:"password"`
50-
DomainId string `yaml:"domain_id"`
51-
DomainName string `yaml:"domain_name"`
52-
ApplicationCredentialID string `yaml:"application_credential_id"`
53-
ApplicationCredentialName string `yaml:"application_credential_name"`
54-
ApplicationCredentialSecret string `yaml:"application_credential_secret"`
55-
ProjectID string `yaml:"project_id"`
56-
ProjectName string `yaml:"project_name"`
57-
ProjectDomainID string `yaml:"project_domain_id"`
58-
ProjectDomainName string `yaml:"project_domain_name"`
59-
RegionName string `yaml:"region_name"`
60-
ContainerName string `yaml:"container_name"`
61-
ChunkSize int64 `yaml:"large_object_chunk_size"`
62-
SegmentContainerName string `yaml:"large_object_segments_container_name"`
63-
Retries int `yaml:"retries"`
64-
ConnectTimeout model.Duration `yaml:"connect_timeout"`
65-
Timeout model.Duration `yaml:"timeout"`
66-
UseDynamicLargeObjects bool `yaml:"use_dynamic_large_objects"`
46+
AuthVersion int `yaml:"auth_version"`
47+
AuthUrl string `yaml:"auth_url"`
48+
Username string `yaml:"username"`
49+
UserDomainName string `yaml:"user_domain_name"`
50+
UserDomainID string `yaml:"user_domain_id"`
51+
UserId string `yaml:"user_id"`
52+
Password string `yaml:"password"`
53+
DomainId string `yaml:"domain_id"`
54+
DomainName string `yaml:"domain_name"`
55+
ApplicationCredentialID string `yaml:"application_credential_id"`
56+
ApplicationCredentialName string `yaml:"application_credential_name"`
57+
ApplicationCredentialSecret string `yaml:"application_credential_secret"`
58+
ProjectID string `yaml:"project_id"`
59+
ProjectName string `yaml:"project_name"`
60+
ProjectDomainID string `yaml:"project_domain_id"`
61+
ProjectDomainName string `yaml:"project_domain_name"`
62+
RegionName string `yaml:"region_name"`
63+
ContainerName string `yaml:"container_name"`
64+
ChunkSize int64 `yaml:"large_object_chunk_size"`
65+
SegmentContainerName string `yaml:"large_object_segments_container_name"`
66+
Retries int `yaml:"retries"`
67+
ConnectTimeout model.Duration `yaml:"connect_timeout"`
68+
Timeout model.Duration `yaml:"timeout"`
69+
UseDynamicLargeObjects bool `yaml:"use_dynamic_large_objects"`
70+
HTTPConfig exthttp.HTTPConfig `yaml:"http_config"`
6771
}
6872

6973
func parseConfig(conf []byte) (*Config, error) {
@@ -101,6 +105,7 @@ func configFromEnv() (*Config, error) {
101105
ConnectTimeout: model.Duration(c.ConnectTimeout),
102106
Timeout: model.Duration(c.Timeout),
103107
UseDynamicLargeObjects: false,
108+
HTTPConfig: DefaultConfig.HTTPConfig,
104109
}
105110
if os.Getenv("SWIFT_CHUNK_SIZE") != "" {
106111
var err error
@@ -115,7 +120,7 @@ func configFromEnv() (*Config, error) {
115120
return &config, nil
116121
}
117122

118-
func connectionFromConfig(sc *Config) *swift.Connection {
123+
func connectionFromConfig(sc *Config, rt http.RoundTripper) *swift.Connection {
119124
connection := swift.Connection{
120125
AuthVersion: sc.AuthVersion,
121126
AuthUrl: sc.AuthUrl,
@@ -135,6 +140,7 @@ func connectionFromConfig(sc *Config) *swift.Connection {
135140
Retries: sc.Retries,
136141
ConnectTimeout: time.Duration(sc.ConnectTimeout),
137142
Timeout: time.Duration(sc.Timeout),
143+
Transport: rt,
138144
}
139145
return &connection
140146
}
@@ -173,7 +179,21 @@ func ensureContainer(connection *swift.Connection, name string, createIfNotExist
173179
}
174180

175181
func NewContainerFromConfig(logger log.Logger, sc *Config, createContainer bool) (*Container, error) {
176-
connection := connectionFromConfig(sc)
182+
183+
// Check if a roundtripper has been set in the config
184+
// otherwise build the default transport.
185+
var rt http.RoundTripper
186+
if sc.HTTPConfig.Transport != nil {
187+
rt = sc.HTTPConfig.Transport
188+
} else {
189+
var err error
190+
rt, err = exthttp.DefaultTransport(sc.HTTPConfig)
191+
if err != nil {
192+
return nil, err
193+
}
194+
}
195+
196+
connection := connectionFromConfig(sc, rt)
177197
if err := connection.Authenticate(); err != nil {
178198
return nil, errors.Wrap(err, "authentication")
179199
}

providers/swift/swift_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ package swift
55

66
import (
77
"testing"
8+
"time"
89

910
"github.com/efficientgo/core/testutil"
11+
"github.com/prometheus/common/model"
1012
)
1113

1214
func TestParseConfig(t *testing.T) {
@@ -34,3 +36,31 @@ tenant_name: something`)
3436
// Must result in unmarshal error as there's no `tenant_name` in SwiftConfig.
3537
testutil.NotOk(t, err)
3638
}
39+
40+
func TestParseConfig_HTTPConfig(t *testing.T) {
41+
input := []byte(`auth_url: http://identity.something.com/v3
42+
username: thanos
43+
user_domain_name: userDomain
44+
project_name: thanosProject
45+
project_domain_name: projectDomain
46+
http_config:
47+
tls_config:
48+
ca_file: /certs/ca.crt
49+
cert_file: /certs/cert.crt
50+
key_file: /certs/key.key
51+
server_name: server
52+
insecure_skip_verify: false`)
53+
cfg, err := parseConfig([]byte(input))
54+
55+
testutil.Ok(t, err)
56+
57+
testutil.Equals(t, "http://identity.something.com/v3", cfg.AuthUrl)
58+
testutil.Equals(t, "thanos", cfg.Username)
59+
testutil.Equals(t, "userDomain", cfg.UserDomainName)
60+
testutil.Equals(t, "thanosProject", cfg.ProjectName)
61+
testutil.Equals(t, "projectDomain", cfg.ProjectDomainName)
62+
testutil.Equals(t, model.Duration(90*time.Second), cfg.HTTPConfig.IdleConnTimeout)
63+
testutil.Equals(t, model.Duration(2*time.Minute), cfg.HTTPConfig.ResponseHeaderTimeout)
64+
testutil.Equals(t, false, cfg.HTTPConfig.InsecureSkipVerify)
65+
66+
}

0 commit comments

Comments
 (0)