Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ config:
disable_compression: false
chunk_size_bytes: 0
max_retries: 0
endpoint: ""
prefix: ""
```

Expand Down
9 changes: 9 additions & 0 deletions providers/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type Config struct {
// Overrides the default gcs storage client behavior if this value is greater than 0.
// Set this to 1 to disable retries.
MaxRetries int `yaml:"max_retries"`

// Endpoint specifies the GCS API endpoint to use.
// This can be used to point to GCS regional endpoints or GCS-compatible storage backends.
// See https://cloud.google.com/storage/docs/regional-endpoints for more details.
Endpoint string `yaml:"endpoint"`
}

// Bucket implements the store.Bucket and shipper.Bucket interfaces against GCS.
Expand Down Expand Up @@ -113,6 +118,10 @@ func NewBucketWithConfig(ctx context.Context, logger log.Logger, gc Config, comp
option.WithUserAgent(fmt.Sprintf("thanos-%s/%s (%s)", component, version.Version, runtime.Version())),
)

if gc.Endpoint != "" {
opts = append(opts, option.WithEndpoint(gc.Endpoint))
}

if !gc.UseGRPC {
var err error
opts, err = appendHttpOptions(gc, opts, wrapRoundtripper)
Expand Down
49 changes: 49 additions & 0 deletions providers/gcs/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,55 @@ http_config:
}
}

func TestParseConfig_Endpoint(t *testing.T) {
for _, tc := range []struct {
name string
input string
assertions func(cfg Config)
}{
{
name: "DefaultEndpoint",
input: `bucket: abcd`,
assertions: func(cfg Config) {
testutil.Equals(t, "", cfg.Endpoint)
},
},
{
name: "CustomEndpoint",
input: `bucket: abcd
endpoint: https://storage.europe-west3.rep.googleapis.com`,
assertions: func(cfg Config) {
testutil.Equals(t, "https://storage.europe-west3.rep.googleapis.com", cfg.Endpoint)
},
},
} {
t.Run(tc.name, func(t *testing.T) {
cfg, err := parseConfig([]byte(tc.input))
testutil.Ok(t, err)
tc.assertions(cfg)
})
}
}

func TestNewBucketWithConfig_CustomEndpoint(t *testing.T) {
svr, err := gcsemu.NewServer("127.0.0.1:0", gcsemu.Options{})
testutil.Ok(t, err)
defer svr.Close()

err = os.Setenv("STORAGE_EMULATOR_HOST", svr.Addr)
testutil.Ok(t, err)

cfg := Config{
Bucket: "test-bucket",
Endpoint: "https://storage.europe-west3.rep.googleapis.com",
noAuth: true,
}

bkt, err := NewBucketWithConfig(context.Background(), log.NewNopLogger(), cfg, "test", nil)
testutil.Ok(t, err)
testutil.Assert(t, bkt != nil, "expected bucket to be created with custom endpoint")
}

func TestNewBucketWithErrorRoundTripper(t *testing.T) {
cfg := Config{
Bucket: "test-bucket",
Expand Down
Loading