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

Add parameter to GET /accounts API to ignore containers information #2998

Merged
merged 3 commits into from
Jan 30, 2025

Conversation

Arun-LinkedIn
Copy link
Contributor

Summary

Add parameter in GET /accounts API to ignore containers information. This is useful for fetching fields of Account (such as quotaResourceType, aclInheritedByContainer) without overhead of containers information.

Testing Done

Tested in locally deployed Ambry

  1. With container information
> curl "http://localhost:1174/accounts" -H "x-ambry-target-account-name: named-blob-sandbox" | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   889  100   889    0     0   3108      0 --:--:-- --:--:-- --:--:--  3108
{
  "accounts": [
    {
      "snapshotVersion": 0,
      "lastModifiedTime": 0,
      "status": "ACTIVE",
      "aclInheritedByContainer": false,
      "quotaResourceType": "ACCOUNT",
      "accountId": 101,
      "accountName": "named-blob-sandbox",
      "containers": [
        {
          "status": "ACTIVE",
          "deleteTriggerTime": 0,
          "description": "This is a container for the blobs without specifying a target account and container when they are put",
          "encrypted": false,
          "cacheable": true,
          "backupEnabled": false,
          "mediaScanDisabled": false,
          "paranoidDurabilityEnabled": false,
          "replicationPolicy": null,
          "ttlRequired": true,
          "securePathRequired": false,
          "namedBlobMode": "OPTIONAL",
          "accessControlAllowOrigin": "",
          "contentTypeWhitelistForFilenamesOnDownload": [],
          "lastModifiedTime": 0,
          "snapshotVersion": 0,
          "cacheTtlInSecond": null,
          "userMetadataKeysToNotPrefixInResponse": [],
          "containerId": 8,
          "containerName": "container-a",
          "previouslyEncrypted": false,
          "overrideAccountAcl": false,
          "version": 2
        }
      ],
      "version": 1
    }
  ]
}

  1. Without container information
> curl "http://localhost:1174/accounts" -H "x-ambry-target-account-name: named-blob-sandbox" -H "x-ambry-ignore-containers:true" | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   200  100   200    0     0   2387      0 --:--:-- --:--:-- --:--:--  2380
{
  "accounts": [
    {
      "snapshotVersion": 0,
      "lastModifiedTime": 0,
      "status": "ACTIVE",
      "aclInheritedByContainer": false,
      "quotaResourceType": "ACCOUNT",
      "accountId": 101,
      "accountName": "named-blob-sandbox",
      "version": 1
    }
  ]
}

@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.03%. Comparing base (52ba813) to head (0008782).
Report is 167 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2998      +/-   ##
============================================
+ Coverage     64.24%   70.03%   +5.79%     
- Complexity    10398    12136    +1738     
============================================
  Files           840      884      +44     
  Lines         71755    74786    +3031     
  Branches       8611     8966     +355     
============================================
+ Hits          46099    52378    +6279     
+ Misses        23004    19682    -3322     
- Partials       2652     2726      +74     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@allenaverbukh allenaverbukh left a comment

Choose a reason for hiding this comment

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

minor questions + style .. if you think they can be disregarded -- let me know and i can approve

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe serializedAccounts might be better variable name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done..

RestResponseChannel restResponseChannel = new MockRestResponseChannel();
ReadableStreamChannel channel = sendRequestGetResponse(request, restResponseChannel);
assertNotNull("There should be a response", channel);
Assert.assertNotNull("Date has not been set", restResponseChannel.getHeader(RestUtils.Headers.DATE));
Copy link
Contributor

Choose a reason for hiding this comment

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

why does line 181 not have "Assert." like line 182

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah.. made it consistent

*/
public static byte[] serializeAccountsInJsonNoContainers(Collection<Account> accounts) throws IOException {
Map<String, Collection<Account>> resultObj = new HashMap<>();
resultObj.put(ACCOUNTS_KEY, accounts);
Copy link
Contributor

Choose a reason for hiding this comment

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

im still new to concurrency but assuming concurrency is involved, do you see any issues that could occur with having a non-concurrent hashmap here? will the different threads not overwrite anything or have race condition ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no concurrency involved with this method. This map is created in this method, which makes it a local variable to this method. If we have multiple threads executing this method, they would just create multiple map objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1

Comment on lines 131 to 137
boolean ignoreContainers =
RestUtils.getBooleanHeader(restRequest.getArgs(), RestUtils.Headers.IGNORE_CONTAINERS, false);
if (ignoreContainers) {
serialized = AccountCollectionSerde.serializeAccountsInJsonNoContainers(getAccounts());
} else {
serialized = AccountCollectionSerde.serializeAccountsInJson(getAccounts());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we merge these two methods to one method with extra parameter? Something like

serialized = AccountCollectionSerde.serializeAccountsInJson(getAccountsI(), RestUtils.getBooleanHeader(restRequest.getArgs(), RestUtils.Headers.IGNORE_CONTAINERS, false));

Basically move the boolean logic to AccountCollectionSerde.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Done..

*/
public static byte[] serializeAccountsInJsonNoContainers(Collection<Account> accounts) throws IOException {
Map<String, Collection<Account>> resultObj = new HashMap<>();
resultObj.put(ACCOUNTS_KEY, accounts);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no concurrency involved with this method. This map is created in this method, which makes it a local variable to this method. If we have multiple threads executing this method, they would just create multiple map objects.

@Arun-LinkedIn Arun-LinkedIn merged commit f7d2c88 into linkedin:master Jan 30, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants