HDDS-6528. Adding Unit-Test cases for S3-Gateway Bucket-Endpoint Metrics.#3263
HDDS-6528. Adding Unit-Test cases for S3-Gateway Bucket-Endpoint Metrics.#3263jojochuang merged 7 commits intoapache:masterfrom
Conversation
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @ArafatKhan2198 for working on this. There is compile error due to recent change on master (HDDS-6466). Can you please merge origin/master into your branch?
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java
Outdated
Show resolved
Hide resolved
...p-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/metrics/TestS3GatewayMetrics.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Can you please add separate test cases (methods) for success/failure scenarios instead of bundling them in the same?
There was a problem hiding this comment.
Each method is associated with a single S3 Endpoint and there are 2 metrics associated with each endpoint, hence we are measuring the number of times a method succeeds and fails, and once an object is initialised we can reuse it for both the metrics, therefore I felt clubbing them together would make more sense !!
There was a problem hiding this comment.
Each method is associated with a single S3 Endpoint and there are 2 metrics associated with each endpoint, hence we are measuring the number of times a method succeeds and fails, and once an object is initialised we can reuse it for both the metrics
Currently each test method is associated with a method on one of the endpoints. E.g. testCreateBucket tests bucketEndpoint.put(), while testDeleteBucket tests bucketEndpoint.delete(). If object reuse is so important, why not merge all these together in a huge testBucketEndpoint method?
The reasons for separating these are at least:
- Small, self-contained test methods are easier to understand.
- Independence: test cases may pass or fail regardless of the result of other test cases. If multiple cases are bundled in the same method, failure of one case may hide the result of the subsequent case.
We can apply the same reasons to testing different metrics on the same endpoint and method pairs.
There was a problem hiding this comment.
Yes you are absolutely right on that part, I'll make the necessary changes
Thanks for the help !!
6816ced to
e9787e1
Compare
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @ArafatKhan2198 for updating the patch. On second look I've found a few more issues.
| } | ||
|
|
||
| private OzoneClient createClientWithKeys(String... keys) throws IOException { | ||
| OzoneClient client = new OzoneClientStub(); |
There was a problem hiding this comment.
setup() already creates a clientStub, why is this new client needed?
There was a problem hiding this comment.
I am sorry I forgot to remove it !!
will change it, thanks !!
| LOG.debug("Bucket Does not Exist " + bucketName, ex); | ||
| throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex); |
There was a problem hiding this comment.
We should just rethrow ex, because:
OS3Exceptionalready has an error code and proper message. No need to wrap in another exception.- Cause may be different, not necessarily
NO_SUCH_BUCKET.
On second thought we also don't need the debug message, because the exception is logged at debug level in newError.
| LOG.debug("Bucket Does not Exist " + bucketName, ex); | |
| throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex); | |
| throw ex; |
There was a problem hiding this comment.
+1 we should just increment the counter and retrhwo
There was a problem hiding this comment.
Sure will do !!
| LOG.debug("Failed to get acl of Bucket " + bucketName, ex); | ||
| throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex); |
There was a problem hiding this comment.
Same here:
| LOG.debug("Failed to get acl of Bucket " + bucketName, ex); | |
| throw newError(S3ErrorTable.NO_SUCH_BUCKET, bucketName, ex); | |
| throw ex; |
There was a problem hiding this comment.
Will make the change, thanks !!
| throw exception; | ||
| } catch (OS3Exception ex) { | ||
| getMetrics().incPutAclFailure(); | ||
| LOG.debug("Failed to put acl of Bucket " + bucketName, ex); |
There was a problem hiding this comment.
We don't need the debug message, because the exception is logged at debug level in newError.
| LOG.debug("Failed to put acl of Bucket " + bucketName, ex); |
There was a problem hiding this comment.
Will make the change, thanks !!
|
|
||
| // BucketEndpoint | ||
| private @Metric MutableCounterLong getBucketSuccess; | ||
|
|
There was a problem hiding this comment.
Will make the change, thanks !!
| private @Metric MutableCounterLong getBucketSuccess; | ||
|
|
||
| private @Metric MutableCounterLong getBucketFailure; | ||
|
|
There was a problem hiding this comment.
Will make the change, thanks !!
| throw newError(S3ErrorTable.INVALID_BUCKET_NAME, bucketName, exception); | ||
| } | ||
| LOG.error("Error in Create Bucket Request for bucket: {}", bucketName, | ||
| LOG.debug("Error in Create Bucket Request for bucket: {}", bucketName, |
There was a problem hiding this comment.
Nit: unrelated change.
| LOG.debug("Error in Create Bucket Request for bucket: {}", bucketName, | |
| LOG.error("Error in Create Bucket Request for bucket: {}", bucketName, |
There was a problem hiding this comment.
Will make the change, thanks !!
...p-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/metrics/TestS3GatewayMetrics.java
Show resolved
Hide resolved
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @ArafatKhan2198 for updating the patch, especially for separating the test cases. I noticed one typo where the wrong metric is returned, otherwise it's looks good to me.
| public long getListMultipartUploadsFailure() { | ||
| return listMultipartUploadsSuccess.value(); |
There was a problem hiding this comment.
Sorry, I just noticed this typo:
| public long getListMultipartUploadsFailure() { | |
| return listMultipartUploadsSuccess.value(); | |
| public long getListMultipartUploadsFailure() { | |
| return listMultipartUploadsFailure.value(); |
| InputStream inputBody = TestBucketAcl.class.getClassLoader() | ||
| .getResourceAsStream("userAccessControlList.xml"); | ||
|
|
||
| try { | ||
| bucketEndpoint.put("unknown_bucket", ACL_MARKER, headers, inputBody); | ||
| fail(); | ||
| } catch (OS3Exception ex) { | ||
| } | ||
| inputBody.close(); |
There was a problem hiding this comment.
Nit: using try-with-resources we can ensure that the stream is closed even in case of failure.
| InputStream inputBody = TestBucketAcl.class.getClassLoader() | |
| .getResourceAsStream("userAccessControlList.xml"); | |
| try { | |
| bucketEndpoint.put("unknown_bucket", ACL_MARKER, headers, inputBody); | |
| fail(); | |
| } catch (OS3Exception ex) { | |
| } | |
| inputBody.close(); | |
| try (InputStream inputBody = TestBucketAcl.class.getClassLoader() | |
| .getResourceAsStream("userAccessControlList.xml")) { | |
| bucketEndpoint.put("unknown_bucket", ACL_MARKER, headers, inputBody); | |
| fail(); | |
| } catch (OS3Exception ex) { | |
| } |
| // Failing the putACL endpoint by applying ACL on a non-Existent Bucket | ||
| long oriMetric = metrics.getPutAclFailure(); | ||
|
|
||
| clientStub.getObjectStore().createS3Bucket("b1"); |
There was a problem hiding this comment.
Nit: b1 bucket is not needed for this test case.
| InputStream inputBody = TestBucketAcl.class.getClassLoader() | ||
| .getResourceAsStream("userAccessControlList.xml"); | ||
|
|
||
| bucketEndpoint.put("b1", ACL_MARKER, headers, inputBody); | ||
| inputBody.close(); |
There was a problem hiding this comment.
Nit: using try-with-resources we can ensure that the stream is closed even in case of failure.
| InputStream inputBody = TestBucketAcl.class.getClassLoader() | |
| .getResourceAsStream("userAccessControlList.xml"); | |
| bucketEndpoint.put("b1", ACL_MARKER, headers, inputBody); | |
| inputBody.close(); | |
| try (InputStream inputBody = TestBucketAcl.class.getClassLoader() | |
| .getResourceAsStream("userAccessControlList.xml")) { | |
| bucketEndpoint.put("b1", ACL_MARKER, headers, inputBody); | |
| } |
What changes were proposed in this pull request?
Added Unit Tests for Bucket Endpoint Metrics for S3-Gateway
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-6528
How was this patch tested?
Wrote Unit tests for existing metrics
@jojochuang @aryangupta1998 @siddhantsangwan @adoroszlai