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

startupTimeMetrics seems to cause bean dependency cycle when a MeterBinder uses a spring data repository #30902

Open
JakobFels opened this issue May 9, 2022 · 6 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@JakobFels
Copy link

Spring Boot version: 2.6.7

We seem to be running into an issue similar to #27591.
We recently migrated one of our metric sources to use a spring data repository. This seems to cause a bean dependency cycle caused by startupTimeMetrics (See attached bean cycle screenshot).
image

If needed, I can attempt to provide a minimal reproducer, but I hope the current information is enough.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 9, 2022
@wilkinsona
Copy link
Member

If needed, I can attempt to provide a minimal reproducer, but I hope the current information is enough.

Yes, please. I have been unable to reproduce the problem from what you have described thus far.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 9, 2022
@JakobFels
Copy link
Author

While building the reproducer I noticed that the problem is caused by including spring-cloud-gcp-starter-data-firestore, with plain data-jpa I could not reproduce it as well.

I'll open an issue on that project.

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix 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 May 9, 2022
@wilkinsona
Copy link
Member

Thanks for letting me know. FWIW the dependency between serviceInstanceRepository and startupTimeMetrics looks a little unusual. If serviceInstanceRepository is a Data Firestore repository, that link is where I'd start looking.

@JakobFels
Copy link
Author

I opened a corresponding issue in the spring cloud gcp project:
GoogleCloudPlatform/spring-cloud-gcp#1113

@elefeint
Copy link

For posterity, the issue is not Firestore-specific, but adding metrics following Spring Boot docs avoids the cycle nicely.

In the reproducer, user implementation of MeterBinder inserted itself in the middle of Micrometer autoconfiguration. It also required a prerequisite service relying on a Spring Data repository, which had to get instantiated first. While instantiating the repository,
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport brings in org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor. Spring Data publishes org.springframework.data.mapping.context.MappingContextEvent when entity type is registered in RepositoryFactoryBeanSupport.afterPropertiesSet(). Because startupTimeMetrics is registered as an ApplicationListener, it has to get instantiated at that point, causing the cycle.

@elefeint
Copy link

elefeint commented Aug 9, 2022

For completeness; here is a reproducer without Firestore: https://github.com/elefeint/FirestoreMetricsReproducer/tree/h2-reproducer

@wilkinsona wilkinsona reopened this Aug 9, 2022
@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged and removed status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix labels Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants