pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

[feat] Authentication implementations such as AuthenticationOAuth2 should support sharing thread pools or DNS cache

Open lhotari opened this issue 3 months ago • 9 comments

Search before reporting

  • [x] I searched in the issues and found nothing similar.

Motivation

PIP-234 implementation #24790 adds support for sharing thread pools and DNS resolver/cache across multiple client instances. However, authentication implementations such as AuthenticationOAuth2 create new thread pools and DNS resolvers/caches. This isn't desired, since it would be useful to be able to share the Netty Event Loop and configure the DNS settings in the client and use them for all Pulsar client DNS lookups, at least for most common use cases.

Solution

The org.apache.pulsar.client.api.Authentication interface could be changed so that the "container" could pass a context instance with contains methods to lookup shared instances.

    /**
     * Initialize the authentication provider.
     */
    default void start(AuthenticationInitContext context) throws PulsarClientException {
        start();
    }

    /**
     * Initialize the authentication provider.
     */
    void start() throws PulsarClientException;

The AuthenticationInitContext could contain generic "getService" and "getServiceByName" methods:

public interface AuthenticationInitContext {
    <T> Optional<T> getService(Class<T> serviceClass);
    <T> Optional<T> getServiceByName(Class<T> serviceClass, String name);
}

This solution could be used to pass the Netty event loop, DNS resolver and Timer to be shared in the AuthenticationOAuth2 implementation.

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • [x] I'm willing to submit a PR!

lhotari avatar Sep 27 '25 18:09 lhotari

Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

AradhyaSharma31 avatar Oct 15 '25 19:10 AradhyaSharma31

Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

@AradhyaSharma31 Thanks for volunteering. This might not be the best way to start contributing to Pulsar, but you can always give it a try. The Pulsar Contributor guide is available at https://pulsar.apache.org/contribute/ with multiple instructions. For example:

You can join the dev channel on Pulsar Slack to coordinate work. I might not be able to respond immediately, but I usually put effort to help if someone is putting effort to contribute.

lhotari avatar Oct 15 '25 21:10 lhotari

Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

Hi, are you still working on this issue?

3pacccccc avatar Nov 26 '25 06:11 3pacccccc

Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

Hi, are you still working on this issue?

@3pacccccc Not at the moment. btw. Please also review the comment in https://github.com/apache/pulsar/pull/24944#issuecomment-3520852664 .

lhotari avatar Nov 26 '25 09:11 lhotari

Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

Hi, are you still working on this issue?

@3pacccccc Not at the moment. btw. Please also review the comment in #24944 (comment) .

@lhotari OK, I see, I'll working on this.

3pacccccc avatar Nov 26 '25 10:11 3pacccccc

Hi, I’ve completed the work for this issue. I was busy for a while, so I hadn’t pushed it yet.
If it’s still useful, I can open a PR. Let me know if I should proceed or if the current assignee is already on it.

AradhyaSharma31 avatar Nov 28 '25 06:11 AradhyaSharma31

Hi, I’ve completed the work for this issue. I was busy for a while, so I hadn’t pushed it yet. If it’s still useful, I can open a PR. Let me know if I should proceed or if the current assignee is already on it.

@AradhyaSharma31 Sure, please go ahead and open a PR. It's recommended to run tests in your own fork as the first step for larger changes, please see https://pulsar.apache.org/contribute/personal-ci/. Please also check comments at https://github.com/apache/pulsar/pull/24944#issuecomment-3520852664.

lhotari avatar Nov 28 '25 07:11 lhotari

@lhotari Thanks for the guidance. After reviewing the changes in #24944 , I see that parts of my implementation conflict with the updated OAuth2 structure. I’ll refactor my solution to align with the new code and then open the PR.

I’ve been running mock tests and Pulsar CI locally when validating changes. If there are additional checks or recommended steps I should follow, please let me know.

AradhyaSharma31 avatar Nov 28 '25 08:11 AradhyaSharma31

I’ve been running mock tests and Pulsar CI locally when validating changes. If there are additional checks or recommended steps I should follow, please let me know.

@AradhyaSharma31 Please follow the instructions in https://pulsar.apache.org/contribute/personal-ci/ to first open a PR in your own fork and run the full Pulsar CI GitHub Actions pipeline there. It's not a very feasible solution to run the full pipeline locally since it requires about 10 hours of compute time to run all tests. You get this for free with GitHub Actions.

lhotari avatar Nov 28 '25 09:11 lhotari