github.com/grafana/pyroscope@v1.18.0/pkg/objstore/providers/cos/bucket_client.go (about)

     1  package cos
     2  
     3  import (
     4  	"github.com/go-kit/log"
     5  	"github.com/prometheus/common/model"
     6  	"github.com/thanos-io/objstore"
     7  	"github.com/thanos-io/objstore/exthttp"
     8  	"github.com/thanos-io/objstore/providers/cos"
     9  	"gopkg.in/yaml.v3"
    10  )
    11  
    12  // NewBucketClient creates a bucket client for COS
    13  func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
    14  	bucketConfig := &cos.Config{
    15  		Bucket:    cfg.Bucket,
    16  		Region:    cfg.Region,
    17  		AppId:     cfg.AppID,
    18  		Endpoint:  cfg.Endpoint,
    19  		SecretKey: cfg.SecretKey.String(),
    20  		SecretId:  cfg.SecretID,
    21  		HTTPConfig: exthttp.HTTPConfig{
    22  			IdleConnTimeout:       model.Duration(cfg.HTTP.IdleConnTimeout),
    23  			ResponseHeaderTimeout: model.Duration(cfg.HTTP.ResponseHeaderTimeout),
    24  			InsecureSkipVerify:    cfg.HTTP.InsecureSkipVerify,
    25  			TLSHandshakeTimeout:   model.Duration(cfg.HTTP.TLSHandshakeTimeout),
    26  			ExpectContinueTimeout: model.Duration(cfg.HTTP.ExpectContinueTimeout),
    27  			MaxIdleConns:          cfg.HTTP.MaxIdleConns,
    28  			MaxIdleConnsPerHost:   cfg.HTTP.MaxIdleConnsPerHost,
    29  			MaxConnsPerHost:       cfg.HTTP.MaxConnsPerHost,
    30  			Transport:             cfg.HTTP.Transport,
    31  		},
    32  	}
    33  
    34  	serializedConfig, err := yaml.Marshal(bucketConfig)
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	return cos.NewBucket(logger, serializedConfig, name, nil)
    40  }