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

feat: create disk memory health checker #5781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AnneMayor
Copy link

@AnneMayor AnneMayor commented Jun 22, 2024

Motivation:

Modifications:

Result:

@CLAassistant
Copy link

CLAassistant commented Jun 22, 2024

CLA assistant check
All committers have signed the CLA.

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch 2 times, most recently from 0e516c8 to 6655182 Compare June 22, 2024 16:46
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks good overall! Left a minor comment 👍

* @param targetTotalDiskSpace Target total disk space in bytes.
* @return an instance of {@link HealthChecker} configured with the provided disk memory space targets.
*/
static HealthChecker ofDisk(long targetFreeDiskSpace, long targetTotalDiskSpace, String path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it would be very useful to allow users to specify the path.
What do you think of just setting this value as a new File(".") like done in spring-boot by default?

ref: https://github.com/spring-projects/spring-boot/blob/ca6ba2e7cf1355fe4764e6bec93dc78f5e76c07e/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java#L205

I also don't think accepting targetTotalDiskSpace would be very useful since it would be mostly static in most cases.

Copy link
Member

@trustin trustin Jun 25, 2024

Choose a reason for hiding this comment

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

Ideally, we should discover all disks in the system automatically (with options to specify or filter filesystem), detect the size of the filesystem. We should also allow a user to specify percentage values.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, I prefer a single health checker is responsible for a single disk as the condition for health checking may become complex. I guess it's fine to leave the File parameter as is then.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we could indeed make use of composition of multiple health checkers to check multiple filesystems. Shall we focus on handling a single filesystem first and see how we could evolve this? That is, yeah, let's keep the File parameter.

Copy link
Author

@AnneMayor AnneMayor Jul 2, 2024

Choose a reason for hiding this comment

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

Thanks for all comments :) Unfortunately, I am not sure what I should do exactly.
Should I remove percentage values if then?

Copy link
Contributor

@injae-kim injae-kim Jul 5, 2024

Choose a reason for hiding this comment

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

Suggested change
static HealthChecker ofDisk(long targetFreeDiskSpace, long targetTotalDiskSpace, String path) {
static HealthChecker ofDisk(long targetFreeDiskSpace, File file) {

Then we only need targetFreeDiskSpace and file as parameter at first?

I think we can enhance it in the future :)

Copy link
Author

Choose a reason for hiding this comment

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

@injae-kim Thank you for your clarification. I get it. Will fix it within this weekend🙂

@injae-kim
Copy link
Contributor

injae-kim commented Jul 5, 2024

FYI) @AnneMayor is my opensource mentoring memeber, contributed on spring-projects/spring-data-redis#2905!

Welcome to armeria! 😃

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch 2 times, most recently from 442e518 to 8070a07 Compare July 7, 2024 07:32
@AnneMayor
Copy link
Author

I fixed it. Please, review it :)

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch 2 times, most recently from d9e7f3f to f1e1716 Compare July 7, 2024 11:32
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left some more comments 👍

@@ -73,6 +75,31 @@ protected void configure(ServerBuilder sb) {
@BeforeEach
void setup() {
serverChannelPipeline.set(null);

bodyPublisher = new BodyPublisher() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert unrelated changes in this PR? I prefer that flaky tests be handled separately - I think it's fine if some flaky tests don't pass in the CI run

Copy link
Author

Choose a reason for hiding this comment

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

Oh I see. Thanks.

* Both free disk space must be (inclusive) lower than the specified threshold in order
* for the {@link HealthChecker} to report as healthy.
*
* @param targetFreeDiskSpace Target free disk space in bytes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param targetFreeDiskSpace Target free disk space in bytes.
* @param diskSpacePercentage the target free disk space as a percentage (0 - 1).

Copy link
Author

Choose a reason for hiding this comment

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

I ammended targetDiskSpacePercentage as you suggested below. Please, consider it.

Comment on lines 110 to 111
* Creates a new instance of {@link HealthChecker}
* which reports health based on disk space of specific file path.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Creates a new instance of {@link HealthChecker}
* which reports health based on disk space of specific file path.
* Creates a new instance of {@link HealthChecker} which reports health based on free disk space
* of the file system the specified path belongs to.

* @param targetFreeDiskSpace Target free disk space in bytes.
* @return an instance of {@link HealthChecker} configured with the provided disk memory space targets.
*/
static HealthChecker ofDisk(double targetFreeDiskSpace, File path) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static HealthChecker ofDisk(double targetFreeDiskSpace, File path) {
static HealthChecker ofDisk(double targetDiskSpacePercentage, File path) {

private final File path;

DiskMemoryHealthChecker(double targetFreeDiskSpace, File path) {
checkArgument(targetFreeDiskSpace >= 0, "freeDiskSpace: %s (expected: >= 0)", targetFreeDiskSpace);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are dealing with percentages, can you also validate that targetFreeDiskSpace <= 1?

Copy link
Author

Choose a reason for hiding this comment

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

For sure 👍

*/
@Override
public boolean isHealthy() {
return path.getUsableSpace() >= targetFreeDiskSpace;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check the percentage of free space instead?

Suggested change
return path.getUsableSpace() >= targetFreeDiskSpace;
return targetFreeSpacePercentage * path.getTotalSpace() <= path.getUsableSpace();

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from f1e1716 to 539c119 Compare July 20, 2024 06:20
@AnneMayor
Copy link
Author

comments resolved.

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from 539c119 to 5588b14 Compare July 20, 2024 07:12
Comment on lines 28 to 31
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(100, new File("/tmp"));
*
* // Returns false if a file disk usable memory space is less than 100 bytes,
* // or true if a file disk usable memory space is greater than or equal to 100 bytes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(100, new File("/tmp"));
*
* // Returns false if a file disk usable memory space is less than 100 bytes,
* // or true if a file disk usable memory space is greater than or equal to 100 bytes.
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(0.8, new File("/tmp"));
*
* // Returns false if a file disk usable memory space is less than 80%.
* // or true if a file disk usable memory space is greater than or equal to 80%.

Can you update doc properly too here?

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I missed it. Thanks.

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from 5588b14 to 8ce5606 Compare July 21, 2024 06:04
@AnneMayor
Copy link
Author

@injae-kim comments resolved 🙇‍♀️

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left some final comments 👍


DiskMemoryHealthChecker(double targetFreeSpacePercentage, File path) {
checkArgument(targetFreeSpacePercentage >= 0 && targetFreeSpacePercentage <= 1,
"freeDiskSpace: %s (expected < 0 or expected > 1)", targetFreeSpacePercentage);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since that's what we expect

Suggested change
"freeDiskSpace: %s (expected < 0 or expected > 1)", targetFreeSpacePercentage);
"freeDiskSpacePercentage: %s (expected >= 0 and <= 1)", targetFreeSpacePercentage);

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I just meant to express the error status. I didn't think of the normal value comments. Thanks.

/**
* Creates a new instance of {@link HealthChecker} which reports health based on free disk space
* of the file system the specified path belongs to.
* Both free disk space must be (inclusive) lower than the specified threshold in order
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Both free disk space must be (inclusive) lower than the specified threshold in order
* There must be more free space (inclusive) than the specified threshold in order

Comment on lines 115 to 123
* @param targetDiskSpacePercentage the target free disk space as a percentage (0 - 1).
* @return an instance of {@link HealthChecker} configured with the provided disk memory space targets.
*/
static HealthChecker ofDisk(double targetDiskSpacePercentage, File path) {
return new DiskMemoryHealthChecker(targetDiskSpacePercentage, path);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry about changing my mind, but freeDiskSpacePercentage seems like a better term since it is analogous to the df linux command, and percentage denotes the type of value.

Can you also replace the name targetFreeSpacePercentage used in DiskMemoryHealthChecker to freeDiskSpacePercentage as well?

Suggested change
* @param targetDiskSpacePercentage the target free disk space as a percentage (0 - 1).
* @return an instance of {@link HealthChecker} configured with the provided disk memory space targets.
*/
static HealthChecker ofDisk(double targetDiskSpacePercentage, File path) {
return new DiskMemoryHealthChecker(targetDiskSpacePercentage, path);
}
* @param freeDiskSpacePercentage the target free disk space as a percentage (0 - 1).
* @return an instance of {@link HealthChecker} configured with the provided disk memory space targets.
*/
static HealthChecker ofDisk(double freeDiskSpacePercentage, File path) {
return new DiskMemoryHealthChecker(freeDiskSpacePercentage, path);
}

Copy link
Author

Choose a reason for hiding this comment

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

For sure. Will apply it.

* when the target free disk space exceeds a file disk usable space.
* For example:
* <pre>{@code
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(80, new File("/tmp"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(80, new File("/tmp"));
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(0.8, new File("/tmp"));

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from f4c53c1 to bf1bc4e Compare July 25, 2024 13:52
@AnneMayor
Copy link
Author

Resolved.

@ikhoon , since rebasing merge your merge commit was updated to my current commit. I hope that would no change logs. Please, review it 🙇‍♀️

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from bf1bc4e to 1791558 Compare July 25, 2024 17:08
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 👍 👍 Thanks @AnneMayor 👍

@ikhoon ikhoon modified the milestones: 1.30.0, 1.31.0 Aug 2, 2024
@github-actions github-actions bot added the Stale label Sep 17, 2024
@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from 1791558 to 04f40a6 Compare September 21, 2024 09:15
@AnneMayor
Copy link
Author

Sorry for being late.
@ikhoon resolved.

Please, review it.
Thank you all for your kind supports.

@AnneMayor AnneMayor force-pushed the feature/create-disk-memory-health-checker branch from 04f40a6 to 7e1db1b Compare September 21, 2024 10:48
@github-actions github-actions bot removed the Stale label Sep 22, 2024
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks!
Left small suggestions. 😉

*/
@Override
public CompletionStage<HealthCheckStatus> get() {
return CompletableFuture.supplyAsync(() -> new HealthCheckStatus(isHealthy(), 500));
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of adding the method variant of HealthChecker.ofDisk() that takes an internal?

Copy link
Author

Choose a reason for hiding this comment

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

That's good. I personally want to make this method relating to HealthChecker class methods. Will add it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More HealthChecker implementations
7 participants