feat(metric): added new metric calculation. Fixes: RCCE-5

This commit is contained in:
Serhii Ilin 2024-01-17 17:19:42 +02:00
parent 6437db69cd
commit 6192f14c32

View file

@ -18,6 +18,7 @@
import os
import sys
import time
import logging
import click
@ -25,6 +26,7 @@ import click
from pyramid.paster import setup_logging
from rhodecode.lib.pyramid_utils import bootstrap
from rhodecode.lib.statsd_client import StatsdClient
from .backends import SshWrapper
log = logging.getLogger(__name__)
@ -65,8 +67,9 @@ def main(ini_path, mode, user, user_id, key_id, shell, debug):
'Please make sure this is set and available during execution '
'of this script.')
connection_info = os.environ.get('SSH_CONNECTION', '')
time_start = time.time()
with bootstrap(ini_path, env={'RC_CMD_SSH_WRAPPER': '1'}) as env:
statsd = StatsdClient.statsd
try:
ssh_wrapper = SshWrapper(
command, connection_info, mode,
@ -74,6 +77,10 @@ def main(ini_path, mode, user, user_id, key_id, shell, debug):
except Exception:
log.exception('Failed to execute SshWrapper')
sys.exit(-5)
return_code = ssh_wrapper.wrap()
operation_took = time.time() - time_start
if statsd:
operation_took_ms = round(1000.0 * operation_took)
statsd.timing("rhodecode_ssh_wrapper_timing.histogram", operation_took_ms,
use_decimals=False)
sys.exit(return_code)