feat: add the configuration for quota update provider (#18928)

Add the related configurations for the quota update provider to the
harbor.yml.

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
Chlins Zhang 2023-07-24 16:28:19 +08:00 committed by GitHub
parent c030fd7863
commit 8ff095d68f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 3 deletions

View File

@ -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

View File

@ -241,3 +241,14 @@ class Cache:
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))

View File

@ -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 %}

View File

@ -3,7 +3,7 @@ import os
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

View File

@ -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 (