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

[storage-blob]Refine behavior of BlobClient.exists #15364

Merged
merged 2 commits into from
Feb 15, 2022
Merged

Conversation

EmmaZhu
Copy link
Member

@EmmaZhu EmmaZhu commented May 21, 2021

Against a blob uploaded with CPK, storage server would return error message of 'BlobUsesCustomerSpecifiedEncryption' for get attributes (without CPK specified) when blob exists.

BlobClient.exists leverages getAttributes operation to verify blob's existence, based on the above behavior, it should return true if got error message 'BlobUsesCustomerSpecifiedEncryption' from server.

@ghost ghost added the Storage Storage Service (Queues, Blobs, Files) label May 21, 2021
openapi-sdkautomation bot pushed a commit to AzureSDKAutomation/azure-sdk-for-js that referenced this pull request Aug 11, 2021
LUIS Authoring V3.0 GA  (Azure#15364)

* v3.0 swagger

* Unchange the preview folder

* Changes in the readme

* readme.go changes

* Readme.md changes

* Changes in th readme

* Changing all v2 to v3

* Editing LUIS.authoring

* Editing readme

* Adding "fuzzyMatchingEnabled" property to some objects

* solving syntax errors

* Deleting SDK files

* Solving errors

* Editing package.json

* Changes according to the comments

* Changing the default value of some properties

* Adding prettier check

* Change

* Revert "Change"

This reverts commit ca991fbbc99602d75128a2f84b1510ae999f9948.

* Add missing parts

* Changes for the SDK

Co-authored-by: MIDDLEEAST\v-mariamel <[email protected]>
@ramya-rao-a
Copy link
Contributor

@EmmaZhu This PR has not seen any activity in about 4 months. Is this still applicable? Looks like there are breaking changes here

@EmmaZhu
Copy link
Member Author

EmmaZhu commented Sep 2, 2021

Thanks @ramya-rao-a for the reminding.

The change is still applicable. I'll handle it later in this week.

Thanks
Emma

@@ -1277,7 +1278,17 @@ export class BlobClient extends StorageClient {
message: "Expected exception when checking blob existence",
});
return false;
} else if (
e.statusCode === 409 &&
Copy link
Member

Choose a reason for hiding this comment

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

@lmolkova I forget what we decided with regards to "expected exceptions" - should the spans be marked as error or success?

In this case there are two scenarios:

  1. 404 when checking if a blob exists, returning false as it does not
  2. 409 when checking if a blob exists which is expected as well if the blob uses specified encryption message (not sure what that means, but seems expected here) and returning true

What would we expect the span status to be? And IIRC the nested HTTP spans will return error since it's a 400ish status code.

Copy link
Member

Choose a reason for hiding this comment

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

We should avoid setting span status for 404/409 calls at all if we are not sure an error has happened:

  • the http status code is enough for Http calls.
  • Logical calls can still end without a status set at all and users can figure out what happened based on the underlying http span.

There could be some room for improvement here (e.g. we might need to show what exists eventually returned), but it feels like an incremental change as long as we leave status unset.

We must not add an exception in any case.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a convenience existence checking for customer.

We only have logic to understand the status we exactly know the meanings.
404 means the target doesn't exist, so we return false.
409 means the target exists, but the provided encryption key is not valid, but existence checking doesn't care about encryption, so we return true to tell customer the target exists.

We won't catch other reported errors.

Copy link
Member

@maorleger maorleger Feb 4, 2022

Choose a reason for hiding this comment

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

In this case then I would recommend the following:

  • In the success case (line 1273) set the span status to success
  • In the error case (the catch block), if the http statusCode is 404 or 409 leave the span status unset, otherwise set it to error and record the message (as you are already doing in line 1291)

Something like this:

  public async exists(options: BlobExistsOptions = {}): Promise<boolean> {
    const { span, updatedOptions } = createSpan("BlobClient-exists", options);
    try {
      ensureCpkIfSpecified(options.customerProvidedKey, this.isHttps);
      await this.getProperties({
        abortSignal: options.abortSignal,
        customerProvidedKey: options.customerProvidedKey,
        conditions: options.conditions,
        tracingOptions: updatedOptions.tracingOptions,
      });
      span.setStatus({
        code: SpanStatusCode.OK,
      });
      return true;
    } catch (e) {
      if (e.statusCode === 404) {
        return false;
      } else if (
        e.statusCode === 409 &&
        e.details.errorCode === BlobUsesCustomerSpecifiedEncryptionMsg
      ) {
        return true;
      }

      span.setStatus({
        code: SpanStatusCode.ERROR,
        message: e.message,
      });
      throw e;
    } finally {
      span.end();
    }
  }

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks a lot for the comments. I've made change as you suggested.

Copy link
Member

@XiaoningLiu XiaoningLiu left a comment

Choose a reason for hiding this comment

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

As synchronized offline, when blob doesn't exist, it will never return 409. This change is also aligned with .Net SDK.

…ns error message of 'BlobUsesCustomerSpecifiedEncryption'.
@EmmaZhu EmmaZhu merged commit d054706 into Azure:main Feb 15, 2022
@EmmaZhu EmmaZhu deleted the exists branch February 15, 2022 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants