Added resources, created a prototype trigger and its corresponding dockerfile for update configurations, Testing required

This commit is contained in:
Lalit Arvind 2024-11-23 15:50:38 -07:00
parent 4d9526ae60
commit 52fc788eee
5 changed files with 69 additions and 14 deletions

View File

@ -0,0 +1,9 @@
FROM python
WORKDIR /update_scripts
COPY . /update_scripts/
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python3","update_trigger.py"]

View File

@ -0,0 +1,8 @@
subprocess
json
jinja2
yaml
re
xml
schedule
time

View File

@ -4,6 +4,7 @@ import subprocess
import json
import xml.etree.ElementTree as ET
import os
import re
if __name__ == "__main__":
@ -15,14 +16,10 @@ if __name__ == "__main__":
all_services = [json.loads(s) for s in all_services]
# extracting the name, removing the custom id from it and storing it in a list
all_service_names = [service['Names'].split('.')[0] for service in all_services]
# extracting only 'keeper1', 'server1'...
all_service_names = [service['Names'].split('.')[0] for service in all_services if re.findall(r'clickhouse-server',service['Names'])]
# extracting only 'server1','server2'...
all_service_names = [ name.split('-')[-1] for name in all_service_names]
# removing all keeepers
all_service_names.remove('keeper1')
all_service_names.remove('keeper2')
all_service_names.remove('keeper3')
curr_num_servers = sorted(all_service_names)[-1][-1]
replication_factor = 2

View File

@ -0,0 +1,34 @@
import subprocess
import json
import re
import schedule
import time
def check_util_exec():
# extracting details of each running container in json format
try:
all_services = subprocess.check_output(["docker","stats","--no-stream","--format","json"],text=True).split('\n')[:-1]
except subprocess.CalledProcessError as e:
print(f"Command failed with return code {e.returncode}")
all_services = [json.loads(s) for s in all_services]
resource_util_exceed_flag = True # Flag to check if all of the containers have exceeded 80% memory utilization
for service in all_services:
if re.findall(r'clickhouse-server',service['Name']):
if float(service['MemPerc'][:-1]) < 80:
resource_util_exceed_flag = False
if resource_util_exceed_flag:
process = subprocess.Popen(['python3','update_compose.py'],text=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout, stderr = process.communicate() # Wait for the process to finish and capture output
print("Standard Output:", stdout)
print("Standard Error:", stderr)
if __name__ == "__main__":
schedule.every(30).seconds.do(check_util_exec)
while True:
schedule.run_pending()
time.sleep(1)

View File

@ -1,4 +1,9 @@
services:
registry:
image: registry:2
ports:
- "5000:5000"
clickhouse-keeper1:
image: clickhouse/clickhouse-server:latest
container_name: clickhouse-keeper1
@ -69,10 +74,10 @@ services:
# constraints: [node.labels.role == server]
update_config:
delay: 10s
# resources:
# limits:
# cpus: "0.50"
# memory: 100M
resources:
limits:
cpus: "0.50"
memory: 1200M
depends_on:
- clickhouse-keeper1
- clickhouse-keeper2
@ -100,10 +105,10 @@ services:
# constraints: [node.labels.role == server]
update_config:
delay: 10s
# resources:
# limits:
# cpus: "0.50"
# memory: 100M
resources:
limits:
cpus: "0.50"
memory: 1200M
depends_on:
- clickhouse-keeper1
- clickhouse-keeper2
@ -115,8 +120,10 @@ services:
networks:
clickhouse-server-network:
driver: overlay
attachable: true
clickhouse-keeper-network:
driver: overlay
attachable: true
volumes:
clickhouse_data1: