Skip to content

Conversation

@adoroszlai
Copy link
Contributor

What changes were proposed in this pull request?

Metrics sources should try to avoid exposing mutable metric objects as public.

  • reduce visibility for most methods
  • change some to return value() instead of the mutable metric itself
  • move OzoneManagerDoubleBufferMetrics to the package where OzoneManagerDoubleBuffer is

https://issues.apache.org/jira/browse/HDDS-10467

How was this patch tested?

CI:
https://github.com/adoroszlai/ozone/actions/runs/8160490612

@adoroszlai adoroszlai self-assigned this Mar 5, 2024
@adoroszlai adoroszlai requested a review from duongkame March 5, 2024 21:38
return totalWriteChunkBytes;
}

@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

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

As tests for this class are in the same package, the VisibleForTesting annotation can be also removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also considered removing the annotation. Here's why I kept it (so far):

Javadoc of @VisibleForTesting says it should not be used on public or protected members, since that indicates bad design. By that logic it should only be applied to members with package-private (default) visibility. So removing it when tests are in the same package means we would never use the annotation.

On the other hand, I'm not sure if it's worth sprinkling all over the code for trivial accessors. Maybe we should limit it to methods with actual logic. Such methods exist in their own right for the class itself, only visibility is affected by usage in tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

VisibleForTesting annotation is overused in the codebase. I think a ticket named "Reduce metrics visibility" is a good chance to put things in order there, including the annotation.
If removing an annotation doesn't break tests, the annotation is not needed and should be removed.

Copy link
Contributor

@myskov myskov left a comment

Choose a reason for hiding this comment

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

Thanks for updating the patch, LGTM @adoroszlai

@adoroszlai adoroszlai added the code-cleanup Changes that aim to make code better, without changing functionality. label Mar 6, 2024
@adoroszlai adoroszlai merged commit 87d8d61 into apache:master Mar 6, 2024
@adoroszlai
Copy link
Contributor Author

Thanks @kerneltime, @myskov for the review.

@adoroszlai adoroszlai deleted the HDDS-10467 branch March 6, 2024 12:13
jojochuang pushed a commit to jojochuang/ozone that referenced this pull request Mar 15, 2024
(cherry picked from commit 87d8d61)
Change-Id: Ic803fb7f3f28dd5dc9a279f1f74602e49a5ab9c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-cleanup Changes that aim to make code better, without changing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants