Skip to content

Commit

Permalink
Merge pull request #1089 from skalenetwork/fix-statsd
Browse files Browse the repository at this point in the history
Replace hyphen with underscore in metric name
  • Loading branch information
dmytrotkk authored Jul 12, 2024
2 parents 3f60fac + 79ff954 commit b2c34f1
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 161 deletions.
4 changes: 2 additions & 2 deletions core/schains/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

from tools.configs.containers import IMA_CONTAINER, SCHAIN_CONTAINER
from tools.docker_utils import DockerUtils
from tools.helper import write_json
from tools.helper import no_hyphens, write_json
from tools.resources import get_statsd_client
from tools.str_formatters import arguments_list_string

Expand Down Expand Up @@ -504,5 +504,5 @@ def log_checks_dict(schain_name, checks_dict):

def send_to_statsd(statsd_client: statsd.StatsClient, schain_name: str, checks_dict: dict) -> None:
for check, result in checks_dict.items():
mname = f'admin.checks.{schain_name}.{check}'
mname = f'admin.schain_checks.{check}.{no_hyphens(schain_name)}'
statsd_client.gauge(mname, int(result))
220 changes: 114 additions & 106 deletions core/schains/dkg/client.py

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions core/schains/monitor/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
from tools.configs import SYNC_NODE
from tools.configs.containers import IMA_CONTAINER, SCHAIN_CONTAINER
from tools.docker_utils import DockerUtils
from tools.helper import no_hyphens
from tools.node_options import NodeOptions
from tools.notifications.messages import notify_repair_mode
from tools.resources import get_statsd_client
Expand Down Expand Up @@ -178,7 +179,7 @@ def config_dir(self) -> bool:
@BaseActionManager.monitor_block
def dkg(self) -> bool:
initial_status = self.checks.dkg.status
with self.statsd_client.timer(f'admin.dkg.{self.name}'):
with self.statsd_client.timer(f'admin.action.dkg.{no_hyphens(self.name)}'):
if not initial_status:
logger.info('Initing dkg client')
dkg_client = get_dkg_client(
Expand Down Expand Up @@ -212,7 +213,7 @@ def dkg(self) -> bool:

@BaseActionManager.monitor_block
def upstream_config(self) -> bool:
with self.statsd_client.timer(f'admin.upstream_config.{self.name}'):
with self.statsd_client.timer(f'admin.action.upstream_config.{no_hyphens(self.name)}'):
logger.info(
'Creating new upstream_config rotation_id: %s, stream: %s',
self.rotation_data.get('rotation_id'), self.stream_version
Expand Down Expand Up @@ -348,15 +349,15 @@ def firewall_rules(self, upstream: bool = False) -> bool:

ranges = self.econfig.ranges
logger.info('Adding ranges %s', ranges)
with self.statsd_client.timer(f'admin.firewall.{self.name}'):
with self.statsd_client.timer(f'admin.action.firewall.{no_hyphens(self.name)}'):
self.rc.configure(
base_port=base_port,
own_ip=own_ip,
node_ips=node_ips,
sync_ip_ranges=ranges
)
self.statsd_client.gauge(
f'admin.expected_rules.{self.name}',
f'admin.action.expected_rules.{no_hyphens(self.name)}',
len(self.rc.expected_rules())
)
self.rc.sync()
Expand Down
18 changes: 10 additions & 8 deletions core/schains/monitor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from tools.docker_utils import DockerUtils
from tools.configs import SYNC_NODE
from tools.notifications.messages import notify_checks
from tools.helper import is_node_part_of_chain
from tools.helper import is_node_part_of_chain, no_hyphens
from tools.resources import get_statsd_client
from web.models.schain import SChainRecord

Expand Down Expand Up @@ -115,9 +115,11 @@ def run_config_pipeline(
mon = RegularConfigMonitor(config_am, config_checks)
statsd_client = get_statsd_client()

statsd_client.incr(f'admin.config.pipeline.{name}.{mon.__class__.__name__}')
statsd_client.gauge(f'admin.schain.rotation_id.{name}', rotation_data['rotation_id'])
with statsd_client.timer(f'admin.config.pipeline.{name}.duration'):
statsd_client.incr(f'admin.config_pipeline.{mon.__class__.__name__}.{no_hyphens(name)}')
statsd_client.gauge(
f'admin.config_pipeline.rotation_id.{no_hyphens(name)}', rotation_data['rotation_id']
)
with statsd_client.timer(f'admin.config_pipeline.duration.{no_hyphens(name)}'):
mon.run()


Expand Down Expand Up @@ -167,8 +169,8 @@ def run_skaled_pipeline(
)

statsd_client = get_statsd_client()
statsd_client.incr(f'schain.skaled.pipeline.{name}.{mon.__name__}')
with statsd_client.timer(f'admin.skaled.pipeline.{name}.duration'):
statsd_client.incr(f'admin.skaled_pipeline.{mon.__name__}.{no_hyphens(name)}')
with statsd_client.timer(f'admin.skaled_pipeline.duration.{no_hyphens(name)}'):
mon(skaled_am, skaled_checks).run()


Expand Down Expand Up @@ -210,8 +212,8 @@ def create_and_execute_tasks(

statsd_client = get_statsd_client()
monitor_last_seen_ts = schain_record.monitor_last_seen.timestamp()
statsd_client.incr(f'admin.schain.monitor.{name}')
statsd_client.gauge(f'admin.schain.monitor_last_seen.{name}', monitor_last_seen_ts)
statsd_client.incr(f'admin.schain.monitor.{no_hyphens(name)}')
statsd_client.gauge(f'admin.schain.monitor_last_seen.{no_hyphens(name)}', monitor_last_seen_ts)

tasks = []
if not leaving_chain:
Expand Down
38 changes: 0 additions & 38 deletions core/schains/monitor/post_rotation_monitor.py

This file was deleted.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
peewee==3.9.5
Flask==2.3.3
Werkzeug==2.3.7
gunicorn==20.1.0
Werkzeug==3.0.3
gunicorn==22.0.0

Jinja2==3.1.2

Expand Down
9 changes: 8 additions & 1 deletion tests/helper_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from tools.helper import is_address_contract
from tools.helper import is_address_contract, no_hyphens
from tools.configs.web3 import ZERO_ADDRESS


def test_is_address_contract(skale):
assert not is_address_contract(skale.web3, ZERO_ADDRESS)
assert is_address_contract(skale.web3, skale.manager.address)
assert is_address_contract(skale.web3, skale.nodes.address)


def test_no_hyphen():
assert no_hyphens('too') == 'too'
assert no_hyphens('too-boo') == 'too_boo'
assert no_hyphens('too-boo_goo') == 'too_boo_goo'
assert no_hyphens('too_goo') == 'too_goo'
4 changes: 4 additions & 0 deletions tools/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ def is_zero_address(address: str) -> bool:
def is_address_contract(web3, address) -> bool:
"""Returns true if contract is deployed at the requested address"""
return web3.eth.get_code(address) != b''


def no_hyphens(name: str) -> str:
return name.replace('-', '_')

0 comments on commit b2c34f1

Please sign in to comment.