Skip to content

Commit

Permalink
feat: add the configuration for quota update provider (#18928)
Browse files Browse the repository at this point in the history
Add the related configurations for the quota update provider to the
harbor.yml.

Signed-off-by: chlins <chenyuzh@vmware.com>
  • Loading branch information
chlins authored Jul 24, 2023
1 parent c030fd7 commit 8ff095d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
12 changes: 12 additions & 0 deletions make/harbor.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions make/photon/prepare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 4 additions & 0 deletions make/photon/prepare/templates/core/env.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
9 changes: 8 additions & 1 deletion make/photon/prepare/utils/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions src/controller/quota/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 8ff095d

Please sign in to comment.