Skip to content

Commit

Permalink
Merge pull request #1093 from skalenetwork/2.7.0-stable
Browse files Browse the repository at this point in the history
2.7.0 stable
  • Loading branch information
dmytrotkk authored Jul 12, 2024
2 parents ebfbd39 + f04c9e0 commit 0dc84e0
Show file tree
Hide file tree
Showing 95 changed files with 2,615 additions and 953 deletions.
31 changes: 29 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,74 @@ env:
SGX_WALLET_TAG: "1.83.0-beta.5"
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
PYTHON_VERSION: 3.11

jobs:
test_core:
runs-on: ubuntu-latest
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
ENDPOINT: http://127.0.0.1:8545
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
IMA_ENDPOINT: ${{ secrets.IMA_ENDPOINT }}
SCHAIN_TYPE: ${{ secrets.SCHAIN_TYPE }}
steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install python dependencies
run: bash ./scripts/install_python_dependencies.sh

- name: Lint with flake8
run: flake8 .

- name: Launch anvil node
run: |
docker run -d --network host --name anvil ghcr.io/foundry-rs/foundry anvil && sleep 5 && docker logs anvil --tail 1000
- name: Deploy manager & ima contracts
run: |
bash ./helper-scripts/deploy_test_ima.sh
- name: Cleanup skale-manager image
run: |
docker rmi -f skalenetwork/skale-manager:${{ env.MANAGER_TAG }}
- name: Show stats before tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run core tests
run: |
bash ./scripts/run_core_tests.sh
- name: Show stats after tests
- name: Cleanup docker artifacts
run: |
docker rm -f $(docker ps -aq)
docker rmi -f $(docker images -q)
- name: Show stats after core tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run firewall tests
run: |
bash ./scripts/run_firewall_test.sh
- name: Show stats after firewall tests
if: always()
run: |
sudo lsblk -f
sudo free -h
- name: Run codecov
run: |
codecov -t $CODECOV_TOKEN
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ schain_status_sample.json
*.lock

skale-manager-*
manager.json
meta.json

tests/skale-data/contracts_info/ima.json
tests/skale-data/contracts_info/schain_ima_abi.json
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.1
2.7.0
4 changes: 2 additions & 2 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from core.schains.process_manager import run_process_manager
from core.schains.cleaner import run_cleaner
from core.updates import soft_updates
from core.filebeat import update_filebeat_service
from core.monitoring import update_monitoring_services

from tools.configs import BACKUP_RUN, INIT_LOCK_PATH, PULL_CONFIG_FOR_SCHAIN
from tools.configs.web3 import (
Expand Down Expand Up @@ -82,7 +82,7 @@ def worker():
skale_ima = SkaleIma(ENDPOINT, MAINNET_IMA_ABI_FILEPATH, wallet)
if BACKUP_RUN:
logger.info('Running sChains in snapshot download mode')
update_filebeat_service(node_config.ip, node_config.id, skale)
update_monitoring_services(node_config.ip, node_config.id, skale)
monitor(skale, skale_ima, node_config)


Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
FLASK_DEBUG_MODE
)
from tools.configs.web3 import ENDPOINT
from tools.db import get_database, REDIS_URI
from tools.docker_utils import DockerUtils
from tools.helper import wait_until_admin_inited
from tools.logger import init_api_logger
from tools.resources import get_database, REDIS_URI
from tools.str_formatters import arguments_list_string

from web.routes.node import node_bp
Expand Down
53 changes: 0 additions & 53 deletions core/filebeat.py

This file was deleted.

121 changes: 121 additions & 0 deletions core/monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# -*- coding: utf-8 -*-
#
# This file is part of SKALE Admin
#
# Copyright (C) 2020 SKALE Labs
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
from typing import Optional

from tools.helper import process_template
from tools.docker_utils import DockerUtils

from tools.configs import SKALE_DIR_HOST
from tools.configs.monitoring import (
FILEBEAT_TEMPLATE_PATH, FILEBEAT_CONTAINER_NAME,
FILEBEAT_CONFIG_PATH,
INFLUX_URL,
TELEGRAF,
TELEGRAF_CONTAINER_NAME, TELEGRAF_IMAGE,
TELEGRAF_TEMPLATE_PATH,
TELEGRAF_CONFIG_PATH,
TELEGRAF_MEM_LIMIT
)

logger = logging.getLogger(__name__)


class TelegrafNotConfiguredError(Exception):
pass


def update_filebeat_service(node_ip, node_id, skale, dutils: Optional[DockerUtils] = None):
dutils = dutils or DockerUtils()
contract_address = skale.manager.address
template_data = {
'ip': node_ip,
'id': node_id,
'contract_address': contract_address
}

logger.info('Configuring filebeat %s', template_data)
process_template(FILEBEAT_TEMPLATE_PATH, FILEBEAT_CONFIG_PATH, template_data)
filebeat_container = dutils.client.containers.get(FILEBEAT_CONTAINER_NAME)
filebeat_container.restart()
logger.info('Filebeat config updated, telegraf restarted')


def filebeat_config_processed() -> bool:
with open(FILEBEAT_CONFIG_PATH) as f:
return 'id: ' in f.read()


def ensure_telegraf_running(dutils: Optional[DockerUtils] = None) -> None:
dutils = dutils or DockerUtils()
if dutils.is_container_exists(TELEGRAF_CONTAINER_NAME):
dutils.restart(TELEGRAF_CONTAINER_NAME)
else:
dutils.run_container(
image_name=TELEGRAF_IMAGE,
name=TELEGRAF_CONTAINER_NAME,
network_mode='host',
user='telegraf:998',
restart_policy={'name': 'on-failure'},
environment={'HOST_PROC': '/host/proc'},
volumes={
'/proc': {'bind': '/host/proc', 'mode': 'ro'},
f'{SKALE_DIR_HOST}/config/telegraf.conf': {'bind': '/etc/telegraf/telegraf.conf', 'mode': 'ro'}, # noqa
f'{SKALE_DIR_HOST}/node_data/telegraf': {'bind': '/var/lib/telegraf', 'mode': 'rw'},
'/var/run/skale/': {'bind': '/var/run/skale', 'mode': 'rw'}
},
mem_limit=TELEGRAF_MEM_LIMIT
)


def update_telegraf_service(
node_ip: str,
node_id: int,
url: str = INFLUX_URL,
dutils: Optional[DockerUtils] = None
) -> None:
dutils = dutils or DockerUtils()
template_data = {
'ip': node_ip,
'node_id': str(node_id),
'url': url
}
missing = list(filter(lambda k: not template_data[k], template_data))

if missing:
emsg = f'TELEGRAF=True is set, but missing options {template_data}'
raise TelegrafNotConfiguredError(emsg)

logger.info('Configuring telegraf %s', template_data)
process_template(TELEGRAF_TEMPLATE_PATH, TELEGRAF_CONFIG_PATH, template_data)

ensure_telegraf_running(dutils)
logger.info('Telegraf config updated, telegraf restarted')


def telegraf_config_processed() -> bool:
with open(TELEGRAF_CONFIG_PATH) as f:
return 'id: ' in f.read()


def update_monitoring_services(node_ip, node_id, skale, dutils: Optional[DockerUtils] = None):
update_filebeat_service(node_ip, node_id, skale, dutils=dutils)
if TELEGRAF:
update_telegraf_service(node_ip, node_id, dutils=dutils)
4 changes: 2 additions & 2 deletions core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from skale.utils.helper import ip_from_bytes
from skale.utils.web3_utils import public_key_to_address, to_checksum_address

from core.filebeat import update_filebeat_service
from core.monitoring import update_monitoring_services
from tools.configs import WATCHDOG_PORT, CHANGE_IP_DELAY, CHECK_REPORT_PATH, META_FILEPATH
from tools.helper import read_json
from tools.str_formatters import arguments_list_string
Expand Down Expand Up @@ -135,7 +135,7 @@ def register(self, ip, public_ip, port, name, domain_name,
self.config.name = name
self.config.ip = ip

update_filebeat_service(public_ip, self.config.id, self.skale)
update_monitoring_services(public_ip, self.config.id, self.skale)
return self._ok(data=self.config.all())

def create_node_on_contracts(self, ip, public_ip, port, name, domain_name,
Expand Down
Loading

0 comments on commit 0dc84e0

Please sign in to comment.