From 3d1cc70b51c6a4b6788963b064c646cba102e359 Mon Sep 17 00:00:00 2001 From: Matthias Frei Date: Tue, 10 Oct 2023 13:37:33 +0200 Subject: [PATCH] control: formatted duration for config trustengine.cache.expiration The `trustengine.cache.expiration` configuration option would accept durations as number of nanoseconds. Most likely, this was accidental, all other configuration options for durations accept formatted duration strings, with unit suffix. Change `trustengine.cache.expiration` to accept (only) formatted duration strings. This is a potentially compatibility breaking change for existing control service configuration files. The `trustengine.cache` configuration block is marked as experimental and is likely not widely used, so no transition mechanism is added. --- control/cmd/control/main.go | 4 ++-- daemon/cmd/daemon/main.go | 4 ++-- doc/manuals/control.rst | 6 ++---- private/trust/config/BUILD.bazel | 1 + private/trust/config/config.go | 11 ++++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/control/cmd/control/main.go b/control/cmd/control/main.go index 8c01a43a3d..0be35b0b51 100644 --- a/control/cmd/control/main.go +++ b/control/cmd/control/main.go @@ -271,7 +271,7 @@ func realMain(ctx context.Context) error { DB: trustDB, }, CacheHits: cacheHits, - MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration, + MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration.Duration, Cache: trustengineCache, } provider := trust.FetchingProvider{ @@ -288,7 +288,7 @@ func realMain(ctx context.Context) error { Verifier: trust.Verifier{ Engine: provider, CacheHits: cacheHits, - MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration, + MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration.Duration, Cache: trustengineCache, }, } diff --git a/daemon/cmd/daemon/main.go b/daemon/cmd/daemon/main.go index a8ec8ca521..ded6ef1106 100644 --- a/daemon/cmd/daemon/main.go +++ b/daemon/cmd/daemon/main.go @@ -156,7 +156,7 @@ func realMain(ctx context.Context) error { Inspector: engine.Inspector, Cache: globalCfg.TrustEngine.Cache.New(), CacheHits: metrics.NewPromCounter(trustmetrics.CacheHitsTotal), - MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration, + MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration.Duration, } trcLoader := periodic.Start(periodic.Func{ Task: func(ctx context.Context) { @@ -247,7 +247,7 @@ func realMain(ctx context.Context) error { Engine: engine, Cache: globalCfg.TrustEngine.Cache.New(), CacheHits: metrics.NewPromCounter(trustmetrics.CacheHitsTotal), - MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration, + MaxCacheExpiration: globalCfg.TrustEngine.Cache.Expiration.Duration, }} } diff --git a/doc/manuals/control.rst b/doc/manuals/control.rst index 310a3bdcc6..5855abfd18 100644 --- a/doc/manuals/control.rst +++ b/doc/manuals/control.rst @@ -315,11 +315,9 @@ considers the following options. Disable caching entirely. - .. option:: trustengine.cache.expiration = (Default: 60000000000) + .. option:: trustengine.cache.expiration = (Default: "1m") - Expiration of cached entries in nanoseconds. - - **TODO:** this should be changed to accept values in :ref:`duration format `. + Expiration time for cached entries. .. object:: drkey diff --git a/private/trust/config/BUILD.bazel b/private/trust/config/BUILD.bazel index 7dbe003d22..4e794eed9b 100644 --- a/private/trust/config/BUILD.bazel +++ b/private/trust/config/BUILD.bazel @@ -6,6 +6,7 @@ go_library( importpath = "github.com/scionproto/scion/private/trust/config", visibility = ["//visibility:public"], deps = [ + "//pkg/private/util:go_default_library", "//private/config:go_default_library", "@com_github_patrickmn_go_cache//:go_default_library", ], diff --git a/private/trust/config/config.go b/private/trust/config/config.go index 35df7d2f16..43ac04ed48 100644 --- a/private/trust/config/config.go +++ b/private/trust/config/config.go @@ -20,6 +20,7 @@ import ( "github.com/patrickmn/go-cache" + "github.com/scionproto/scion/pkg/private/util" "github.com/scionproto/scion/private/config" ) @@ -47,20 +48,20 @@ func (cfg *Config) ConfigName() string { } type Cache struct { - Disable bool `toml:"disable,omitempty"` - Expiration time.Duration `toml:"expiration,omitempty"` + Disable bool `toml:"disable,omitempty"` + Expiration util.DurWrap `toml:"expiration,omitempty"` } func (cfg *Cache) New() *cache.Cache { if cfg.Disable { return nil } - return cache.New(cfg.Expiration, time.Minute) + return cache.New(cfg.Expiration.Duration, time.Minute) } func (cfg *Cache) InitDefaults() { - if cfg.Expiration == 0 { - cfg.Expiration = defaultExpiration + if cfg.Expiration.Duration == 0 { + cfg.Expiration.Duration = defaultExpiration } }