github.com/grafana/pyroscope@v1.18.0/pkg/objstore/providers/gcs/config.go (about) 1 // SPDX-License-Identifier: AGPL-3.0-only 2 // Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/storage/bucket/gcs/config.go 3 // Provenance-includes-license: Apache-2.0 4 // Provenance-includes-copyright: The Cortex Authors. 5 6 package gcs 7 8 import ( 9 "flag" 10 "time" 11 12 "github.com/grafana/dskit/flagext" 13 ) 14 15 // Config holds the config options for GCS backend 16 type Config struct { 17 BucketName string `yaml:"bucket_name"` 18 ServiceAccount flagext.Secret `yaml:"service_account" doc:"description_method=GCSServiceAccountLongDescription"` 19 HTTP HTTPConfig `yaml:"http"` 20 } 21 22 // RegisterFlags registers the flags for GCS storage 23 func (cfg *Config) RegisterFlags(f *flag.FlagSet) { 24 cfg.RegisterFlagsWithPrefix("", f) 25 } 26 27 // RegisterFlagsWithPrefix registers the flags for GCS storage with the provided prefix 28 func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { 29 f.StringVar(&cfg.BucketName, prefix+"gcs.bucket-name", "", "GCS bucket name") 30 f.Var(&cfg.ServiceAccount, prefix+"gcs.service-account", cfg.GCSServiceAccountShortDescription()) 31 cfg.HTTP.RegisterFlagsWithPrefix(prefix, f) 32 } 33 34 type HTTPConfig struct { 35 IdleConnTimeout time.Duration `yaml:"idle_conn_timeout" category:"advanced"` 36 ResponseHeaderTimeout time.Duration `yaml:"response_header_timeout" category:"advanced"` 37 InsecureSkipVerify bool `yaml:"insecure_skip_verify" category:"advanced"` 38 TLSHandshakeTimeout time.Duration `yaml:"tls_handshake_timeout" category:"advanced"` 39 ExpectContinueTimeout time.Duration `yaml:"expect_continue_timeout" category:"advanced"` 40 MaxIdleConns int `yaml:"max_idle_conns" category:"advanced"` 41 MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host" category:"advanced"` 42 MaxConnsPerHost int `yaml:"max_conns_per_host" category:"advanced"` 43 } 44 45 // RegisterFlagsWithPrefix registers the flags for s3 storage with the provided prefix 46 func (cfg *HTTPConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { 47 f.DurationVar(&cfg.IdleConnTimeout, prefix+"gcs.http.idle-conn-timeout", 90*time.Second, "The time an idle connection will remain idle before closing.") 48 f.DurationVar(&cfg.ResponseHeaderTimeout, prefix+"gcs.http.response-header-timeout", 2*time.Minute, "The amount of time the client will wait for a servers response headers.") 49 f.BoolVar(&cfg.InsecureSkipVerify, prefix+"gcs.http.insecure-skip-verify", false, "If the client connects to GCS via HTTPS and this option is enabled, the client will accept any certificate and hostname.") 50 f.DurationVar(&cfg.TLSHandshakeTimeout, prefix+"gcs.tls-handshake-timeout", 10*time.Second, "Maximum time to wait for a TLS handshake. 0 means no limit.") 51 f.DurationVar(&cfg.ExpectContinueTimeout, prefix+"gcs.expect-continue-timeout", 1*time.Second, "The time to wait for a server's first response headers after fully writing the request headers if the request has an Expect header. 0 to send the request body immediately.") 52 f.IntVar(&cfg.MaxIdleConns, prefix+"gcs.max-idle-connections", 0, "Maximum number of idle (keep-alive) connections across all hosts. 0 means no limit.") 53 f.IntVar(&cfg.MaxIdleConnsPerHost, prefix+"gcs.max-idle-connections-per-host", 100, "Maximum number of idle (keep-alive) connections to keep per-host. If 0, a built-in default value is used.") 54 f.IntVar(&cfg.MaxConnsPerHost, prefix+"gcs.max-connections-per-host", 0, "Maximum number of connections per host. 0 means no limit.") 55 } 56 57 func (cfg *Config) GCSServiceAccountShortDescription() string { 58 return "JSON either from a Google Developers Console client_credentials.json file, or a Google Developers service account key. Needs to be valid JSON, not a filesystem path." 59 } 60 61 func (cfg *Config) GCSServiceAccountLongDescription() string { 62 return cfg.GCSServiceAccountShortDescription() + 63 " If empty, fallback to Google default logic:" + 64 "\n1. A JSON file whose path is specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable. For workload identity federation, refer to https://cloud.google.com/iam/docs/how-to#using-workload-identity-federation on how to generate the JSON configuration file for on-prem/non-Google cloud platforms." + 65 "\n2. A JSON file in a location known to the gcloud command-line tool: $HOME/.config/gcloud/application_default_credentials.json." + 66 "\n3. On Google Compute Engine it fetches credentials from the metadata server." 67 }