Skip to content

Conversation

@qinnnyul
Copy link
Contributor

Add out-of-the-box health indicator for reactive MongoDB and write few test cases to cover new changes. #11766

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 12, 2018
Copy link
Member

@snicoll snicoll left a 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() {
Copy link
Member

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?

Copy link
Contributor Author

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 ”

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

See also #12001

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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>
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dependencies been re-ordered.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Feb 12, 2018
@ConditionalOnClass({ MongoClient.class, ReactiveMongoTemplate.class })
@EnableConfigurationProperties(MongoProperties.class)
@AutoConfigureAfter(MongoReactiveAutoConfiguration.class)
@AutoConfigureAfter({ MongoReactiveAutoConfiguration.class, MongoDataAutoConfiguration.class })
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*
* @author Yulin Qin
*/

Copy link
Member

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})
Copy link
Member

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.

Copy link
Contributor Author

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>
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@snicoll snicoll self-assigned this Feb 13, 2018
@snicoll snicoll added type: enhancement A general enhancement priority: normal and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Feb 13, 2018
@snicoll snicoll added this to the 2.0.0.RC2 milestone Feb 13, 2018
snicoll pushed a commit that referenced this pull request Feb 13, 2018
@snicoll snicoll closed this in 28f5392 Feb 13, 2018
snicoll added a commit that referenced this pull request Feb 13, 2018
…tive-mongo

* pr/11997:
  Polish "Add health indicator for reactive MongoDB"
  Add health indicator for reactive MongoDB
@snicoll
Copy link
Member

snicoll commented Feb 13, 2018

@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:

  • The PR wasn't properly rebased on master. You can run git rebase origin/master on your branch once you've pulled the latest change (git fetch origin). Some conflicts needed to be fixed. Once that's done, please squash your commit into one and push force on your branch
  • The build did not pass. Did you run it? Some tests were failing because the reactive driver wasn't available. Once I added it, other tests start failing as they didn't expect reactive mongo to be there
  • The reactive health indicator wasn't shadowing the "regular" health indicator so an app with the reactive mongo driver had two health indicators for MongoDB. You wrote a test that was supposed to exercise that but it wasn't importing the regular mongo auto-configuration. Once I added that, it failed
  • reactive health indicators are listed in the doc

@qinnnyul qinnnyul deleted the add-health-indicator-for-reactive-mongo branch February 13, 2018 11:32
@qinnnyul
Copy link
Contributor Author

@snicoll thanks, will keep it in mind.

@qinnnyul qinnnyul restored the add-health-indicator-for-reactive-mongo branch February 13, 2018 12:03
@qinnnyul qinnnyul deleted the add-health-indicator-for-reactive-mongo branch February 13, 2018 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants