X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/be4852ec32e5eeed1af9a62017cfc39ed66ac186..a3851eec63fb52c1f8121395d0092f4aff25405f:/sdk/go/keepclient/support.go diff --git a/sdk/go/keepclient/support.go b/sdk/go/keepclient/support.go index 33ba8720bc..49ef543d87 100644 --- a/sdk/go/keepclient/support.go +++ b/sdk/go/keepclient/support.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package keepclient import ( @@ -8,13 +12,11 @@ import ( "io/ioutil" "log" "math/rand" - "net" "net/http" "os" - "regexp" "strings" - "time" + "git.curoverse.com/arvados.git/sdk/go/arvadosclient" "git.curoverse.com/arvados.git/sdk/go/streamer" ) @@ -24,8 +26,7 @@ import ( var DebugPrintf = func(string, ...interface{}) {} func init() { - var matchTrue = regexp.MustCompile("^(?i:1|yes|true)$") - if matchTrue.MatchString(os.Getenv("ARVADOS_DEBUG")) { + if arvadosclient.StringBool(os.Getenv("ARVADOS_DEBUG")) { DebugPrintf = log.Printf } } @@ -44,50 +45,6 @@ func Md5String(s string) string { return fmt.Sprintf("%x", md5.Sum([]byte(s))) } -// Set timeouts applicable when connecting to non-disk services -// (assumed to be over the Internet). -func (*KeepClient) setClientSettingsNonDisk(client *http.Client) { - // Maximum time to wait for a complete response - client.Timeout = 300 * time.Second - - // TCP and TLS connection settings - client.Transport = &http.Transport{ - Dial: (&net.Dialer{ - // The maximum time to wait to set up - // the initial TCP connection. - Timeout: 30 * time.Second, - - // The TCP keep alive heartbeat - // interval. - KeepAlive: 120 * time.Second, - }).Dial, - - TLSHandshakeTimeout: 10 * time.Second, - } -} - -// Set timeouts applicable when connecting to keepstore services directly -// (assumed to be on the local network). -func (*KeepClient) setClientSettingsDisk(client *http.Client) { - // Maximum time to wait for a complete response - client.Timeout = 20 * time.Second - - // TCP and TLS connection timeouts - client.Transport = &http.Transport{ - Dial: (&net.Dialer{ - // The maximum time to wait to set up - // the initial TCP connection. - Timeout: 2 * time.Second, - - // The TCP keep alive heartbeat - // interval. - KeepAlive: 180 * time.Second, - }).Dial, - - TLSHandshakeTimeout: 4 * time.Second, - } -} - type svcList struct { Items []keepService `json:"items"` } @@ -115,8 +72,8 @@ func (this *KeepClient) uploadToKeepServer(host string, hash string, body io.Rea req.ContentLength = expectedLength if expectedLength > 0 { - // http.Client.Do will close the body ReadCloser when it is - // done with it. + // Do() will close the body ReadCloser when it is done + // with it. req.Body = body } else { // "For client requests, a value of 0 means unknown if Body is @@ -131,7 +88,7 @@ func (this *KeepClient) uploadToKeepServer(host string, hash string, body io.Rea req.Header.Add(X_Keep_Desired_Replicas, fmt.Sprint(this.Want_replicas)) var resp *http.Response - if resp, err = this.Client.Do(req); err != nil { + if resp, err = this.httpClient().Do(req); err != nil { DebugPrintf("DEBUG: [%08x] Upload failed %v error: %v", requestID, url, err.Error()) upload_status <- uploadStatus{err, url, 0, 0, ""} return