Skip to content

Commit

Permalink
control: formatted duration for config trustengine.cache.expiration (#…
Browse files Browse the repository at this point in the history
…4417)

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 and daemon configuration files.
The `trustengine.cache` configuration block is marked as experimental
and is likely not widely used, so no transition mechanism is added.
  • Loading branch information
matzf authored Oct 16, 2023
1 parent 1a51838 commit 46b055a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions control/cmd/control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
}}
}

Expand Down
6 changes: 2 additions & 4 deletions doc/manuals/control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,9 @@ considers the following options.

Disable caching entirely.

.. option:: trustengine.cache.expiration = <int> (Default: 60000000000)
.. option:: trustengine.cache.expiration = <duration> (Default: "1m")

Expiration of cached entries in nanoseconds.

**TODO:** this should be changed to accept values in :ref:`duration format <common-conf-duration>`.
Expiration time for cached entries.

.. object:: drkey

Expand Down
1 change: 1 addition & 0 deletions private/trust/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
11 changes: 6 additions & 5 deletions private/trust/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/patrickmn/go-cache"

"github.com/scionproto/scion/pkg/private/util"
"github.com/scionproto/scion/private/config"
)

Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 46b055a

Please sign in to comment.