16118: Keep-web initializes its client pool from config instead of envvars.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 11 May 2020 18:26:28 +0000 (15:26 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Mon, 11 May 2020 18:26:28 +0000 (15:26 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

sdk/go/arvadosclient/pool.go
sdk/go/keepclient/discover.go
services/keep-web/handler.go

index 732080770b31bdbece62be480004b129c50cf4a4..bb7867aef7e35d283c5e47adb68873492bda609c 100644 (file)
@@ -6,6 +6,8 @@ package arvadosclient
 
 import (
        "sync"
+
+       "git.arvados.org/arvados.git/sdk/go/arvados"
 )
 
 // A ClientPool is a pool of ArvadosClients. This is useful for
@@ -14,7 +16,7 @@ import (
 // credentials. See arvados-git-httpd for an example, and sync.Pool
 // for more information about garbage collection.
 type ClientPool struct {
-       // Initialize new clients by coping this one.
+       // Initialize new clients by copying this one.
        Prototype *ArvadosClient
 
        pool      *sync.Pool
@@ -25,7 +27,20 @@ type ClientPool struct {
 // MakeClientPool returns a new empty ClientPool, using environment
 // variables to initialize the prototype.
 func MakeClientPool() *ClientPool {
-       proto, err := MakeArvadosClient()
+       return MakeClientPoolWith(nil)
+}
+
+// MakeClientPoolWith returns a new empty ClientPool with a previously
+// initialized arvados.Client.
+func MakeClientPoolWith(client *arvados.Client) *ClientPool {
+       var err error
+       var proto *ArvadosClient
+
+       if client == nil {
+               proto, err = MakeArvadosClient()
+       } else {
+               proto, err = New(client)
+       }
        return &ClientPool{
                Prototype: proto,
                lastErr:   err,
index 744ff826853895c1769a5865d8dbded75ddc1474..726c3fb30c88414cd7e3ea93841084bdfadf61f0 100644 (file)
@@ -19,7 +19,7 @@ import (
        "git.arvados.org/arvados.git/sdk/go/arvadosclient"
 )
 
-// ClearCache clears the Keep service discovery cache.
+// RefreshServiceDiscovery clears the Keep service discovery cache.
 func RefreshServiceDiscovery() {
        var wg sync.WaitGroup
        defer wg.Wait()
@@ -35,8 +35,8 @@ func RefreshServiceDiscovery() {
        }
 }
 
-// ClearCacheOnSIGHUP installs a signal handler that calls
-// ClearCache when SIGHUP is received.
+// RefreshServiceDiscoveryOnSIGHUP installs a signal handler that calls
+// RefreshServiceDiscovery when SIGHUP is received.
 func RefreshServiceDiscoveryOnSIGHUP() {
        svcListCacheMtx.Lock()
        defer svcListCacheMtx.Unlock()
index 563a59df014b8f642b545a68bc23f2e72e1a57d1..643ca4f587f51bc9b353ab29b4a82869d96578a8 100644 (file)
@@ -76,7 +76,9 @@ func parseCollectionIDFromURL(s string) string {
 }
 
 func (h *handler) setup() {
-       h.clientPool = arvadosclient.MakeClientPool()
+       // Errors will be handled at the client pool.
+       arv, _ := arvados.NewClientFromConfig(h.Config.cluster)
+       h.clientPool = arvadosclient.MakeClientPoolWith(arv)
 
        keepclient.RefreshServiceDiscoveryOnSIGHUP()
        keepclient.DefaultBlockCache.MaxBlocks = h.Config.cluster.Collections.WebDAVCache.MaxBlockEntries