From b0fa917eae868b819f081290f6e0ab8159792d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 12 Sep 2022 14:05:24 +0000 Subject: [PATCH] enable a 300sec in memory cache for resource infos when listing shares on the ocs API (#4438) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enable a 300sec in memory cache for resource infos when listing shares on the ocs API Signed-off-by: Jörn Friedrich Dreyer * lint Signed-off-by: Jörn Friedrich Dreyer * disable ocs cache by default Signed-off-by: Jörn Friedrich Dreyer Signed-off-by: Jörn Friedrich Dreyer --- services/frontend/pkg/config/config.go | 16 +++++++++++++++- .../pkg/config/defaults/defaultconfig.go | 1 + services/frontend/pkg/revaconfig/config.go | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/services/frontend/pkg/config/config.go b/services/frontend/pkg/config/config.go index 136d11d0945..5ed913e4bee 100644 --- a/services/frontend/pkg/config/config.go +++ b/services/frontend/pkg/config/config.go @@ -110,11 +110,25 @@ type OCS struct { SharePrefix string `yaml:"share_prefix" env:"FRONTEND_OCS_SHARE_PREFIX" desc:"Path prefix for shares."` HomeNamespace string `yaml:"home_namespace" env:"FRONTEND_OCS_HOME_NAMESPACE" desc:"Homespace namespace identifier."` AdditionalInfoAttribute string `yaml:"additional_info_attribute" env:"FRONTEND_OCS_ADDITIONAL_INFO_ATTRIBUTE" desc:"Additional information attribute for the user like {{.Mail}}."` - ResourceInfoCacheTTL int `yaml:"resource_info_cache_ttl" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_TTL" desc:"Max TTL for the resource info cache."` + ResourceInfoCacheTTL int `yaml:"resource_info_cache_ttl" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_TTL" desc:"Max TTL for the resource info cache. 0 disables the cache."` + ResourceInfoCacheType string `yaml:"resource_info_cache_type" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_TYPE" desc:"Resource info cache type ('memory' or 'redis')."` + ResourceInfoCaches ResourceInfoCaches `yaml:"resource_info_caches,omitempty"` // only used for redis CacheWarmupDriver string `yaml:"cache_warmup_driver,omitempty"` // not supported by the oCIS product, therefore not part of docs CacheWarmupDrivers CacheWarmupDrivers `yaml:"cache_warmup_drivers,omitempty"` // not supported by the oCIS product, therefore not part of docs } +// ResourceInfoCaches holds resource info cache configurations +type ResourceInfoCaches struct { + Redis RedisDriver `yaml:"redis,omitempty"` +} + +// RedisDriver holds redis configuration +type RedisDriver struct { + Address string `yaml:"address" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_REDIS_ADDR" desc:"Redis service address"` + Username string `yaml:"username" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_REDIS_USERNAME" desc:"Redis username"` + Password string `yaml:"password" env:"FRONTEND_OCS_RESOURCE_INFO_CACHE_REDIS_PASSWORD" desc:"Redis password"` +} + type CacheWarmupDrivers struct { CBOX CBOXDriver `yaml:"cbox,omitempty"` } diff --git a/services/frontend/pkg/config/defaults/defaultconfig.go b/services/frontend/pkg/config/defaults/defaultconfig.go index 4cd1ea94dea..b70f8095c77 100644 --- a/services/frontend/pkg/config/defaults/defaultconfig.go +++ b/services/frontend/pkg/config/defaults/defaultconfig.go @@ -61,6 +61,7 @@ func DefaultConfig() *config.Config { SharePrefix: "/Shares", HomeNamespace: "/users/{{.Id.OpaqueId}}", AdditionalInfoAttribute: "{{.Mail}}", + ResourceInfoCacheType: "memory", ResourceInfoCacheTTL: 0, }, Middleware: config.Middleware{ diff --git a/services/frontend/pkg/revaconfig/config.go b/services/frontend/pkg/revaconfig/config.go index bae3c2972f5..1439d32029e 100644 --- a/services/frontend/pkg/revaconfig/config.go +++ b/services/frontend/pkg/revaconfig/config.go @@ -125,10 +125,19 @@ func FrontendConfigFromStruct(cfg *config.Config) (map[string]interface{}, error "insecure": true, }, "ocs": map[string]interface{}{ - "storage_registry_svc": cfg.Reva.Address, - "share_prefix": cfg.OCS.SharePrefix, - "home_namespace": cfg.OCS.HomeNamespace, - "resource_info_cache_ttl": cfg.OCS.ResourceInfoCacheTTL, + "storage_registry_svc": cfg.Reva.Address, + "share_prefix": cfg.OCS.SharePrefix, + "home_namespace": cfg.OCS.HomeNamespace, + "resource_info_cache_ttl": cfg.OCS.ResourceInfoCacheTTL, + "resource_info_cache_type": cfg.OCS.ResourceInfoCacheType, + "resource_info_caches": map[string]interface{}{ + // memory has no additional config + "redis": map[string]interface{}{ + "redis_address": cfg.OCS.ResourceInfoCaches.Redis.Address, + "redis_username": cfg.OCS.ResourceInfoCaches.Redis.Username, + "redis_password": cfg.OCS.ResourceInfoCaches.Redis.Password, + }, + }, "prefix": cfg.OCS.Prefix, "additional_info_attribute": cfg.OCS.AdditionalInfoAttribute, "machine_auth_apikey": cfg.MachineAuthAPIKey,