Open yupeng9 opened 2 years ago
+1
ControllerRequestURLBuilder
contains most of the APIs. We can probably wrap it into a library
Agreed that this will be a useful thing.
We will just have to pay more attention to a few things then:
As long as we are wiling to bear the cost, I am all for this feature.
+1 for this proposal. I am also working on factoring out the helper functions from ControllerTestUtils.
Here is what I proposed to do, please kindly let me know if this is the right track:
*RestResource
in controller/broker have internal static functions to do send request and parse responses)Any suggestions? I will create an example PR to demonstrate what I meant soon
see: #8293 for demonstration of the refactoring
[update] #8329 is the new POC, for several reasons
URLConnection
, HTTPClient seems a better choice (see: https://www.mocklab.io/blog/which-java-http-client-should-i-use-in-2020/)Currently there are many ad-hoc usage/utils that makes http call to Pinot components, to name a few
ControllerTestUtils
that uses URLConnection
to Controller
HTTPClient
from Apache HTTP module for 2 of the multi-part requestHTTPClient
with SSLContext supportThere are discrepancies regarding (1) what's the format of the send data / return; (2) what type of return code throws exception or encapsulate the exception in the response code; (3) what default header is being used.
What's more, there are inefficiency in HTTPClient usage: in general HTTPClient should be used as a singleton and leverage the underlying resource reused benefit.
Propose to
update on status: with #8329 and #8390 contributed. item 1 and 3 is almost finished.
we can now: add functionalities to ControllerRequestClient
and create Server/BrokerRequestClients
.
there are other places where either java.net.*
or apache.http.*
is directly used, I propose to create a separate ticket to track the migration of these usages as they are (1) many and scattered around the codebase and might not make sense to migrate all; (2) mostly will be migrated over when security/auth is enabled for example QueryRunner now doesn't support auth token.
It will be very helpful to have a library for the common REST APIs for Controller/Broker/Server. There are a number of existing methods/helpers in the code repo, such as in the test utils or connector for this purpose. But those are adhoc and not comprehensive.