-
Notifications
You must be signed in to change notification settings - Fork 927
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
base: main
Are you sure you want to change the base?
feat: create disk memory health checker #5781
Conversation
0e516c8
to
6655182
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
I also don't think accepting targetTotalDiskSpace
would be very useful since it would be mostly static in most cases.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :)
There was a problem hiding this comment.
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🙂
FYI) @AnneMayor is my opensource mentoring memeber, contributed on spring-projects/spring-data-redis#2905! Welcome to armeria! 😃 |
442e518
to
8070a07
Compare
I fixed it. Please, review it :) |
d9e7f3f
to
f1e1716
Compare
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param targetFreeDiskSpace Target free disk space in bytes. | |
* @param diskSpacePercentage the target free disk space as a percentage (0 - 1). |
There was a problem hiding this comment.
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.
* Creates a new instance of {@link HealthChecker} | ||
* which reports health based on disk space of specific file path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
return path.getUsableSpace() >= targetFreeDiskSpace; | |
return targetFreeSpacePercentage * path.getTotalSpace() <= path.getUsableSpace(); |
f1e1716
to
539c119
Compare
comments resolved. |
539c119
to
5588b14
Compare
core/src/test/java/com/linecorp/armeria/server/healthcheck/DiskMemoryCheckerTest.java
Show resolved
Hide resolved
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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?
There was a problem hiding this comment.
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.
5588b14
to
8ce5606
Compare
@injae-kim comments resolved 🙇♀️ |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
"freeDiskSpace: %s (expected < 0 or expected > 1)", targetFreeSpacePercentage); | |
"freeDiskSpacePercentage: %s (expected >= 0 and <= 1)", targetFreeSpacePercentage); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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 |
* @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); | ||
} |
There was a problem hiding this comment.
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?
* @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); | |
} |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(80, new File("/tmp")); | |
* final DiskMemoryHealthChecker diskMemoryHealthChecker = HealthChecker.ofDisk(0.8, new File("/tmp")); |
f4c53c1
to
bf1bc4e
Compare
Resolved. @ikhoon , since rebasing merge your merge commit was updated to my current commit. I hope that would no change logs. Please, review it 🙇♀️ |
bf1bc4e
to
1791558
Compare
There was a problem hiding this 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 👍
core/src/main/java/com/linecorp/armeria/server/healthcheck/DiskMemoryHealthChecker.java
Show resolved
Hide resolved
1791558
to
04f40a6
Compare
Sorry for being late. Please, review it. |
04f40a6
to
7e1db1b
Compare
There was a problem hiding this 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. 😉
core/src/main/java/com/linecorp/armeria/server/healthcheck/DiskMemoryHealthChecker.java
Show resolved
Hide resolved
*/ | ||
@Override | ||
public CompletionStage<HealthCheckStatus> get() { | ||
return CompletableFuture.supplyAsync(() -> new HealthCheckStatus(isHealthy(), 500)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Motivation:
HealthChecker
implementations #1854 issue. I felt interested to solve the problem and opened this PR.Modifications:
Result:
HealthChecker
implementations #1854 issue.