-
Notifications
You must be signed in to change notification settings - Fork 40.7k
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 auto-configuration for Micrometer DiskSpaceMetrics #26001
Add auto-configuration for Micrometer DiskSpaceMetrics #26001
Conversation
@Bean | ||
@ConditionalOnMissingBean | ||
public DiskSpaceMetrics diskSpaceMetrics() { | ||
return new DiskSpaceMetrics(new File(System.getProperty("user.dir"))); |
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.
Would we want to make this configurable? That could easily move it out of the "JVM" category if it was just some random 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.
Given how easy it is to expose it, I am not sure I would make it configurable (at least for a first version). However the disk space health indicator uses the current path (i.e. new File(".")
) so I'd rather use that.
...org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java
Outdated
Show resolved
Hide 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.
Since the validateBaseJvmMetricsBeansArePresent()
function returns the ContextConsumer
interface, it seems that the calling method needs to be changed.
...org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
...org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java
Outdated
Show resolved
Hide 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.
Thanks for the PR @bono007. I've scheduled it for our next feature release.
} | ||
|
||
private ContextConsumer<AssertableApplicationContext> validateBaseJvmMetricsBeansArePresentWithCustomBean( | ||
String customBean) { |
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 wouldn't overuse ContextConsumer
like this. The essence of the assertion is to show that a single bean of a given type is present, and the one with the custom name we've added there as well (hence it's used). By moving this to a method that takes "a bean name", the link between the two is less obvious so I don't think this abstraction improves readability.
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.
Fair enough. I will update sometime today.
@Bean | ||
@ConditionalOnMissingBean | ||
public DiskSpaceMetrics diskSpaceMetrics() { | ||
return new DiskSpaceMetrics(new File(System.getProperty("user.dir"))); |
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.
Given how easy it is to expose it, I am not sure I would make it configurable (at least for a first version). However the disk space health indicator uses the current path (i.e. new File(".")
) so I'd rather use that.
- Reverted overuse of ContextConsumer - use "." for the directory to report metrics on
Thanks again @bono007. |
My pleasure @snicoll |
@philwebb this one is a bit interesting as to where the "home" for the auto-configuration should go for "DiskSpaceMetrics". It is in the Micrometer JVM package but feels a bit more like "System" metrics.
2 reasons I landed it in the JvmMetricsAutoConfiguration:
user.dir
which is the current working directory the JVM was launched fromFixes gh-25996