18051: Add logging capability to webdav cache.
authorTom Clegg <tom@curii.com>
Wed, 15 Sep 2021 19:45:40 +0000 (15:45 -0400)
committerTom Clegg <tom@curii.com>
Wed, 15 Sep 2021 19:48:08 +0000 (15:48 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/keep-web/cache.go
services/keep-web/cache_test.go
services/keep-web/handler_test.go
services/keep-web/main.go
services/keep-web/server_test.go
services/keep-web/status_test.go

index 16fbd0788cb3840f299d649aa73378aae579fce1..ee61d13449d0d14d8a3daba0d78bfe8e8d2b9d3e 100644 (file)
@@ -14,6 +14,7 @@ import (
        "git.arvados.org/arvados.git/sdk/go/keepclient"
        lru "github.com/hashicorp/golang-lru"
        "github.com/prometheus/client_golang/prometheus"
+       "github.com/sirupsen/logrus"
 )
 
 const metricsUpdateInterval = time.Second / 10
@@ -21,6 +22,7 @@ const metricsUpdateInterval = time.Second / 10
 type cache struct {
        cluster     *arvados.Cluster
        config      *arvados.WebDAVCacheConfig // TODO: use cluster.Collections.WebDAV instead
+       logger      logrus.FieldLogger
        registry    *prometheus.Registry
        metrics     cacheMetrics
        pdhs        *lru.TwoQueueCache
index 80e00b02ad5c962ec7674b82449ee18cf6ddac63..3e2faaff726ed52e45991fc9f50d3b986672e001 100644 (file)
@@ -10,6 +10,7 @@ import (
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/arvadosclient"
        "git.arvados.org/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/ctxlog"
        "github.com/prometheus/client_golang/prometheus"
        "github.com/prometheus/common/expfmt"
        "gopkg.in/check.v1"
@@ -33,7 +34,7 @@ func (s *UnitSuite) TestCache(c *check.C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, check.Equals, nil)
 
-       cache := newConfig(s.Config).Cache
+       cache := newConfig(ctxlog.TestLogger(c), s.Config).Cache
        cache.registry = prometheus.NewRegistry()
 
        // Hit the same collection 5 times using the same token. Only
@@ -110,7 +111,7 @@ func (s *UnitSuite) TestCacheForceReloadByPDH(c *check.C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, check.Equals, nil)
 
-       cache := newConfig(s.Config).Cache
+       cache := newConfig(ctxlog.TestLogger(c), s.Config).Cache
        cache.registry = prometheus.NewRegistry()
 
        for _, forceReload := range []bool{false, true, false, true} {
@@ -129,7 +130,7 @@ func (s *UnitSuite) TestCacheForceReloadByUUID(c *check.C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, check.Equals, nil)
 
-       cache := newConfig(s.Config).Cache
+       cache := newConfig(ctxlog.TestLogger(c), s.Config).Cache
        cache.registry = prometheus.NewRegistry()
 
        for _, forceReload := range []bool{false, true, false, true} {
index a74b85b98da6d7657b85906cb3729d865b073d67..55c122b0ff7123ba4eb1c670900a5d3c6b5c4dba 100644 (file)
@@ -50,7 +50,7 @@ func (s *UnitSuite) SetUpTest(c *check.C) {
 }
 
 func (s *UnitSuite) TestCORSPreflight(c *check.C) {
-       h := handler{Config: newConfig(s.Config)}
+       h := handler{Config: newConfig(ctxlog.TestLogger(c), s.Config)}
        u := mustParseURL("http://keep-web.example/c=" + arvadostest.FooCollection + "/foo")
        req := &http.Request{
                Method:     "OPTIONS",
@@ -109,7 +109,7 @@ func (s *UnitSuite) TestEmptyResponse(c *check.C) {
                        c.Assert(err, check.IsNil)
                }
 
-               h := handler{Config: newConfig(s.Config)}
+               h := handler{Config: newConfig(ctxlog.TestLogger(c), s.Config)}
                u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo")
                req := &http.Request{
                        Method:     "GET",
@@ -159,7 +159,7 @@ func (s *UnitSuite) TestInvalidUUID(c *check.C) {
                        RequestURI: u.RequestURI(),
                }
                resp := httptest.NewRecorder()
-               cfg := newConfig(s.Config)
+               cfg := newConfig(ctxlog.TestLogger(c), s.Config)
                cfg.cluster.Users.AnonymousUserToken = arvadostest.AnonymousToken
                h := handler{Config: cfg}
                h.ServeHTTP(resp, req)
@@ -1241,7 +1241,7 @@ func (s *IntegrationSuite) checkUploadDownloadRequest(c *check.C, h *handler, re
 }
 
 func (s *IntegrationSuite) TestDownloadLoggingPermission(c *check.C) {
-       config := newConfig(s.ArvConfig)
+       config := newConfig(ctxlog.TestLogger(c), s.ArvConfig)
        h := handler{Config: config}
        u := mustParseURL("http://" + arvadostest.FooCollection + ".keep-web.example/foo")
 
@@ -1314,7 +1314,7 @@ func (s *IntegrationSuite) TestDownloadLoggingPermission(c *check.C) {
 }
 
 func (s *IntegrationSuite) TestUploadLoggingPermission(c *check.C) {
-       config := newConfig(s.ArvConfig)
+       config := newConfig(ctxlog.TestLogger(c), s.ArvConfig)
        h := handler{Config: config}
 
        for _, adminperm := range []bool{true, false} {
index a62e0abb667ca5211994211e9f401c271e2e5b5b..a9ac834a20cedf21f80fcc5e9a7742f86bb0e812 100644 (file)
@@ -29,7 +29,7 @@ type Config struct {
        cluster *arvados.Cluster
 }
 
-func newConfig(arvCfg *arvados.Config) *Config {
+func newConfig(logger logrus.FieldLogger, arvCfg *arvados.Config) *Config {
        cfg := Config{}
        var cls *arvados.Cluster
        var err error
@@ -39,6 +39,7 @@ func newConfig(arvCfg *arvados.Config) *Config {
        cfg.cluster = cls
        cfg.Cache.config = &cfg.cluster.Collections.WebDAVCache
        cfg.Cache.cluster = cls
+       cfg.Cache.logger = logger
        return &cfg
 }
 
@@ -81,7 +82,7 @@ func configure(logger log.FieldLogger, args []string) *Config {
        if err != nil {
                log.Fatal(err)
        }
-       cfg := newConfig(arvCfg)
+       cfg := newConfig(logger, arvCfg)
 
        if *dumpConfig {
                out, err := yaml.Marshal(cfg)
index d592295209b3c0599147b672090eadc81dc36274..54e9ddf3704d606a14c2b8965c1bf611cacb76bd 100644 (file)
@@ -433,7 +433,7 @@ func (s *IntegrationSuite) SetUpTest(c *check.C) {
        ldr.Path = "-"
        arvCfg, err := ldr.Load()
        c.Check(err, check.IsNil)
-       cfg := newConfig(arvCfg)
+       cfg := newConfig(ctxlog.TestLogger(c), arvCfg)
        c.Assert(err, check.IsNil)
        cfg.Client = arvados.Client{
                APIHost:  testAPIHost,
index 1b6ad93de7dd2207c97a56a8e6ff0365391b09b0..f90f85cd93691c1fa8ed389b6a48bb17d7e7c376 100644 (file)
@@ -11,11 +11,12 @@ import (
        "net/url"
 
        "git.arvados.org/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/ctxlog"
        "gopkg.in/check.v1"
 )
 
 func (s *UnitSuite) TestStatus(c *check.C) {
-       h := handler{Config: newConfig(s.Config)}
+       h := handler{Config: newConfig(ctxlog.TestLogger(c), s.Config)}
        u, _ := url.Parse("http://keep-web.example/status.json")
        req := &http.Request{
                Method:     "GET",