Skip to content

Commit

Permalink
feat: add a config option for custom GCS endpoints (#16419)
Browse files Browse the repository at this point in the history
(cherry picked from commit f1ebd97)
  • Loading branch information
na-- authored and grafana-delivery-bot[bot] committed Feb 24, 2025
1 parent 0d84681 commit 9769904
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,10 @@ The `gcs_storage_config` block configures the connection to Google Cloud Storage
# CLI flag: -<prefix>.gcs.bucketname
[bucket_name: <string> | default = ""]
# Custom GCS endpoint URL.
# CLI flag: -<prefix>.gcs.endpoint
[endpoint: <string> | default = ""]
# Service account key content in JSON format, refer to
# https://cloud.google.com/iam/docs/creating-managing-service-account-keys for
# creation.
Expand Down
6 changes: 6 additions & 0 deletions pkg/storage/chunk/client/gcp/gcs_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type GCSObjectClient struct {
// GCSConfig is config for the GCS Chunk Client.
type GCSConfig struct {
BucketName string `yaml:"bucket_name"`
Endpoint string `yaml:"endpoint"`
ServiceAccount flagext.Secret `yaml:"service_account"`
ChunkBufferSize int `yaml:"chunk_buffer_size"`
RequestTimeout time.Duration `yaml:"request_timeout"`
Expand All @@ -57,6 +58,7 @@ func (cfg *GCSConfig) RegisterFlags(f *flag.FlagSet) {
// RegisterFlagsWithPrefix registers flags with prefix.
func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&cfg.BucketName, prefix+"gcs.bucketname", "", "Name of GCS bucket. Please refer to https://cloud.google.com/docs/authentication/production for more information about how to configure authentication.")
f.StringVar(&cfg.Endpoint, prefix+"gcs.endpoint", "", "Custom GCS endpoint URL.")
f.Var(&cfg.ServiceAccount, prefix+"gcs.service-account", "Service account key content in JSON format, refer to https://cloud.google.com/iam/docs/creating-managing-service-account-keys for creation.")
f.IntVar(&cfg.ChunkBufferSize, prefix+"gcs.chunk-buffer-size", 0, "The size of the buffer that GCS client for each PUT request. 0 to disable buffering.")
f.DurationVar(&cfg.RequestTimeout, prefix+"gcs.request-timeout", 0, "The duration after which the requests to GCS should be timed out.")
Expand Down Expand Up @@ -109,6 +111,10 @@ func newBucketHandle(ctx context.Context, cfg GCSConfig, hedgingCfg hedging.Conf
opts = append(opts, option.WithTelemetryDisabled())
}

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

client, err := clientFactory(ctx, opts...)
if err != nil {
return nil, err
Expand Down

0 comments on commit 9769904

Please sign in to comment.