Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable http2 for GCS. #4942

Merged
merged 10 commits into from
Jan 3, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [4892](https://github.com/grafana/loki/pull/4892) **cristaloleg**: Loki: upgrade cristalhq/hedgedhttp from v0.6.0 to v0.7.0
* [4902](https://github.com/grafana/loki/pull/4902) **cyriltovena**: Fixes 500 when query is outside of max_query_lookback.
* [4904](https://github.com/grafana/loki/pull/4904) **bboreham**: Fixes rare race condition that could crash an ingester.
* [4942](https://github.com/grafana/loki/pull/4942) **cyriltovena**: Allow to disable http2 for GCS.
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved

# 2.4.1 (2021/11/07)

Expand Down
4 changes: 4 additions & 0 deletions docs/sources/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ The `gcs_storage_config` configures GCS as a general storage for different data
# The duration after which the requests to GCS should be timed out.
# CLI flag: -<prefix>.gcs.request-timeout
[request_timeout: <duration> | default = 0s]

# Enable http2 when connecting to GCS.
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
# CLI flag: -<prefix>.gcs.enable-http2
[enable_http2: <bool> | default = true]
```

## s3_storage_config
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/chunk/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ func buildS3Client(cfg S3Config, hedgingCfg hedging.Config, hedging bool) (*s3.S
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
MaxIdleConns: 512,
IdleConnTimeout: cfg.HTTPConfig.IdleConnTimeout,
MaxIdleConnsPerHost: 100,
MaxIdleConnsPerHost: 256,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ResponseHeaderTimeout: cfg.HTTPConfig.ResponseHeaderTimeout,
Expand Down
6 changes: 2 additions & 4 deletions pkg/storage/chunk/azure/blob_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ var (
KeepAlive: 30 * time.Second,
DualStack: true,
}).Dial,
MaxIdleConns: 0,
MaxIdleConnsPerHost: 100,
MaxIdleConns: 512,
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
MaxIdleConnsPerHost: 256,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
Expand Down Expand Up @@ -292,7 +292,6 @@ func (b *BlobStorage) newPipeline(hedgingCfg hedging.Config, hedging bool) (pipe
}

return azblob.NewPipeline(*tokenCredential, opts), nil

}

func (b *BlobStorage) getOAuthToken() (*azblob.TokenCredential, error) {
Expand Down Expand Up @@ -331,7 +330,6 @@ func (b *BlobStorage) fetchMSIToken() (*adal.ServicePrincipalToken, error) {

// both can be empty, systemAssignedMSI scenario
spt, err := adal.NewServicePrincipalTokenFromMSI(msiEndpoint, "https://storage.azure.com/")

if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/chunk/gcp/gcs_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type GCSConfig struct {
ChunkBufferSize int `yaml:"chunk_buffer_size"`
RequestTimeout time.Duration `yaml:"request_timeout"`
EnableOpenCensus bool `yaml:"enable_opencensus"`
EnableHTTP2 bool `yaml:"enable_http2"`

Insecure bool `yaml:"-"`
}
Expand All @@ -48,6 +49,7 @@ func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
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.")
f.BoolVar(&cfg.EnableOpenCensus, prefix+"gcs.enable-opencensus", true, "Enabled OpenCensus (OC) instrumentation for all requests.")
f.BoolVar(&cfg.EnableHTTP2, prefix+"gcs.enable-http2", true, "Enabled HTTP2 connections.")
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
}

func (cfg *GCSConfig) ToCortexGCSConfig() cortex_gcp.GCSConfig {
Expand Down Expand Up @@ -82,7 +84,7 @@ func newGCSObjectClient(ctx context.Context, cfg GCSConfig, hedgingCfg hedging.C

func newBucketHandle(ctx context.Context, cfg GCSConfig, hedgingCfg hedging.Config, hedging bool, clientFactory ClientFactory) (*storage.BucketHandle, error) {
var opts []option.ClientOption
httpClient, err := gcsInstrumentation(ctx, storage.ScopeReadWrite, cfg.Insecure)
httpClient, err := gcsInstrumentation(ctx, storage.ScopeReadWrite, cfg.Insecure, cfg.EnableHTTP2)
if err != nil {
return nil, err
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/storage/chunk/gcp/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ func bigtableInstrumentation() ([]grpc.UnaryClientInterceptor, []grpc.StreamClie
}
}

func gcsInstrumentation(ctx context.Context, scope string, insecure bool) (*http.Client, error) {
func gcsInstrumentation(ctx context.Context, scope string, insecure bool, http2 bool) (*http.Client, error) {
// start with default transport
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.MaxIdleConnsPerHost = 256
customTransport.MaxIdleConns = 512
if !http2 {
// disable HTTP/2 by setting TLSNextProto to non-nil empty map, as per the net/http documentation.
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved
customTransport.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)
}
if insecure {
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/chunk/openstack/swift_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import (

var defaultTransport http.RoundTripper = &http.Transport{
Proxy: http.ProxyFromEnvironment,
MaxIdleConnsPerHost: 512,
MaxIdleConnsPerHost: 256,
MaxIdleConns: 512,
ExpectContinueTimeout: 5 * time.Second,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/chunk/util/parallel_chunk_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/grafana/loki/pkg/storage/chunk"
)

const maxParallel = 1000
const maxParallel = 150
cyriltovena marked this conversation as resolved.
Show resolved Hide resolved

var decodeContextPool = sync.Pool{
New: func() interface{} {
Expand Down