Skip to content

Commit fb6789d

Browse files
authored
feat(thanos): add support for aliyun oss and baidu bos (#14891)
1 parent a629212 commit fb6789d

File tree

9 files changed

+1042
-3
lines changed

9 files changed

+1042
-3
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package bos
2+
3+
import (
4+
"github.com/go-kit/log"
5+
"github.com/thanos-io/objstore"
6+
"github.com/thanos-io/objstore/providers/bos"
7+
)
8+
9+
func NewBucketClient(cfg Config, name string, logger log.Logger) (objstore.Bucket, error) {
10+
bosCfg := bos.Config{
11+
Endpoint: cfg.Endpoint,
12+
Bucket: cfg.Bucket,
13+
SecretKey: cfg.SecretKey.String(),
14+
AccessKey: cfg.AccessKey,
15+
}
16+
return bos.NewBucketWithConfig(logger, bosCfg, name)
17+
}

‎pkg/storage/bucket/bos/config.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package bos
2+
3+
import (
4+
"flag"
5+
6+
"github.com/grafana/dskit/flagext"
7+
)
8+
9+
// Config holds the configuration for Baidu Cloud BOS client
10+
type Config struct {
11+
Bucket string `yaml:"bucket"`
12+
Endpoint string `yaml:"endpoint"`
13+
AccessKey string `yaml:"access_key"`
14+
SecretKey flagext.Secret `yaml:"secret_key"`
15+
}
16+
17+
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
18+
cfg.RegisterFlagsWithPrefix("", f)
19+
}
20+
21+
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
22+
f.StringVar(&cfg.Bucket, prefix+"bos.bucket", "", "Name of BOS bucket.")
23+
f.StringVar(&cfg.Endpoint, prefix+"bos.endpoint", "", "BOS endpoint to connect to.")
24+
f.StringVar(&cfg.AccessKey, prefix+"bos.access-key", "", "Baidu Cloud Engine (BCE) Access Key ID.")
25+
f.Var(&cfg.SecretKey, prefix+"bos.secret-key", "Baidu Cloud Engine (BCE) Secret Access Key.")
26+
}

‎pkg/storage/bucket/client.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ import (
1515
objstoretracing "github.com/thanos-io/objstore/tracing/opentracing"
1616

1717
"github.com/grafana/loki/v3/pkg/storage/bucket/azure"
18+
"github.com/grafana/loki/v3/pkg/storage/bucket/bos"
1819
"github.com/grafana/loki/v3/pkg/storage/bucket/filesystem"
1920
"github.com/grafana/loki/v3/pkg/storage/bucket/gcs"
21+
"github.com/grafana/loki/v3/pkg/storage/bucket/oss"
2022
"github.com/grafana/loki/v3/pkg/storage/bucket/s3"
2123
"github.com/grafana/loki/v3/pkg/storage/bucket/swift"
2224
)
@@ -37,12 +39,18 @@ const (
3739
// Filesystem is the value for the filesystem storage backend.
3840
Filesystem = "filesystem"
3941

42+
// Alibaba is the value for the Alibaba Cloud OSS storage backend
43+
Alibaba = "alibabacloud"
44+
45+
// BOS is the value for the Baidu Cloud BOS storage backend
46+
BOS = "bos"
47+
4048
// validPrefixCharactersRegex allows only alphanumeric characters to prevent subtle bugs and simplify validation
4149
validPrefixCharactersRegex = `^[\da-zA-Z]+$`
4250
)
4351

4452
var (
45-
SupportedBackends = []string{S3, GCS, Azure, Swift, Filesystem}
53+
SupportedBackends = []string{S3, GCS, Azure, Swift, Filesystem, Alibaba, BOS}
4654

4755
ErrUnsupportedStorageBackend = errors.New("unsupported storage backend")
4856
ErrInvalidCharactersInStoragePrefix = errors.New("storage prefix contains invalid characters, it may only contain digits and English alphabet letters")
@@ -73,6 +81,8 @@ type StorageBackendConfig struct {
7381
Azure azure.Config `yaml:"azure"`
7482
Swift swift.Config `yaml:"swift"`
7583
Filesystem filesystem.Config `yaml:"filesystem"`
84+
Alibaba oss.Config `yaml:"alibaba"`
85+
BOS bos.Config `yaml:"bos"`
7686

7787
// Used to inject additional backends into the config. Allows for this config to
7888
// be embedded in multiple contexts and support non-object storage based backends.
@@ -95,6 +105,8 @@ func (cfg *StorageBackendConfig) RegisterFlagsWithPrefixAndDefaultDirectory(pref
95105
cfg.Azure.RegisterFlagsWithPrefix(prefix, f)
96106
cfg.Swift.RegisterFlagsWithPrefix(prefix, f)
97107
cfg.Filesystem.RegisterFlagsWithPrefixAndDefaultDirectory(prefix, dir, f)
108+
cfg.Alibaba.RegisterFlagsWithPrefix(prefix, f)
109+
cfg.BOS.RegisterFlagsWithPrefix(prefix, f)
98110
}
99111

100112
func (cfg *StorageBackendConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
@@ -154,7 +166,7 @@ func (cfg *Config) disableRetries(backend string) error {
154166
cfg.Azure.MaxRetries = 1
155167
case Swift:
156168
cfg.Swift.MaxRetries = 1
157-
case Filesystem:
169+
case Filesystem, Alibaba, BOS:
158170
// do nothing
159171
default:
160172
return fmt.Errorf("cannot disable retries for backend: %s", backend)
@@ -173,7 +185,7 @@ func (cfg *Config) configureTransport(backend string, rt http.RoundTripper) erro
173185
cfg.Azure.Transport = rt
174186
case Swift:
175187
cfg.Swift.Transport = rt
176-
case Filesystem:
188+
case Filesystem, Alibaba, BOS:
177189
// do nothing
178190
default:
179191
return fmt.Errorf("cannot configure transport for backend: %s", backend)
@@ -201,6 +213,10 @@ func NewClient(ctx context.Context, backend string, cfg Config, name string, log
201213
client, err = swift.NewBucketClient(cfg.Swift, name, logger, instrumentTransport())
202214
case Filesystem:
203215
client, err = filesystem.NewBucketClient(cfg.Filesystem)
216+
case Alibaba:
217+
client, err = oss.NewBucketClient(cfg.Alibaba, name, logger)
218+
case BOS:
219+
client, err = bos.NewBucketClient(cfg.BOS, name, logger)
204220
default:
205221
return nil, ErrUnsupportedStorageBackend
206222
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package oss
2+
3+
import (
4+
"github.com/go-kit/log"
5+
"github.com/thanos-io/objstore"
6+
"github.com/thanos-io/objstore/providers/oss"
7+
)
8+
9+
// NewBucketClient creates a new Alibaba Cloud OSS bucket client
10+
func NewBucketClient(cfg Config, component string, logger log.Logger) (objstore.Bucket, error) {
11+
ossCfg := oss.Config{
12+
Endpoint: cfg.Endpoint,
13+
Bucket: cfg.Bucket,
14+
AccessKeyID: cfg.AccessKeyID,
15+
AccessKeySecret: cfg.AccessKeySecret.String(),
16+
}
17+
return oss.NewBucketWithConfig(logger, ossCfg, component, nil)
18+
}

‎pkg/storage/bucket/oss/config.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package oss
2+
3+
import (
4+
"flag"
5+
6+
"github.com/grafana/dskit/flagext"
7+
)
8+
9+
// Config holds the configuration for Alibaba Cloud OSS client
10+
type Config struct {
11+
Endpoint string `yaml:"endpoint"`
12+
Bucket string `yaml:"bucket"`
13+
AccessKeyID string `yaml:"access_key_id"`
14+
AccessKeySecret flagext.Secret `yaml:"access_key_secret"`
15+
}
16+
17+
// RegisterFlags registers the flags for Alibaba Cloud OSS storage config
18+
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
19+
cfg.RegisterFlagsWithPrefix("", f)
20+
}
21+
22+
// RegisterFlagsWithPrefix registers the flags for Alibaba Cloud OSS storage config with prefix
23+
func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
24+
f.StringVar(&cfg.Bucket, prefix+"oss.bucketname", "", "Name of OSS bucket.")
25+
f.StringVar(&cfg.Endpoint, prefix+"oss.endpoint", "", "Endpoint to connect to.")
26+
f.StringVar(&cfg.AccessKeyID, prefix+"oss.access-key-id", "", "alibabacloud Access Key ID")
27+
f.Var(&cfg.AccessKeySecret, prefix+"oss.access-key-secret", "alibabacloud Secret Access Key")
28+
}

‎vendor/github.com/thanos-io/objstore/clientutil/parse.go

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)