Skip to content

Commit

Permalink
Merge pull request #750 from skalenetwork/add-telegraf
Browse files Browse the repository at this point in the history
Add optional telegraf service setup parameters
  • Loading branch information
badrogger authored May 15, 2024
2 parents 6c3d29c + c46f60b commit 7f1cb81
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 45 deletions.
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
FROM ubuntu:20.04
FROM python:3.11-buster

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get install -y \
git \
python3.11 \
libpython3.11-dev \
python3.11-venv \
python3.11-distutils \
python3.11-dev \
build-essential \
zlib1g-dev \
libssl-dev \
Expand Down
3 changes: 3 additions & 0 deletions node_cli/configs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ def _get_env():

AUTOLOAD_KERNEL_MODULES_PATH = '/etc/modules'
BTRFS_KERNEL_MODULE = 'btrfs'

TELEGRAF_TEMPLATE_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf.j2')
TELEGRAF_CONFIG_PATH = os.path.join(CONTAINER_CONFIG_PATH, 'telegraf.conf')
3 changes: 3 additions & 0 deletions node_cli/configs/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

OPTIONAL_PARAMS = {
'MONITORING_CONTAINERS': '',
'TELEGRAF': '',
'INFLUX_TOKEN': '',
'INFLUX_URL': '',
'TG_API_KEY': '',
'TG_CHAT_ID': '',
'CONTAINER_CONFIGS_DIR': '',
Expand Down
4 changes: 4 additions & 0 deletions node_cli/operations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def init(env_filepath: str, env: dict) -> bool:
)
update_resource_allocation(env_type=env['ENV_TYPE'])
update_images(env.get('CONTAINER_CONFIGS_DIR') != '')

compose_up(env)
return True

Expand Down Expand Up @@ -224,6 +225,7 @@ def init_sync(
)
update_resource_allocation(env_type=env['ENV_TYPE'])
update_images(env.get('CONTAINER_CONFIGS_DIR') != '', sync_node=True)

compose_up(env, sync_node=True)
return True

Expand Down Expand Up @@ -265,6 +267,7 @@ def update_sync(env_filepath: str, env: Dict) -> bool:
distro.version()
)
update_images(env.get('CONTAINER_CONFIGS_DIR') != '', sync_node=True)

compose_up(env, sync_node=True)
return True

Expand Down Expand Up @@ -310,6 +313,7 @@ def restore(env, backup_path, config_only=False):
distro.version()
)
update_resource_allocation(env_type=env['ENV_TYPE'])

if not config_only:
compose_up(env)

Expand Down
17 changes: 13 additions & 4 deletions node_cli/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

SCHAIN_REMOVE_TIMEOUT = 300
IMA_REMOVE_TIMEOUT = 20
TELEGRAF_REMOVE_TIMEOUT = 20

MAIN_COMPOSE_CONTAINERS = ('skale-api', 'bounty', 'skale-admin')
BASE_COMPOSE_SERVICES = (
Expand All @@ -53,7 +54,8 @@
'watchdog',
'filebeat'
)
MONITORING_COMPOSE_SERVICES = ('node-exporter', 'advisor')
MONITORING_COMPOSE_SERVICES = ('node-exporter', 'advisor',)
TELEGRAF_SERVICES = ('telegraf',)
NOTIFICATION_COMPOSE_SERVICES = ('celery',)
COMPOSE_TIMEOUT = 10

Expand Down Expand Up @@ -85,11 +87,13 @@ def get_all_ima_containers(_all=True) -> list:
return docker_client().containers.list(all=_all, filters={'name': 'skale_ima_*'})


def remove_dynamic_containers():
def remove_dynamic_containers() -> None:
logger.info('Removing sChains containers')
rm_all_schain_containers()
logger.info('Removing IMA containers')
rm_all_ima_containers()
logger.info('Removing telegraf (if exists)')
remove_telegraf()


def rm_all_schain_containers():
Expand All @@ -102,6 +106,11 @@ def rm_all_ima_containers():
remove_containers(ima_containers, timeout=IMA_REMOVE_TIMEOUT)


def remove_telegraf() -> None:
telegraf = docker_client().containers.list(filters={'name': 'skale_telegraf'})
remove_containers(telegraf, timeout=TELEGRAF_REMOVE_TIMEOUT)


def remove_containers(containers, timeout):
for container in containers:
safe_rm(container, timeout=timeout)
Expand Down Expand Up @@ -162,7 +171,7 @@ def get_logs_backup_filepath(container: Container) -> str:
def ensure_volume(name: str, size: int, driver='lvmpy', dutils=None):
dutils = dutils or docker_client()
if is_volume_exists(name, dutils=dutils):
logger.info('Volume %s already exits', name)
logger.info('Volume %s already exist', name)
return
logger.info('Creating volume %s, size: %d', name, size)
driver_opts = {'size': str(size)} if driver == 'lvmpy' else None
Expand Down Expand Up @@ -244,7 +253,7 @@ def compose_up(env, sync_node=False):
env['SGX_CERTIFICATES_DIR_NAME'] = SGX_CERTIFICATES_DIR_NAME

run_cmd(cmd=get_up_compose_cmd(BASE_COMPOSE_SERVICES), env=env)
if str_to_bool(env.get('MONITORING_CONTAINERS', '')):
if str_to_bool(env.get('MONITORING_CONTAINERS', 'False')):
logger.info('Running monitoring containers')
run_cmd(cmd=get_up_compose_cmd(MONITORING_COMPOSE_SERVICES), env=env)
if 'TG_API_KEY' in env and 'TG_CHAT_ID' in env:
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ LVMPY_LOG_DIR="$PROJECT_DIR/tests/" \
TEST_HOME_DIR="$PROJECT_DIR/tests/" \
GLOBAL_SKALE_DIR="$PROJECT_DIR/tests/etc/skale" \
DOTENV_FILEPATH='tests/test-env' \
py.test --cov=$PROJECT_DIR/ tests/ --ignore=tests/operations/ $@
py.test --cov=$PROJECT_DIR/ tests/ $@
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def find_version(*file_paths):
"python-dotenv==0.21.0",
"terminaltables==3.1.10",
"requests==2.28.1",
"GitPython==3.1.31",
"GitPython==3.1.41",
"packaging==23.0",
"python-debian==0.1.49",
"python-iptables==1.0.1",
Expand Down
Empty file removed tests/operations/__init__.py
Empty file.
32 changes: 0 additions & 32 deletions tests/operations/common_test.py

This file was deleted.

0 comments on commit 7f1cb81

Please sign in to comment.