Skip to content

Commit

Permalink
Add more APIs in connectionFactory to allow customizing http client (#29
Browse files Browse the repository at this point in the history
)
  • Loading branch information
xiangfu0 committed Feb 1, 2024
1 parent 615f2d0 commit 4b5baf2
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pinot/connectionFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,58 @@ const (

// NewFromBrokerList create a new Pinot connection with pre configured Pinot Broker list.
func NewFromBrokerList(brokerList []string) (*Connection, error) {
return NewFromBrokerListAndClient(brokerList, http.DefaultClient)
}

// NewFromBrokerListAndClient create a new Pinot connection with pre configured Pinot Broker list and http client.
func NewFromBrokerListAndClient(brokerList []string, httpClient *http.Client) (*Connection, error) {
clientConfig := &ClientConfig{
BrokerList: brokerList,
}
return NewWithConfig(clientConfig)
return NewWithConfigAndClient(clientConfig, httpClient)
}

// NewFromZookeeper create a new Pinot connection through Pinot Zookeeper.
func NewFromZookeeper(zkPath []string, zkPathPrefix string, pinotCluster string) (*Connection, error) {
return NewFromZookeeperAndClient(zkPath, zkPathPrefix, pinotCluster, http.DefaultClient)
}

// NewFromZookeeperAndClient create a new Pinot connection through Pinot Zookeeper and http client.
func NewFromZookeeperAndClient(zkPath []string, zkPathPrefix string, pinotCluster string, httpClient *http.Client) (*Connection, error) {
clientConfig := &ClientConfig{
ZkConfig: &ZookeeperConfig{
ZookeeperPath: zkPath,
PathPrefix: strings.Join([]string{zkPathPrefix, pinotCluster}, "/"),
SessionTimeoutSec: defaultZkSessionTimeoutSec,
},
}
return NewWithConfig(clientConfig)
return NewWithConfigAndClient(clientConfig, httpClient)
}

// NewFromController creates a new Pinot connection that periodically fetches available brokers via the Controller API.
func NewFromController(controllerAddress string) (*Connection, error) {
return NewFromControllerAndClient(controllerAddress, http.DefaultClient)
}

// NewFromControllerAndClient creates a new Pinot connection that periodically fetches available brokers via the Controller API.
func NewFromControllerAndClient(controllerAddress string, httpClient *http.Client) (*Connection, error) {
clientConfig := &ClientConfig{
ControllerConfig: &ControllerConfig{
ControllerAddress: controllerAddress,
},
}
return NewWithConfig(clientConfig)
return NewWithConfigAndClient(clientConfig, httpClient)
}

// NewWithConfig create a new Pinot connection.
func NewWithConfig(config *ClientConfig) (*Connection, error) {
return NewWithConfigAndClient(config, http.DefaultClient)
}

// NewWithConfigAndClient create a new Pinot connection with pre-created http client.
func NewWithConfigAndClient(config *ClientConfig, httpClient *http.Client) (*Connection, error) {
transport := &jsonAsyncHTTPClientTransport{
client: http.DefaultClient,
client: httpClient,
header: config.ExtraHTTPHeader,
}

Expand Down

0 comments on commit 4b5baf2

Please sign in to comment.