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

feat(thanos): add support for aliyun oss and baidu bos #14891

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/storage/bucket/bos/bucket_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bos

import (
"github.com/go-kit/log"
"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/providers/bos"
)

func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
bosCfg := bos.Config{
Endpoint: cfg.Endpoint,
Bucket: cfg.Bucket,
SecretKey: cfg.SecretKey.String(),
AccessKey: cfg.AccessKey,
}
return bos.NewBucketWithConfig(logger, bosCfg, name)
}
26 changes: 26 additions & 0 deletions pkg/storage/bucket/bos/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package bos

import (
"flag"

"github.com/grafana/dskit/flagext"
)

// Config holds the configuration for Baidu Cloud BOS client
type Config struct {
Bucket string `yaml:"bucket"`
Endpoint string `yaml:"endpoint"`
AccessKey string `yaml:"access_key"`
SecretKey flagext.Secret `yaml:"secret_key"`
}

func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.RegisterFlagsWithPrefix("", f)
}

func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&cfg.Bucket, prefix+"bos.bucket", "", "Name of BOS bucket.")
f.StringVar(&cfg.Endpoint, prefix+"bos.endpoint", "", "BOS endpoint to connect to.")
f.StringVar(&cfg.AccessKey, prefix+"bos.access-key", "", "Baidu Cloud Engine (BCE) Access Key ID.")
f.Var(&cfg.SecretKey, prefix+"bos.secret-key", "Baidu Cloud Engine (BCE) Secret Access Key.")
}
22 changes: 19 additions & 3 deletions pkg/storage/bucket/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
objstoretracing "github.com/thanos-io/objstore/tracing/opentracing"

"github.com/grafana/loki/v3/pkg/storage/bucket/azure"
"github.com/grafana/loki/v3/pkg/storage/bucket/bos"
"github.com/grafana/loki/v3/pkg/storage/bucket/filesystem"
"github.com/grafana/loki/v3/pkg/storage/bucket/gcs"
"github.com/grafana/loki/v3/pkg/storage/bucket/oss"
"github.com/grafana/loki/v3/pkg/storage/bucket/s3"
"github.com/grafana/loki/v3/pkg/storage/bucket/swift"
)
Expand All @@ -36,12 +38,18 @@ const (
// Filesystem is the value for the filesystem storage backend.
Filesystem = "filesystem"

// Alibaba is the value for the Alibaba Cloud OSS storage backend
Alibaba = "alibabacloud"

// BOS is the value for the Baidu Cloud BOS storage backend
BOS = "bos"

// validPrefixCharactersRegex allows only alphanumeric characters to prevent subtle bugs and simplify validation
validPrefixCharactersRegex = `^[\da-zA-Z]+$`
)

var (
SupportedBackends = []string{S3, GCS, Azure, Swift, Filesystem}
SupportedBackends = []string{S3, GCS, Azure, Swift, Filesystem, Alibaba, BOS}

ErrUnsupportedStorageBackend = errors.New("unsupported storage backend")
ErrInvalidCharactersInStoragePrefix = errors.New("storage prefix contains invalid characters, it may only contain digits and English alphabet letters")
Expand All @@ -57,6 +65,8 @@ type StorageBackendConfig struct {
Azure azure.Config `yaml:"azure"`
Swift swift.Config `yaml:"swift"`
Filesystem filesystem.Config `yaml:"filesystem"`
Alibaba oss.Config `yaml:"alibaba"`
BOS bos.Config `yaml:"bos"`

// Used to inject additional backends into the config. Allows for this config to
// be embedded in multiple contexts and support non-object storage based backends.
Expand All @@ -79,6 +89,8 @@ func (cfg *StorageBackendConfig) RegisterFlagsWithPrefixAndDefaultDirectory(pref
cfg.Azure.RegisterFlagsWithPrefix(prefix, f)
cfg.Swift.RegisterFlagsWithPrefix(prefix, f)
cfg.Filesystem.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir, f)
cfg.Alibaba.RegisterFlagsWithPrefix(prefix, f)
cfg.BOS.RegisterFlagsWithPrefix(prefix, f)
}

func (cfg *StorageBackendConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
Expand Down Expand Up @@ -138,7 +150,7 @@ func (cfg *Config) disableRetries(backend string) error {
cfg.Azure.MaxRetries = 1
case Swift:
cfg.Swift.MaxRetries = 1
case Filesystem:
case Filesystem, Alibaba, BOS:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed: with thanos-io/objstore#147 merged we can now define these for these two no? Also fine to do it on a follow up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both bos and oss do not have a any way to configure retries, that's what i gathered from my last search :)

// do nothing
default:
return fmt.Errorf("cannot disable retries for backend: %s", backend)
Expand All @@ -157,7 +169,7 @@ func (cfg *Config) configureTransport(backend string, rt http.RoundTripper) erro
cfg.Azure.Transport = rt
case Swift:
cfg.Swift.Transport = rt
case Filesystem:
case Filesystem, Alibaba, BOS:
// do nothing
default:
return fmt.Errorf("cannot configure transport for backend: %s", backend)
Expand Down Expand Up @@ -185,6 +197,10 @@ func NewClient(ctx context.Context, backend string, cfg Config, name string, log
client, err = swift.NewBucketClient(cfg.Swift, name, logger)
case Filesystem:
client, err = filesystem.NewBucketClient(cfg.Filesystem)
case Alibaba:
client, err = oss.NewBucketClient(cfg.Alibaba, name, logger)
case BOS:
client, err = bos.NewBucketClient(cfg.BOS, name, logger)
default:
return nil, ErrUnsupportedStorageBackend
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/storage/bucket/oss/bucket_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package oss

import (
"github.com/go-kit/log"
"github.com/thanos-io/objstore"
"github.com/thanos-io/objstore/providers/oss"
)

// NewBucketClient creates a new Alibaba Cloud OSS bucket client
func NewBucketClient(cfg Config, component string, logger log.Logger) (objstore.Bucket, error) {
ossCfg := oss.Config{
Endpoint: cfg.Endpoint,
Bucket: cfg.Bucket,
AccessKeyID: cfg.AccessKeyID,
AccessKeySecret: cfg.AccessKeySecret.String(),
}
return oss.NewBucketWithConfig(logger, ossCfg, component, nil)
}
28 changes: 28 additions & 0 deletions pkg/storage/bucket/oss/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package oss

import (
"flag"

"github.com/grafana/dskit/flagext"
)

// Config holds the configuration for Alibaba Cloud OSS client
type Config struct {
Endpoint string `yaml:"endpoint"`
Bucket string `yaml:"bucket"`
AccessKeyID string `yaml:"access_key_id"`
AccessKeySecret flagext.Secret `yaml:"access_key_secret"`
}

// RegisterFlags registers the flags for Alibaba Cloud OSS storage config
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
cfg.RegisterFlagsWithPrefix("", f)
}

// RegisterFlagsWithPrefix registers the flags for Alibaba Cloud OSS storage config with prefix
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.StringVar(&cfg.Bucket, prefix+"oss.bucketname", "", "Name of OSS bucket.")
f.StringVar(&cfg.Endpoint, prefix+"oss.endpoint", "", "Endpoint to connect to.")
f.StringVar(&cfg.AccessKeyID, prefix+"oss.access-key-id", "", "alibabacloud Access Key ID")
f.Var(&cfg.AccessKeySecret, prefix+"oss.access-key-secret", "alibabacloud Secret Access Key")
}
65 changes: 65 additions & 0 deletions vendor/github.com/thanos-io/objstore/clientutil/parse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading