Skip to content

Commit 1d44723

Browse files
committed
move the http client instance to the cloudfetch config
1 parent 510c08b commit 1d44723

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

connector.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ func WithAuthenticator(authr auth.Authenticator) ConnOption {
260260
func WithTransport(t http.RoundTripper) ConnOption {
261261
return func(c *config.Config) {
262262
c.Transport = t
263+
264+
if c.CloudFetchConfig.HTTPClient == nil {
265+
c.CloudFetchConfig.HTTPClient = &http.Client{
266+
Transport: t,
267+
}
268+
}
263269
}
264270
}
265271

connector_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func TestNewConnector(t *testing.T) {
4848
MaxFilesInMemory: 10,
4949
MinTimeToExpiry: 0 * time.Second,
5050
CloudFetchSpeedThresholdMbps: 0.1,
51+
HTTPClient: &http.Client{Transport: roundTripper},
5152
}
5253
expectedUserConfig := config.UserConfig{
5354
Host: host,
@@ -246,6 +247,25 @@ func TestNewConnector(t *testing.T) {
246247
require.True(t, ok)
247248
assert.False(t, coni.cfg.EnableMetricViewMetadata)
248249
})
250+
251+
t.Run("Connector test WithTransport sets HTTPClient in CloudFetchConfig", func(t *testing.T) {
252+
host := "databricks-host"
253+
accessToken := "token"
254+
httpPath := "http-path"
255+
customTransport := &http.Transport{MaxIdleConns: 10}
256+
con, err := NewConnector(
257+
WithServerHostname(host),
258+
WithAccessToken(accessToken),
259+
WithHTTPPath(httpPath),
260+
WithTransport(customTransport),
261+
)
262+
assert.Nil(t, err)
263+
264+
coni, ok := con.(*connector)
265+
require.True(t, ok)
266+
assert.NotNil(t, coni.cfg.CloudFetchConfig.HTTPClient)
267+
assert.Equal(t, customTransport, coni.cfg.CloudFetchConfig.HTTPClient.Transport)
268+
})
249269
}
250270

251271
type mockRoundTripper struct{}

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ type CloudFetchConfig struct {
479479
MaxFilesInMemory int
480480
MinTimeToExpiry time.Duration
481481
CloudFetchSpeedThresholdMbps float64 // Minimum download speed in MBps before WARN logging (default: 0.1)
482-
Transport http.RoundTripper
482+
HTTPClient *http.Client
483483
}
484484

485485
func (cfg CloudFetchConfig) WithDefaults() CloudFetchConfig {

internal/rows/arrowbased/batchloader.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ func NewCloudIPCStreamIterator(
3434
startRowOffset int64,
3535
cfg *config.Config,
3636
) (IPCStreamIterator, dbsqlerr.DBError) {
37-
transport := cfg.UserConfig.Transport
3837
httpClient := http.DefaultClient
39-
if transport != nil {
40-
httpClient = &http.Client{
41-
Transport: transport,
42-
}
38+
if cfg.UserConfig.CloudFetchConfig.HTTPClient != nil {
39+
httpClient = cfg.UserConfig.CloudFetchConfig.HTTPClient
4340
}
4441

4542
bi := &cloudIPCStreamIterator{

internal/rows/arrowbased/batchloader_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,21 @@ func TestCloudFetchIterator(t *testing.T) {
254254
assert.ErrorContains(t, err3, fmt.Sprintf("%s %d", "HTTP error", http.StatusNotFound))
255255
})
256256

257-
t.Run("should use custom Transport when provided", func(t *testing.T) {
257+
t.Run("should use custom HTTPClient when provided", func(t *testing.T) {
258258
handler = func(w http.ResponseWriter, r *http.Request) {
259259
w.WriteHeader(http.StatusOK)
260260
w.Write(generateMockArrowBytes(generateArrowRecord()))
261261
}
262262

263263
startRowOffset := int64(100)
264-
customTransport := &http.Transport{MaxIdleConns: 10}
264+
customHTTPClient := &http.Client{
265+
Transport: &http.Transport{MaxIdleConns: 10},
266+
}
265267

266268
cfg := config.WithDefaults()
267269
cfg.UseLz4Compression = false
268270
cfg.MaxDownloadThreads = 1
269-
cfg.UserConfig.Transport = customTransport
271+
cfg.UserConfig.CloudFetchConfig.HTTPClient = customHTTPClient
270272

271273
bi, err := NewCloudBatchIterator(
272274
context.Background(),
@@ -282,16 +284,15 @@ func TestCloudFetchIterator(t *testing.T) {
282284
assert.Nil(t, err)
283285

284286
cbi := bi.(*batchIterator).ipcIterator.(*cloudIPCStreamIterator)
285-
assert.NotNil(t, cbi.httpClient)
286-
assert.Equal(t, customTransport, cbi.httpClient.Transport)
287+
assert.Equal(t, customHTTPClient, cbi.httpClient)
287288

288289
// Verify fetch works
289290
sab, nextErr := bi.Next()
290291
assert.Nil(t, nextErr)
291292
assert.NotNil(t, sab)
292293
})
293294

294-
t.Run("should fallback to http.DefaultClient when Transport is nil", func(t *testing.T) {
295+
t.Run("should fallback to http.DefaultClient when HTTPClient is nil", func(t *testing.T) {
295296
handler = func(w http.ResponseWriter, r *http.Request) {
296297
w.WriteHeader(http.StatusOK)
297298
w.Write(generateMockArrowBytes(generateArrowRecord()))
@@ -301,6 +302,8 @@ func TestCloudFetchIterator(t *testing.T) {
301302
cfg := config.WithDefaults()
302303
cfg.UseLz4Compression = false
303304
cfg.MaxDownloadThreads = 1
305+
// Explicitly set HTTPClient to nil to verify fallback behavior
306+
cfg.UserConfig.CloudFetchConfig.HTTPClient = nil
304307

305308
bi, err := NewCloudBatchIterator(
306309
context.Background(),

0 commit comments

Comments
 (0)