Skip to content

Commit 9f421f2

Browse files
authored
Merge pull request #92 from fpetkovski/gcs-grpc-client
Enable using gRPC client for GCS
2 parents bffedaa + a70cbf6 commit 9f421f2

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
3636
- [#51](https://github.com/thanos-io/objstore/pull/51) Azure: Support using connection string authentication.
3737
- [#76](https://github.com/thanos-io/objstore/pull/76) GCS: Query for object names only in `Iter` to possibly improve performance when listing objects.
3838
- [#85](https://github.com/thanos-io/objstore/pull/85) S3: Allow checksum algorithm to be configured
39+
- [#92](https://github.com/thanos-io/objstore/pull/92) GCS: Allow using a gRPC client.
3940

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

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ type: GCS
352352
config:
353353
bucket: ""
354354
service_account: ""
355+
use_grpc: false
356+
grpc_conn_pool_size: 0
355357
prefix: ""
356358
```
357359

providers/gcs/gcs.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"golang.org/x/oauth2/google"
2020
"google.golang.org/api/iterator"
2121
"google.golang.org/api/option"
22+
"google.golang.org/grpc"
2223
"google.golang.org/grpc/codes"
2324
"google.golang.org/grpc/status"
2425
"gopkg.in/yaml.v2"
@@ -33,6 +34,12 @@ const DirDelim = "/"
3334
type Config struct {
3435
Bucket string `yaml:"bucket"`
3536
ServiceAccount string `yaml:"service_account"`
37+
UseGRPC bool `yaml:"use_grpc"`
38+
// GRPCConnPoolSize controls the size of the gRPC connection pool and should only be used
39+
// when direct path is not enabled.
40+
// See https://pkg.go.dev/cloud.google.com/go/storage#hdr-Experimental_gRPC_API for more details
41+
// on how to enable direct path.
42+
GRPCConnPoolSize int `yaml:"grpc_conn_pool_size"`
3643
}
3744

3845
// Bucket implements the store.Bucket and shipper.Bucket interfaces against GCS.
@@ -75,7 +82,23 @@ func NewBucketWithConfig(ctx context.Context, logger log.Logger, gc Config, comp
7582
option.WithUserAgent(fmt.Sprintf("thanos-%s/%s (%s)", component, version.Version, runtime.Version())),
7683
)
7784

78-
gcsClient, err := storage.NewClient(ctx, opts...)
85+
return newBucket(ctx, logger, gc, opts)
86+
}
87+
88+
func newBucket(ctx context.Context, logger log.Logger, gc Config, opts []option.ClientOption) (*Bucket, error) {
89+
var (
90+
err error
91+
gcsClient *storage.Client
92+
)
93+
if gc.UseGRPC {
94+
opts = append(opts,
95+
option.WithGRPCDialOption(grpc.WithRecvBufferPool(grpc.NewSharedBufferPool())),
96+
option.WithGRPCConnectionPool(gc.GRPCConnPoolSize),
97+
)
98+
gcsClient, err = storage.NewGRPCClient(ctx, opts...)
99+
} else {
100+
gcsClient, err = storage.NewClient(ctx, opts...)
101+
}
79102
if err != nil {
80103
return nil, err
81104
}

0 commit comments

Comments
 (0)