Skip to content

Add customizers to R2DBC ProxyConnectionFactory / ConnectionFactoryDecorator #40010

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

Closed
pauljohe-dnb opened this issue Mar 18, 2024 · 4 comments
Closed
Labels
status: superseded An issue that has been superseded by another

Comments

@pauljohe-dnb
Copy link

pauljohe-dnb commented Mar 18, 2024

Would it be possible to make it easy to apply customizers to R2DBC observability?

For example, consider this fuctional interface:

@FunctionalInterface
public interface ProxyConnectionFactoryBuilderCustomizer {
    void customize(ConnectionFactory connectionFactory, ProxyConnectionFactory.Builder builder);
}

The current listener org.springframework.boot.actuate.autoconfigure.r2dbc.R2dbcObservationAutoConfiguration could be re-written:

@Bean
ConnectionFactoryDecorator connectionFactoryDecorator(ObjectProvider<ProxyConnectionFactoryBuilderCustomizer> customizers) {
    return (connectionFactory) -> {
        var builder = ProxyConnectionFactory.builder(connectionFactory);
        customizers.forEach(customizer -> customizer.customize(connectionFactory, builder));
        return builder.build();
    };
}

@Bean
@ConditionalOnBean(ObservationRegistry.class)
ProxyConnectionFactoryBuilderCustomizer connectionObserver(R2dbcObservationProperties properties,
                                                           ObservationRegistry observationRegistry,
                                                           ObjectProvider<QueryObservationConvention> queryObservationConvention,
                                                           ObjectProvider<QueryParametersTagProvider> queryParametersTagProvider) {
    return (connectionFactory, builder) -> {
        HostAndPort hostAndPort = extractHostAndPort(connectionFactory);
        ObservationProxyExecutionListener listener = new ObservationProxyExecutionListener(observationRegistry,
                connectionFactory, hostAndPort.host(), hostAndPort.port());
        listener.setIncludeParameterValues(properties.isIncludeParameterValues());
        queryObservationConvention.ifAvailable(listener::setQueryObservationConvention);
        queryParametersTagProvider.ifAvailable(listener::setQueryParametersTagProvider);
        builder.listener(listener);
    };
}

With this pattern, it is very easy for other applications to apply their own listeners and customizations to the ProxyConnectionFactory initalization.

@philwebb
Copy link
Member

Thanks for the suggestion @pauljohe-dnb. We generally like the idea of a customizer, although having one that accepts two parameters isn't that common.

@ttddyy Is there anything we could get changed in ProxyConnectionFactory.Builder to help remove the need to pass in the ConnectionFactory? Perhaps a getter on the builder for connectionFactory or an alternative listener method that takes a Factory<ConnectionFactory, ProxyExecutionListener>?

@philwebb philwebb added type: enhancement A general enhancement status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Apr 25, 2024
@philwebb philwebb added this to the 3.x milestone Apr 25, 2024
@ttddyy
Copy link
Contributor

ttddyy commented Apr 26, 2024

Perhaps a getter on the builder for connectionFactory

@philwebb Yeah, usually builder doesn't have getters to expose the inside objects, but I do see a value here; so, I can add getters to the builder.

@ttddyy
Copy link
Contributor

ttddyy commented Apr 27, 2024

@philwebb I have released r2dbc-proxy 1.1.5.RELEASE which now has getters on the builder.

@philwebb
Copy link
Member

philwebb commented May 2, 2024

Closing in favor of PR #40555. Thanks @ttddyy!

@philwebb philwebb closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2024
@philwebb philwebb added status: superseded An issue that has been superseded by another and removed type: enhancement A general enhancement status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels May 2, 2024
@philwebb philwebb removed this from the 3.x milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

4 participants