Skip to content
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
2 changes: 1 addition & 1 deletion integration/s3_storage_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestS3Client(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client, err := s3.NewS3ObjectClient(tt.cfg, "/")
client, err := s3.NewS3ObjectClient(tt.cfg)

require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/alerts/objectclient/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewAlertStore(client chunk.ObjectClient) *AlertStore {

// ListAlertConfigs returns all of the active alert configs in this store
func (a *AlertStore) ListAlertConfigs(ctx context.Context) (map[string]alerts.AlertConfigDesc, error) {
objs, _, err := a.client.List(ctx, alertPrefix)
objs, _, err := a.client.List(ctx, alertPrefix, "")
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func NewAlertStore(cfg AlertStoreConfig) (AlertStore, error) {
case "local":
return local.NewStore(cfg.Local)
case "gcs":
return newObjAlertStore(gcp.NewGCSObjectClient(context.Background(), cfg.GCS, ""))
return newObjAlertStore(gcp.NewGCSObjectClient(context.Background(), cfg.GCS))
case "s3":
return newObjAlertStore(aws.NewS3ObjectClient(cfg.S3, ""))
return newObjAlertStore(aws.NewS3ObjectClient(cfg.S3))
default:
return nil, fmt.Errorf("unrecognized alertmanager storage backend %v, choose one of: azure, configdb, gcs, local, s3", cfg.Type)
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/chunk/aws/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ var Fixtures = []testutils.Fixture{
schemaCfg: schemaConfig,
metrics: newMetrics(nil),
}
object := objectclient.NewClient(&S3ObjectClient{
S3: newMockS3(),
delimiter: chunk.DirDelim,
}, nil)
object := objectclient.NewClient(&S3ObjectClient{S3: newMockS3()}, nil)
return index, object, table, schemaConfig, testutils.CloserFunc(func() error {
table.Stop()
index.Stop()
Expand Down
14 changes: 4 additions & 10 deletions pkg/chunk/aws/s3_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ func (cfg *S3Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
type S3ObjectClient struct {
bucketNames []string
S3 s3iface.S3API
delimiter string
sseEncryption *string
}

// NewS3ObjectClient makes a new S3-backed ObjectClient.
func NewS3ObjectClient(cfg S3Config, delimiter string) (*S3ObjectClient, error) {
func NewS3ObjectClient(cfg S3Config) (*S3ObjectClient, error) {
s3Config, bucketNames, err := buildS3Config(cfg)
if err != nil {
return nil, errors.Wrap(err, "failed to build s3 config")
Expand All @@ -120,7 +119,6 @@ func NewS3ObjectClient(cfg S3Config, delimiter string) (*S3ObjectClient, error)
client := S3ObjectClient{
S3: s3Client,
bucketNames: bucketNames,
delimiter: delimiter,
sseEncryption: sseEncryption,
}
return &client, nil
Expand Down Expand Up @@ -289,8 +287,8 @@ func (a *S3ObjectClient) PutObject(ctx context.Context, objectKey string, object
})
}

// List objects and common-prefixes i.e synthetic directories from the store non-recursively
func (a *S3ObjectClient) List(ctx context.Context, prefix string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
// List implements chunk.ObjectClient.
func (a *S3ObjectClient) List(ctx context.Context, prefix, delimiter string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
var storageObjects []chunk.StorageObject
var commonPrefixes []chunk.StorageCommonPrefix

Expand All @@ -299,7 +297,7 @@ func (a *S3ObjectClient) List(ctx context.Context, prefix string) ([]chunk.Stora
input := s3.ListObjectsV2Input{
Bucket: aws.String(a.bucketNames[i]),
Prefix: aws.String(prefix),
Delimiter: aws.String(a.delimiter),
Delimiter: aws.String(delimiter),
}

for {
Expand Down Expand Up @@ -337,7 +335,3 @@ func (a *S3ObjectClient) List(ctx context.Context, prefix string) ([]chunk.Stora

return storageObjects, commonPrefixes, nil
}

func (a *S3ObjectClient) PathSeparator() string {
return a.delimiter
}
2 changes: 1 addition & 1 deletion pkg/chunk/aws/s3_storage_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestRequestMiddleware(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg.Inject = tt.fn
client, err := NewS3ObjectClient(cfg, "/")
client, err := NewS3ObjectClient(cfg)
require.NoError(t, err)

readCloser, err := client.GetObject(context.Background(), "key")
Expand Down
16 changes: 5 additions & 11 deletions pkg/chunk/azure/blob_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ type BlobStorage struct {
//blobService storage.Serv
cfg *BlobStorageConfig
containerURL azblob.ContainerURL
delimiter string
}

// NewBlobStorage creates a new instance of the BlobStorage struct.
func NewBlobStorage(cfg *BlobStorageConfig, delimiter string) (*BlobStorage, error) {
func NewBlobStorage(cfg *BlobStorageConfig) (*BlobStorage, error) {
util.WarnExperimentalUse("Azure Blob Storage")
blobStorage := &BlobStorage{
cfg: cfg,
delimiter: delimiter,
cfg: cfg,
}

var err error
Expand Down Expand Up @@ -196,8 +194,8 @@ func (b *BlobStorage) newPipeline() (pipeline.Pipeline, error) {
}), nil
}

// List objects and common-prefixes i.e synthetic directories from the store non-recursively
func (b *BlobStorage) List(ctx context.Context, prefix string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
// List implements chunk.ObjectClient.
func (b *BlobStorage) List(ctx context.Context, prefix, delimiter string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
var storageObjects []chunk.StorageObject
var commonPrefixes []chunk.StorageCommonPrefix

Expand All @@ -206,7 +204,7 @@ func (b *BlobStorage) List(ctx context.Context, prefix string) ([]chunk.StorageO
return nil, nil, ctx.Err()
}

listBlob, err := b.containerURL.ListBlobsHierarchySegment(ctx, marker, b.delimiter, azblob.ListBlobsSegmentOptions{Prefix: prefix})
listBlob, err := b.containerURL.ListBlobsHierarchySegment(ctx, marker, delimiter, azblob.ListBlobsSegmentOptions{Prefix: prefix})
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -240,10 +238,6 @@ func (b *BlobStorage) DeleteObject(ctx context.Context, blobID string) error {
return err
}

func (b *BlobStorage) PathSeparator() string {
return b.delimiter
}

// Validate the config.
func (c *BlobStorageConfig) Validate() error {
if !util.StringsContain(supportedEnvironments, c.Environment) {
Expand Down
4 changes: 1 addition & 3 deletions pkg/chunk/gcp/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ func (f *fixture) Clients() (
}

if f.gcsObjectClient {
cClient = objectclient.NewClient(newGCSObjectClient(GCSConfig{
BucketName: "chunks",
}, f.gcssrv.Client(), chunk.DirDelim), nil)
cClient = objectclient.NewClient(newGCSObjectClient(GCSConfig{BucketName: "chunks"}, f.gcssrv.Client()), nil)
} else {
cClient = newBigtableObjectClient(Config{}, schemaConfig, client)
}
Expand Down
30 changes: 12 additions & 18 deletions pkg/chunk/gcp/gcs_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import (
)

type GCSObjectClient struct {
cfg GCSConfig
client *storage.Client
bucket *storage.BucketHandle
delimiter string
cfg GCSConfig
client *storage.Client
bucket *storage.BucketHandle
}

// GCSConfig is config for the GCS Chunk Client.
Expand All @@ -39,7 +38,7 @@ func (cfg *GCSConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
}

// NewGCSObjectClient makes a new chunk.Client that writes chunks to GCS.
func NewGCSObjectClient(ctx context.Context, cfg GCSConfig, delimiter string) (*GCSObjectClient, error) {
func NewGCSObjectClient(ctx context.Context, cfg GCSConfig) (*GCSObjectClient, error) {
option, err := gcsInstrumentation(ctx, storage.ScopeReadWrite)
if err != nil {
return nil, err
Expand All @@ -49,16 +48,15 @@ func NewGCSObjectClient(ctx context.Context, cfg GCSConfig, delimiter string) (*
if err != nil {
return nil, err
}
return newGCSObjectClient(cfg, client, delimiter), nil
return newGCSObjectClient(cfg, client), nil
}

func newGCSObjectClient(cfg GCSConfig, client *storage.Client, delimiter string) *GCSObjectClient {
func newGCSObjectClient(cfg GCSConfig, client *storage.Client) *GCSObjectClient {
bucket := client.Bucket(cfg.BucketName)
return &GCSObjectClient{
cfg: cfg,
client: client,
bucket: bucket,
delimiter: delimiter,
cfg: cfg,
client: client,
bucket: bucket,
}
}

Expand Down Expand Up @@ -107,12 +105,12 @@ func (s *GCSObjectClient) PutObject(ctx context.Context, objectKey string, objec
return nil
}

// List objects and common-prefixes i.e synthetic directories from the store non-recursively
func (s *GCSObjectClient) List(ctx context.Context, prefix string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
// List implements chunk.ObjectClient.
func (s *GCSObjectClient) List(ctx context.Context, prefix, delimiter string) ([]chunk.StorageObject, []chunk.StorageCommonPrefix, error) {
var storageObjects []chunk.StorageObject
var commonPrefixes []chunk.StorageCommonPrefix

iter := s.bucket.Objects(ctx, &storage.Query{Prefix: prefix, Delimiter: s.delimiter})
iter := s.bucket.Objects(ctx, &storage.Query{Prefix: prefix, Delimiter: delimiter})
for {
if ctx.Err() != nil {
return nil, nil, ctx.Err()
Expand Down Expand Up @@ -155,7 +153,3 @@ func (s *GCSObjectClient) DeleteObject(ctx context.Context, objectKey string) er

return nil
}

func (s *GCSObjectClient) PathSeparator() string {
return s.delimiter
}
7 changes: 2 additions & 5 deletions pkg/chunk/inmemory_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ func (m *MockStorage) DeleteObject(ctx context.Context, objectKey string) error
return nil
}

func (m *MockStorage) List(ctx context.Context, prefix string) ([]StorageObject, []StorageCommonPrefix, error) {
// List implements chunk.ObjectClient.
func (m *MockStorage) List(ctx context.Context, prefix, delimiter string) ([]StorageObject, []StorageCommonPrefix, error) {
m.mtx.RLock()
defer m.mtx.RUnlock()

Expand All @@ -442,10 +443,6 @@ func (m *MockStorage) List(ctx context.Context, prefix string) ([]StorageObject,
return storageObjects, []StorageCommonPrefix{}, nil
}

func (m *MockStorage) PathSeparator() string {
return DirDelim
}

type mockWriteBatch struct {
inserts []struct {
tableName, hashValue string
Expand Down
4 changes: 1 addition & 3 deletions pkg/chunk/local/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ func (f *fixture) Clients() (
return
}

oClient, err := NewFSObjectClient(FSConfig{
Directory: f.dirname,
})
oClient, err := NewFSObjectClient(FSConfig{Directory: f.dirname})
if err != nil {
return
}
Expand Down
Loading