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

ApplicationAvailability bean is auto-configured even if a custom one is already present #34347

Conversation

acktsap
Copy link
Contributor

@acktsap acktsap commented Feb 23, 2023

Spring boot actuator autoconfigures ApplicationAvailability bean which is used in AvailabilityProbesAutoConfiguration and AvailabilityHealthContributorAutoConfiguration.

That is awesome since it automatically configures kubernetes probes in separate endpoints (liveness, readiness).

But if i want to replace ApplicationAvailability bean injected in LivenessStateHealthIndicator and ReadinessStateHealthIndicator i have to register ApplicationAvailability as @Primary since it's always registered by ApplicationAvailabilityAutoConfiguration.

This PR prevents auto-registeration of ApplicationAvailability bean when it's already present.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 23, 2023
@acktsap acktsap force-pushed the feature/application-availaility-custom branch from 198b63a to 0daf6cc Compare February 23, 2023 14:44
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.availability;
Copy link
Contributor Author

@acktsap acktsap Feb 23, 2023

Choose a reason for hiding this comment

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

Also i moved package from kubernetes to availability since it seems to make sense.

@acktsap acktsap force-pushed the feature/application-availaility-custom branch from 0daf6cc to b1ac4c3 Compare February 23, 2023 15:06
@acktsap acktsap force-pushed the feature/application-availaility-custom branch from b1ac4c3 to 6af8882 Compare February 23, 2023 16:28
@wilkinsona
Copy link
Member

Thanks, @acktsap.

Given that we have the ApplicationAvailability interface and a default implementation of it (ApplicationAvailabilityBean), it feels like a bug to me that you can't (without using @Primary) easily declare your own ApplicationAvailability implementation. That makes it tempting to schedule this for 2.7.x. It could, although I think it's very unlikely, be a breaking change if someone's relying on the current behavior where they end up with both their primary custom implementation and the default implementation co-existing. I can't think why someone would need that behavior though. Flagging for team attention in case I've overlooked something.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Feb 24, 2023
@snicoll snicoll added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Apr 11, 2023
@snicoll snicoll added this to the 2.7.x milestone Apr 11, 2023
@snicoll snicoll changed the title Prevent autoconfigure of ApplicationAvailability when already registered ApplicationAvailability bean is auto-configured even if a custom one is already present Apr 11, 2023
@snicoll snicoll self-assigned this Apr 19, 2023
@snicoll snicoll modified the milestones: 2.7.x, 2.7.11 Apr 19, 2023
@snicoll snicoll closed this in da10c4e Apr 19, 2023
@snicoll
Copy link
Member

snicoll commented Apr 19, 2023

@acktsap thank you for making your first contribution to Spring Boot.

@nickd147
Copy link

Hi All
i found in my case that after this changes
5e95ba8#diff-4520e41b59ccf0379a94bad29e96a802db342fc4a056a570db16ba0821f6b618

ApplicationAvailabilityBean is not being peaked up by DefaultListableBeanFactory
because of failing the checking

typeToMatch.isAssignableFrom(beanType)

where typeToMatch - ApplicationListener, beanType - ApplicationAvailability

in 2.7.10 it was
typeToMatch - ApplicationListener, beanType - ApplicationAvailabilityBean

and all worked well.

and as a result it's missed during publishing event in org.springframework.boot.context.event.EventPublishingRunListener#started

please check this.
to make it works in this version I need to create custom cnfiguration

@wilkinsona
Copy link
Member

@dyakovni That has been fixed by #35161.

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

Successfully merging this pull request may close these issues.

5 participants