Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit 5c60c4c

Browse files
author
Rohit Kolapkar
authored
CORTX-33879: Fixed errors while fetching resource limit conf from consul confstore (#883)
* CORTX-33879: Fixed CSM services resource limit fetching from consul gconf Signed-off-by: Rohit Kolapkar <[email protected]> * CORTX-33879: Minor: Key name fixed Signed-off-by: Rohit Kolapkar <[email protected]> * CORTX-33879: Minor: logs fixed Signed-off-by: Rohit Kolapkar <[email protected]>
1 parent 76555d1 commit 5c60c4c

File tree

6 files changed

+196
-184
lines changed

6 files changed

+196
-184
lines changed

csm/conf/configure.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def _prepare_and_validate_confstore_keys(self):
120120
const.KEY_CLUSTER_ID:f"{const.NODE}>{self.machine_id}>{const.CLUSTER_ID}",
121121
const.RGW_S3_AUTH_USER: f"{const.RGW_S3_AUTH_USER_KEY}",
122122
const.RGW_S3_AUTH_ADMIN: f"{const.RGW_S3_AUTH_ADMIN_KEY}",
123-
const.RGW_S3_AUTH_SECRET: f"{const.RGW_S3_AUTH_SECRET_KEY}",
124-
const.KEY_SERVICE_LIMITS: const.CSM_USAGE_LIMIT_SERVICES
123+
const.RGW_S3_AUTH_SECRET: f"{const.RGW_S3_AUTH_SECRET_KEY}"
125124
})
126125

127126
Setup._validate_conf_store_keys(const.CONSUMER_INDEX, keylist = list(self.conf_store_keys.values()))
@@ -373,15 +372,36 @@ def _cpu_limit_to_int(cpu: str) -> int:
373372
@staticmethod
374373
def set_resource_limits() -> None:
375374
"""Set resource limits for CSM."""
376-
limits = Conf.get(const.CONSUMER_INDEX, const.CSM_USAGE_LIMIT_SERVICES)
377-
Conf.set(const.CSM_GLOBAL_INDEX, const.CSM_USAGE_LIMIT_SERVICES, limits)
378-
limits = next(filter(lambda x: x[const.NAME] == "agent", limits), None)
379-
if limits:
380-
mem_min = Configure._mem_limit_to_int(limits["memory"]["min"])
381-
mem_max = Configure._mem_limit_to_int(limits["memory"]["max"])
382-
cpu_min = Configure._cpu_limit_to_int(limits["cpu"]["min"])
383-
cpu_max = Configure._cpu_limit_to_int(limits["cpu"]["max"])
384-
385-
request_rate = Configure._calculate_request_quota(mem_min, mem_max, cpu_min, cpu_max)
386-
Conf.set(const.CSM_GLOBAL_INDEX, const.USAGE_REQUEST_QUOTA, request_rate)
387-
375+
Log.info("Config: Fetching CSM services cpu and memory limits")
376+
count_services : str = Conf.get(const.CONSUMER_INDEX,
377+
const.CSM_LIMITS_NUM_SERVICES_KEY)
378+
try:
379+
count_services = int(count_services)
380+
except ValueError:
381+
raise CsmSetupError("CSM num_services value is not a valid"
382+
" integer.")
383+
for count in range(count_services):
384+
name = Conf.get(const.CONSUMER_INDEX,
385+
f'{const.CSM_LIMITS_SERVICES_KEY}[{count}]>name')
386+
if name == "agent":
387+
mem_min = Conf.get(const.CONSUMER_INDEX,
388+
f'{const.CSM_LIMITS_SERVICES_KEY}[{count}]>memory>min')
389+
mem_max = Conf.get(const.CONSUMER_INDEX,
390+
f'{const.CSM_LIMITS_SERVICES_KEY}[{count}]>memory>max')
391+
cpu_min = Conf.get(const.CONSUMER_INDEX,
392+
f'{const.CSM_LIMITS_SERVICES_KEY}[{count}]>cpu>min')
393+
cpu_max = Conf.get(const.CONSUMER_INDEX,
394+
f'{const.CSM_LIMITS_SERVICES_KEY}[{count}]>cpu>max')
395+
396+
mem_min = Configure._mem_limit_to_int(mem_min)
397+
mem_max = Configure._mem_limit_to_int(mem_max)
398+
cpu_min = Configure._cpu_limit_to_int(cpu_min)
399+
cpu_max = Configure._cpu_limit_to_int(cpu_max)
400+
401+
request_quota = Configure._calculate_request_quota(
402+
mem_min, mem_max, cpu_min, cpu_max)
403+
Conf.set(const.CSM_GLOBAL_INDEX, const.AGENT_REQUEST_QUOTA,
404+
request_quota)
405+
else:
406+
raise CsmSetupError("CSM agent service mem and cpu limits are"
407+
" not found")

csm/conf/csm_default.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ CSM_SERVICE:
3030
port: ''
3131
ssl_check: 'false'
3232
base_url: ''
33+
request_quota: '100'
3334
HA:
3435
enabled: 'false'
3536
primary: node1

0 commit comments

Comments
 (0)