Skip to content

Commit

Permalink
passes ContainerURL to getBlobURL for Azure (#4607)
Browse files Browse the repository at this point in the history
* Passes ContainerURL to getBlobURL for Azure

Signed-off-by: Wiard van Rij <wiard@outlook.com>

* e2e retest

Signed-off-by: Wiard van Rij <wiard@outlook.com>

* adds changelog

Signed-off-by: Wiard van Rij <wiard@outlook.com>
  • Loading branch information
wiardvanrij committed Aug 27, 2021
1 parent 702752a commit 4b03b54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -27,6 +27,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#4468](https://github.com/thanos-io/thanos/pull/4468) Rule: Fix temporary rule filename composition issue.
- [#4476](https://github.com/thanos-io/thanos/pull/4476) UI: fix incorrect html escape sequence used for '>' symbol.
- [#4532](https://github.com/thanos-io/thanos/pull/4532) Mixin: Fixed "all jobs" selector in thanos mixin dashboards.
- [#4607](https://github.com/thanos-io/thanos/pull/4607) Azure: Fix Azure MSI Rate Limit

### Changed
- [#4519](https://github.com/thanos-io/thanos/pull/4519) Query: switch to miekgdns DNS resolver as the default one.
Expand Down
32 changes: 10 additions & 22 deletions pkg/objstore/azure/azure.go
Expand Up @@ -294,7 +294,7 @@ func (b *Bucket) getBlobReader(ctx context.Context, name string, offset, length
return nil, errors.New("X-Ms-Error-Code: [BlobNotFound]")
}

blobURL, err := getBlobURL(ctx, *b.config, name)
blobURL := getBlobURL(name, b.containerURL)
if err != nil {
return nil, errors.Wrapf(err, "cannot get Azure blob URL, address: %s", name)
}
Expand Down Expand Up @@ -345,13 +345,9 @@ func (b *Bucket) GetRange(ctx context.Context, name string, off, length int64) (

// Attributes returns information about the specified object.
func (b *Bucket) Attributes(ctx context.Context, name string) (objstore.ObjectAttributes, error) {
blobURL, err := getBlobURL(ctx, *b.config, name)
if err != nil {
return objstore.ObjectAttributes{}, errors.Wrapf(err, "cannot get Azure blob URL, blob: %s", name)
}
blobURL := getBlobURL(name, b.containerURL)

var props *blob.BlobGetPropertiesResponse
props, err = blobURL.GetProperties(ctx, blob.BlobAccessConditions{}, blob.ClientProvidedKeyOptions{})
props, err := blobURL.GetProperties(ctx, blob.BlobAccessConditions{}, blob.ClientProvidedKeyOptions{})
if err != nil {
return objstore.ObjectAttributes{}, err
}
Expand All @@ -365,12 +361,9 @@ func (b *Bucket) Attributes(ctx context.Context, name string) (objstore.ObjectAt
// Exists checks if the given object exists.
func (b *Bucket) Exists(ctx context.Context, name string) (bool, error) {
level.Debug(b.logger).Log("msg", "check if blob exists", "blob", name)
blobURL, err := getBlobURL(ctx, *b.config, name)
if err != nil {
return false, errors.Wrapf(err, "cannot get Azure blob URL, address: %s", name)
}
blobURL := getBlobURL(name, b.containerURL)

if _, err = blobURL.GetProperties(ctx, blob.BlobAccessConditions{}, blob.ClientProvidedKeyOptions{}); err != nil {
if _, err := blobURL.GetProperties(ctx, blob.BlobAccessConditions{}, blob.ClientProvidedKeyOptions{}); err != nil {
if b.IsObjNotFoundErr(err) {
return false, nil
}
Expand All @@ -383,11 +376,9 @@ func (b *Bucket) Exists(ctx context.Context, name string) (bool, error) {
// Upload the contents of the reader as an object into the bucket.
func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {
level.Debug(b.logger).Log("msg", "Uploading blob", "blob", name)
blobURL, err := getBlobURL(ctx, *b.config, name)
if err != nil {
return errors.Wrapf(err, "cannot get Azure blob URL, address: %s", name)
}
if _, err = blob.UploadStreamToBlockBlob(ctx, r, blobURL,
blobURL := getBlobURL(name, b.containerURL)

if _, err := blob.UploadStreamToBlockBlob(ctx, r, blobURL,
blob.UploadStreamToBlockBlobOptions{
BufferSize: 3 * 1024 * 1024,
MaxBuffers: 4,
Expand All @@ -401,12 +392,9 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {
// Delete removes the object with the given name.
func (b *Bucket) Delete(ctx context.Context, name string) error {
level.Debug(b.logger).Log("msg", "Deleting blob", "blob", name)
blobURL, err := getBlobURL(ctx, *b.config, name)
if err != nil {
return errors.Wrapf(err, "cannot get Azure blob URL, address: %s", name)
}
blobURL := getBlobURL(name, b.containerURL)

if _, err = blobURL.Delete(ctx, blob.DeleteSnapshotsOptionInclude, blob.BlobAccessConditions{}); err != nil {
if _, err := blobURL.Delete(ctx, blob.DeleteSnapshotsOptionInclude, blob.BlobAccessConditions{}); err != nil {
return errors.Wrapf(err, "error deleting blob, address: %s", name)
}
return nil
Expand Down
8 changes: 2 additions & 6 deletions pkg/objstore/azure/helpers.go
Expand Up @@ -156,12 +156,8 @@ func createContainer(ctx context.Context, conf Config) (blob.ContainerURL, error
return c, err
}

func getBlobURL(ctx context.Context, conf Config, blobName string) (blob.BlockBlobURL, error) {
c, err := getContainerURL(ctx, conf)
if err != nil {
return blob.BlockBlobURL{}, err
}
return c.NewBlockBlobURL(blobName), nil
func getBlobURL(blobName string, c blob.ContainerURL) blob.BlockBlobURL {
return c.NewBlockBlobURL(blobName)
}

func parseError(errorCode string) string {
Expand Down

0 comments on commit 4b03b54

Please sign in to comment.