-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Provide health for an AbstractRoutingDataSource's resolved targets #25708
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
Conversation
@@ -64,8 +71,7 @@ | |||
@ConditionalOnEnabledHealthIndicator("db") | |||
@AutoConfigureAfter(DataSourceAutoConfiguration.class) | |||
@EnableConfigurationProperties(DataSourceHealthIndicatorProperties.class) | |||
public class DataSourceHealthContributorAutoConfiguration extends | |||
CompositeHealthContributorConfiguration<AbstractHealthIndicator, DataSource> implements InitializingBean { |
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 broke out of the CHCC hierarchy as this stretched that contract a bit too much. We need the createIndicator
to return HealthContributor
rather than AbstractHealthIndicator
to allow for the case where one of the datasource beans is actual the AbstractRoutingDataSource which in turn is composite contributor.
Function<DataSource, HealthContributor> indicatorFunction) { | ||
Map<String, DataSource> routedDataSources = routingDataSource.getResolvedDataSources().entrySet().stream() | ||
.collect(toMap((e) -> e.getKey().toString(), Map.Entry::getValue)); | ||
delegate = CompositeHealthContributor.fromMap(routedDataSources, indicatorFunction); |
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.
We could have simply returned this CompositeHealthContributor.fromMap(routedDataSources, indicatorFunction)
from here and not created a 1st class type for it. However, having the RoutingDataSourceHealthIndicator
is helpful for testing as well as for future extensions to the indicator when/if needed.
@wilkinsona not sure if this is what you had in mind - let me know where we need to adjust. I have a couple of points/questions/caveats to discuss as well. Relies on metadataprovider
I have since figured out this is not an issue as described here
Duplicate indicatorsIf a routed datasource is also a registered
One edge case on option 2 is when one of the routed datasources is already covered but another is not. Would we ignore only the covered target datasource in the routing health indicator? That would be strange. I am inclined to go w/ option 1. I am curious to hear others thoughts as well. |
This looks great. Thank you, @Bono007.
Agreed. I think this is the better option.
Agreed again. When looking at the main code I was tempted to get rid of it, but having looked at the tests I think it's useful to have the distinction. It's also a package-private implementation detail so we can refine in the future as needed without worrying about backwards compatibility. |
Fixes gh-22824