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

Add support for multiple paths to DiskSpaceMetrics #2747

Closed

Conversation

onobc
Copy link
Contributor

@onobc onobc commented Aug 14, 2021

What

This code proposal will allow consumers to add disk space metrics to multiple paths.

Why

SpringBoot auto-configures a DiskSpaceMetrics and also has a DiskSpaceHealthContributor. There is a desire to keep their configurability in parity.

The health contributor has a request to support multiple paths. The first attempted proposal was closed quite some time ago due to concern of breaking actuator output compatibility (root disk threshold values vs. child path thresholds etc.). I intend to get a 2nd attempt going now that a breaking change should be ok in a minor version bump (2.6).

This change to DiskSpaceMetrics will be followed with an update to JvmMetricsAutoConfiguration to allow configuration of multiple paths.

public DiskSpaceMetrics(List<File> paths) {
this(paths, emptyList());
}

public DiskSpaceMetrics(File path, Iterable<Tag> tags) {
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 was hoping to not add 2 new constructors by editing the existing ones and changing their single path param to a varargs path param. That approach came up short w/ this particular <init> as varargs has to be the last in param list.

I am open to suggestions. I think a builder would be overkill. What are thoughts on deprecation of the single path <init> variants?

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

If a user wants disk space metrics for multiple paths, wouldn't binding multiple DiskSpaceMetrics make sense? What is the benefit of the proposed changes over that approach?
Not that it necessarily matters, but I would think a single path is sufficient for most users.

@shakuzen shakuzen added the waiting for feedback We need additional information before we can continue label Aug 18, 2021
@onobc
Copy link
Contributor Author

onobc commented Aug 20, 2021

If a user wants disk space metrics for multiple paths, wouldn't binding multiple DiskSpaceMetrics make sense? What is the benefit of the proposed changes over that approach?
Not that it necessarily matters, but I would think a single path is sufficient for most users.

The main reason of going w/ this approach is to keep the auto-config simple by not having to dynamically register N beans as the paths will be config property driven.

IOW, doing this

	@Bean
	@ConditionalOnMissingBean
	public DiskSpaceMetrics diskSpaceMetrics() {
		return new DiskSpaceMetrics(props.getListOfPaths());
	}

is much simpler than creating an ApplicationContextInitializer (or other means) and registering N of the metrics dynamically via something like

props.getListOfPaths().forEach(path -> {
   context.registerBean("diskSpaceMetrics" + i, DiskSpaceMetrics.class,
                () -> new DiskSpaceMetrics(new File(path)));
}

@onobc onobc force-pushed the diskspace-metrics-multiple-paths branch from d420976 to 2662ce7 Compare August 20, 2021 17:00
@onobc
Copy link
Contributor Author

onobc commented Aug 20, 2021

@shakuzen I rebased to pickup the move to the system package.

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

I think we're okay to accept this. I saw in the Spring Boot pull request another proposal was made that wouldn't need these changes. Let us know.

private final Iterable<Tag> tags;
private final File path;
private final String absolutePath;
private final List<File> paths;
Copy link
Member

Choose a reason for hiding this comment

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

We could be less specific than List since we don't care about order. How about Collection?


public DiskSpaceMetrics(File path) {
this(path, emptyList());
}

public DiskSpaceMetrics(List<File> paths) {
Copy link
Member

Choose a reason for hiding this comment

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

While mostly intuitive, a JavaDoc would be nice. I know we're missing one on the existing constructors - I can follow-up with adding that separately. In the case of this constructor, the paths should be to different partitions, since there's no point getting the same information about the same partition for different paths on that partition.

@onobc
Copy link
Contributor Author

onobc commented Aug 24, 2021

I think we're okay to accept this. I saw in the Spring Boot pull request another proposal was made that wouldn't need these changes. Let us know.

Thanks @shakuzen. Yeh, we are going to handle the multi-paths on the Spring Boot side in a MeterBinder impl that will bind the N DiskSpaceMetrics (your original thought about the impl).

@onobc onobc closed this Aug 24, 2021
@onobc
Copy link
Contributor Author

onobc commented Aug 24, 2021

@shakuzen if you think this could be valuable for others then I don't mind making the suggested changes and re-opening. Just let me know.

@jonatan-ivanov
Copy link
Member

For the sake of discoverability, the involved Spring Boot PR that will create DiskSpaceMetrics instances: spring-projects/spring-boot#27660

@shakuzen
Copy link
Member

if you think this could be valuable for others then I don't mind making the suggested changes and re-opening. Just let me know.

We haven't had a request for it until this. That could partially be due to DiskSpaceMetrics not being auto-configured in Spring Boot until recently. If other users are interested, we can re-visit this. I'd rather see requests from users for this than me assume it's something many users want.

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

Successfully merging this pull request may close these issues.

3 participants