-
Notifications
You must be signed in to change notification settings - Fork 41.6k
Add out-of-the-box health indicator for reactive MongoDB #11997
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 out-of-the-box health indicator for reactive MongoDB #11997
Conversation
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. I've made a few suggestions.
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean(MongoConverter.class) | ||
| public MappingMongoConverter mappingMongoConverter() { |
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.
How is this related to this change?
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.
It is required by “ReactiveMongoTemplate” bean while it is missing from Spring IOC factory, that is why I provided default implementation of MongoConverter here when it is missing in context, otherwise, it will complains “unsatisfied dependencies ”
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.
@qinnnyul sorry I am not following. Why is it required?
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.
@snicoll In current class, we can see “reactiveMongoTemplate” method, when it constructs instance, it needs spring to inject two type of beans(one is ReactiveMongoDatabaseFactory,another is MongoConverter), however, it only has method to construct ReactiveMongoDatabaseFactory before, another is missing. You can find the similar way in MongoDataAutoConfiguration.class, but I did not want to mix it up, that is why I added default implementation of MongoConverter here, does that make sense to you? what do you recommend?
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 saw that but this is provided by MongoDataAutoConfiguration and there isn't a reason to copy/paste that here. Can you please rework the PR so that tests also include MongoDataAutoConfiguration?
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.
See also #12001
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.
@snicoll thanks for your suggestion, but I am not sure if it is good idea to make an explicit link between MongoReactiveDataAutoConfiguration and MongoDataAutoConfiguration, cause it has different conditions. Besides that, even I tried what you suggested, it throws out the following error: “Error creating bean with name 'reactiveMongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reactiveMongoTemplate' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.mongodb.core.convert.MongoConverter' available: “
| */ | ||
|
|
||
| public class MongoReactiveHealthIndicatorTest { | ||
| @Mock |
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 don't use this construct, please mock the template in the test as you've done for the rest.
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.
completed.
| <artifactId>spring-data-mongodb</artifactId> | ||
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> |
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.
Dependencies are ordered alphabetically. Please reorder those two entries.
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.
dependencies been re-ordered.
| @ConditionalOnClass({ MongoClient.class, ReactiveMongoTemplate.class }) | ||
| @EnableConfigurationProperties(MongoProperties.class) | ||
| @AutoConfigureAfter(MongoReactiveAutoConfiguration.class) | ||
| @AutoConfigureAfter({ MongoReactiveAutoConfiguration.class, MongoDataAutoConfiguration.class }) |
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.
Please rebase your PR rather than changing something that has already been changed.
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.
done
| */ | ||
|
|
||
| public class MongoReactiveHealthIndicatorTest { | ||
| private MongoReactiveHealthIndicator mongoReactiveHealthIndicator; |
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 doesn't need to be a field
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.
done
| * | ||
| * @author Yulin Qin | ||
| */ | ||
|
|
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.
Unnecessary extra space.
| @ConditionalOnBean(ReactiveMongoTemplate.class) | ||
| @ConditionalOnEnabledHealthIndicator("mongo") | ||
| @AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) | ||
| @AutoConfigureAfter({MongoReactiveAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class}) |
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 think only the latter is necessary 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.
changed
| <optional>true</optional> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mongodb</groupId> |
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 isn't sorted properly still (m is before s)
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.
done
…tive-mongo * pr/11997: Polish "Add health indicator for reactive MongoDB" Add health indicator for reactive MongoDB
|
@qinnnyul Thanks for working on my comments. Unfortunately, the state of this PR is still poor so I decided to polish it myself rather than asking you to review again. Please review the following and take it into account for any future PR:
|
|
@snicoll thanks, will keep it in mind. |
Add out-of-the-box health indicator for reactive MongoDB and write few test cases to cover new changes. #11766