diff --git a/make/harbor.yml.tmpl b/make/harbor.yml.tmpl index 4ed087eb199..56dc8837304 100644 --- a/make/harbor.yml.tmpl +++ b/make/harbor.yml.tmpl @@ -258,3 +258,15 @@ cache: enabled: false # keep cache for one day by default expire_hours: 24 + +# Harbor core configurations +# Uncomment to enable the following harbor core related configuration items. +# core: +# # The provider for updating project quota(usage), there are 2 options, redis or db, +# # by default is implemented by db but you can switch the updation via redis which +# # can improve the performance of high concurrent pushing to the same project, +# # and reduce the database connections spike and occupies. +# # By redis will bring up some delay for quota usage updation for display, so only +# # suggest switch provider to redis if you were ran into the db connections spike aroud +# # the scenario of high concurrent pushing to same project, no improvment for other scenes. +# quota_update_provider: redis # Or db \ No newline at end of file diff --git a/make/photon/prepare/models.py b/make/photon/prepare/models.py index d77e3ec85f5..d60246184c8 100644 --- a/make/photon/prepare/models.py +++ b/make/photon/prepare/models.py @@ -241,3 +241,14 @@ def validate(self): if not self.expire_hours or self.expire_hours <= 0: raise Exception('cache expire hours should be positive number') return + +class Core: + def __init__(self, config: dict): + self.quota_update_provider = config.get('quota_update_provider') or 'db' + + def validate(self): + if not self.quota_update_provider: + return + + if self.quota_update_provider not in ['db', 'redis']: + raise Exception('invalid quota update provider: {}'.format(self.quota_update_provider)) \ No newline at end of file diff --git a/make/photon/prepare/templates/core/env.jinja b/make/photon/prepare/templates/core/env.jinja index 0b0f6f47f31..161e0d16690 100644 --- a/make/photon/prepare/templates/core/env.jinja +++ b/make/photon/prepare/templates/core/env.jinja @@ -87,3 +87,7 @@ TRACE_OTEL_INSECURE={{ trace.otel.insecure }} CACHE_ENABLED=true CACHE_EXPIRE_HOURS={{ cache.expire_hours }} {% endif %} + +{% if core.quota_update_provider %} +QUOTA_UPDATE_PROVIDER={{ core.quota_update_provider }} +{% endif %} \ No newline at end of file diff --git a/make/photon/prepare/utils/configs.py b/make/photon/prepare/utils/configs.py index d7d73f2db30..28f2db2cb16 100644 --- a/make/photon/prepare/utils/configs.py +++ b/make/photon/prepare/utils/configs.py @@ -3,7 +3,7 @@ import yaml from urllib.parse import urlencode, quote from g import versions_file_path, host_root_dir, DEFAULT_UID, INTERNAL_NO_PROXY_DN -from models import InternalTLS, Metric, Trace, PurgeUpload, Cache +from models import InternalTLS, Metric, Trace, PurgeUpload, Cache, Core from utils.misc import generate_random_string, owner_can_read, other_can_read # NOTE: https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns @@ -85,6 +85,9 @@ def validate(conf: dict, **kwargs): if conf.get('cache'): conf['cache'].validate() + if conf.get('core'): + conf['core'].validate() + def parse_versions(): if not versions_file_path.is_file(): @@ -324,6 +327,10 @@ def parse_yaml_config(config_file_path, with_trivy): cache_config = configs.get('cache') config_dict['cache'] = Cache(cache_config or {}) + # core configs + core_config = configs.get('core') + config_dict['core'] = Core(core_config or {}) + return config_dict diff --git a/src/controller/quota/controller.go b/src/controller/quota/controller.go index 3c4b857d502..951be3f493d 100644 --- a/src/controller/quota/controller.go +++ b/src/controller/quota/controller.go @@ -59,8 +59,8 @@ var ( // quotaExpireTimeout is the expire time for quota when update quota by redis quotaExpireTimeout = time.Minute * 5 - updateQuotaProviderRedis updateQuotaProviderType = "Redis" - updateQuotaProviderDB updateQuotaProviderType = "DB" + updateQuotaProviderRedis updateQuotaProviderType = "redis" + updateQuotaProviderDB updateQuotaProviderType = "db" ) var (