Skip to content

Commit 3d0ae4e

Browse files
committed
chore: add GCS HTTP config
1 parent f0cd146 commit 3d0ae4e

File tree

5 files changed

+96
-18
lines changed

5 files changed

+96
-18
lines changed

Diff for: docs/sources/configure-server/reference-configuration-parameters/index.md

+38
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,44 @@ The gcs_backend block configures the connection to Google Cloud Storage object s
23562356
# 3. On Google Compute Engine it fetches credentials from the metadata server.
23572357
# CLI flag: -storage.gcs.service-account
23582358
[service_account: <string> | default = ""]
2359+
2360+
http:
2361+
# The time an idle connection will remain idle before closing.
2362+
# CLI flag: -storage.gcs.http.idle-conn-timeout
2363+
[idle_conn_timeout: <duration> | default = 1m30s]
2364+
2365+
# The amount of time the client will wait for a servers response headers.
2366+
# CLI flag: -storage.gcs.http.response-header-timeout
2367+
[response_header_timeout: <duration> | default = 2m]
2368+
2369+
# If the client connects to GCS via HTTPS and this option is enabled, the
2370+
# client will accept any certificate and hostname.
2371+
# CLI flag: -storage.gcs.http.insecure-skip-verify
2372+
[insecure_skip_verify: <boolean> | default = false]
2373+
2374+
# Maximum time to wait for a TLS handshake. 0 means no limit.
2375+
# CLI flag: -storage.gcs.tls-handshake-timeout
2376+
[tls_handshake_timeout: <duration> | default = 10s]
2377+
2378+
# The time to wait for a server's first response headers after fully writing
2379+
# the request headers if the request has an Expect header. 0 to send the
2380+
# request body immediately.
2381+
# CLI flag: -storage.gcs.expect-continue-timeout
2382+
[expect_continue_timeout: <duration> | default = 1s]
2383+
2384+
# Maximum number of idle (keep-alive) connections across all hosts. 0 means no
2385+
# limit.
2386+
# CLI flag: -storage.gcs.max-idle-connections
2387+
[max_idle_conns: <int> | default = 0]
2388+
2389+
# Maximum number of idle (keep-alive) connections to keep per-host. If 0, a
2390+
# built-in default value is used.
2391+
# CLI flag: -storage.gcs.max-idle-connections-per-host
2392+
[max_idle_conns_per_host: <int> | default = 100]
2393+
2394+
# Maximum number of connections per host. 0 means no limit.
2395+
# CLI flag: -storage.gcs.max-connections-per-host
2396+
[max_conns_per_host: <int> | default = 0]
23592397
```
23602398
23612399
### azure_storage_backend

Diff for: pkg/objstore/client/config.go

+11-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"regexp"
88
"strings"
99

10-
"github.com/go-kit/log"
1110
"github.com/samber/lo"
1211
"github.com/thanos-io/objstore"
1312

@@ -70,11 +69,11 @@ func (cfg *StorageBackendConfig) supportedBackends() []string {
7069
}
7170

7271
// RegisterFlags registers the backend storage config.
73-
func (cfg *StorageBackendConfig) RegisterFlags(f *flag.FlagSet, logger log.Logger) {
74-
cfg.RegisterFlagsWithPrefix("", f, logger)
72+
func (cfg *StorageBackendConfig) RegisterFlags(f *flag.FlagSet) {
73+
cfg.RegisterFlagsWithPrefix("", f)
7574
}
7675

77-
func (cfg *StorageBackendConfig) RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir string, f *flag.FlagSet, logger log.Logger) {
76+
func (cfg *StorageBackendConfig) RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir string, f *flag.FlagSet) {
7877
cfg.S3.RegisterFlagsWithPrefix(prefix, f)
7978
cfg.GCS.RegisterFlagsWithPrefix(prefix, f)
8079
cfg.Azure.RegisterFlagsWithPrefix(prefix, f)
@@ -84,8 +83,8 @@ func (cfg *StorageBackendConfig) RegisterFlagsWithPrefixAndDefaultDirectory(pref
8483
f.StringVar(&cfg.Backend, prefix+"backend", None, fmt.Sprintf("Backend storage to use. Supported backends are: %s.", strings.Join(cfg.supportedBackends(), ", ")))
8584
}
8685

87-
func (cfg *StorageBackendConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet, logger log.Logger) {
88-
cfg.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, "", f, logger)
86+
func (cfg *StorageBackendConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
87+
cfg.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, "", f)
8988
}
9089

9190
func (cfg *StorageBackendConfig) Validate() error {
@@ -119,17 +118,17 @@ type Config struct {
119118
}
120119

121120
// RegisterFlags registers the backend storage config.
122-
func (cfg *Config) RegisterFlags(f *flag.FlagSet, logger log.Logger) {
123-
cfg.RegisterFlagsWithPrefix("", f, logger)
121+
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
122+
cfg.RegisterFlagsWithPrefix("", f)
124123
}
125124

126-
func (cfg *Config) RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir string, f *flag.FlagSet, logger log.Logger) {
127-
cfg.StorageBackendConfig.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir, f, logger)
125+
func (cfg *Config) RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir string, f *flag.FlagSet) {
126+
cfg.StorageBackendConfig.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir, f)
128127
f.StringVar(&cfg.StoragePrefix, prefix+"storage-prefix", "", "Prefix for all objects stored in the backend storage. For simplicity, it may only contain digits and English alphabet letters.")
129128
}
130129

131-
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet, logger log.Logger) {
132-
cfg.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, "./data-shared", f, logger)
130+
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
131+
cfg.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, "./data-shared", f)
133132
}
134133

135134
func (cfg *Config) Validate() error {

Diff for: pkg/objstore/providers/gcs/bucket_client.go

+12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"context"
1010

1111
"github.com/go-kit/log"
12+
"github.com/prometheus/common/model"
1213
"github.com/thanos-io/objstore"
14+
"github.com/thanos-io/objstore/exthttp"
1315
"github.com/thanos-io/objstore/providers/gcs"
1416
"gopkg.in/yaml.v3"
1517
)
@@ -19,6 +21,16 @@ func NewBucketClient(ctx context.Context, cfg Config, name string, logger log.Lo
1921
bucketConfig := gcs.Config{
2022
Bucket: cfg.BucketName,
2123
ServiceAccount: cfg.ServiceAccount.String(),
24+
HTTPConfig: exthttp.HTTPConfig{
25+
IdleConnTimeout: model.Duration(cfg.HTTP.IdleConnTimeout),
26+
ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
27+
InsecureSkipVerify: cfg.HTTP.InsecureSkipVerify,
28+
TLSHandshakeTimeout: model.Duration(cfg.HTTP.TLSHandshakeTimeout),
29+
ExpectContinueTimeout: model.Duration(cfg.HTTP.ExpectContinueTimeout),
30+
MaxIdleConns: cfg.HTTP.MaxIdleConns,
31+
MaxIdleConnsPerHost: cfg.HTTP.MaxIdleConnsPerHost,
32+
MaxConnsPerHost: cfg.HTTP.MaxConnsPerHost,
33+
},
2234
}
2335

2436
// Thanos currently doesn't support passing the config as is, but expects a YAML,

Diff for: pkg/objstore/providers/gcs/config.go

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package gcs
77

88
import (
99
"flag"
10+
"time"
1011

1112
"github.com/grafana/dskit/flagext"
1213
)
@@ -15,6 +16,7 @@ import (
1516
type Config struct {
1617
BucketName string `yaml:"bucket_name"`
1718
ServiceAccount flagext.Secret `yaml:"service_account" doc:"description_method=GCSServiceAccountLongDescription"`
19+
HTTP HTTPConfig `yaml:"http"`
1820
}
1921

2022
// RegisterFlags registers the flags for GCS storage
@@ -26,6 +28,30 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
2628
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
2729
f.StringVar(&cfg.BucketName, prefix+"gcs.bucket-name", "", "GCS bucket name")
2830
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"`
36+
ResponseHeaderTimeout time.Duration `yaml:"response_header_timeout"`
37+
InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
38+
TLSHandshakeTimeout time.Duration `yaml:"tls_handshake_timeout"`
39+
ExpectContinueTimeout time.Duration `yaml:"expect_continue_timeout"`
40+
MaxIdleConns int `yaml:"max_idle_conns"`
41+
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
42+
MaxConnsPerHost int `yaml:"max_conns_per_host"`
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.")
2955
}
3056

3157
func (cfg *Config) GCSServiceAccountShortDescription() string {

Diff for: pkg/phlare/phlare.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import (
6161
phlareobj "github.com/grafana/pyroscope/pkg/objstore"
6262
objstoreclient "github.com/grafana/pyroscope/pkg/objstore/client"
6363
"github.com/grafana/pyroscope/pkg/operations"
64-
phlarecontext "github.com/grafana/pyroscope/pkg/phlare/context"
6564
"github.com/grafana/pyroscope/pkg/phlaredb"
6665
"github.com/grafana/pyroscope/pkg/querier"
6766
"github.com/grafana/pyroscope/pkg/querier/worker"
@@ -131,8 +130,8 @@ type StorageConfig struct {
131130
Bucket objstoreclient.Config `yaml:",inline"`
132131
}
133132

134-
func (c *StorageConfig) RegisterFlagsWithContext(ctx context.Context, f *flag.FlagSet) {
135-
c.Bucket.RegisterFlagsWithPrefix("storage.", f, phlarecontext.Logger(ctx))
133+
func (c *StorageConfig) RegisterFlags(f *flag.FlagSet) {
134+
c.Bucket.RegisterFlagsWithPrefix("storage.", f)
136135
}
137136

138137
type SelfProfilingConfig struct {
@@ -161,11 +160,11 @@ func (c *SelfProfilingConfig) RegisterFlags(f *flag.FlagSet) {
161160
}
162161

163162
func (c *Config) RegisterFlags(f *flag.FlagSet) {
164-
c.RegisterFlagsWithContext(context.Background(), f)
163+
c.RegisterFlagsWithContext(f)
165164
}
166165

167166
// RegisterFlagsWithContext registers flag.
168-
func (c *Config) RegisterFlagsWithContext(ctx context.Context, f *flag.FlagSet) {
167+
func (c *Config) RegisterFlagsWithContext(f *flag.FlagSet) {
169168
// Set the default module list to 'all'
170169
c.Target = []string{All}
171170
f.StringVar(&c.ConfigFile, "config.file", "", "yaml file to load")
@@ -191,7 +190,6 @@ func (c *Config) RegisterFlagsWithContext(ctx context.Context, f *flag.FlagSet)
191190
c.StoreGateway.RegisterFlags(f, util.Logger)
192191
c.PhlareDB.RegisterFlags(f)
193192
c.Tracing.RegisterFlags(f)
194-
c.Storage.RegisterFlagsWithContext(ctx, f)
195193
c.SelfProfiling.RegisterFlags(f)
196194
c.RuntimeConfig.RegisterFlags(f)
197195
c.Analytics.RegisterFlags(f)
@@ -208,6 +206,7 @@ func (c *Config) registerServerFlagsWithChangedDefaultValues(fs *flag.FlagSet) {
208206

209207
// Register to throwaway flags first. Default values are remembered during registration and cannot be changed,
210208
// but we can take values from throwaway flag set and reregister into supplied flags with new default values.
209+
c.Storage.RegisterFlags(throwaway)
211210
c.Server.RegisterFlags(throwaway)
212211
c.Ingester.RegisterFlags(throwaway)
213212
c.Distributor.RegisterFlags(throwaway, log.NewLogfmtLogger(os.Stderr))
@@ -233,6 +232,10 @@ func (c *Config) registerServerFlagsWithChangedDefaultValues(fs *flag.FlagSet) {
233232
"segment-writer.heartbeat-timeout": "1m",
234233
"segment-writer.unregister-on-shutdown": "false",
235234
"segment-writer.min-ready-duration": "30s",
235+
// "storage.s3.http.idle-conn-timeout": "10m",
236+
// "storage.s3.max-idle-connections-per-host": "1000",
237+
"storage.gcs.http.idle-conn-timeout": "10m",
238+
"storage.gcs.max-idle-connections-per-host": "1000",
236239
} {
237240
overrides[k] = v
238241
}

0 commit comments

Comments
 (0)