Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

control: formatted duration for config trustengine.cache.expiration #4417

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading