graphite: Separate out configuration from the statsd classes.
The new version of the statsd classes should be created using an instance of
the new Statsd class which sets up some defaults without having to specify
them over and over. This makes it essentially compatible with the existing
usage in autotest, but will allow chromite to configure things differently and
avoid having side effects from importing the module or global state.
BUG=chromium:446291
TEST=Ran unit tests, ran stats_es_functionaltest.py, ran the
stats_mock_unittest, ran a butterfly-paladin tryjob with --hwtest, testing by
fdeng.
DEPLOY=apache,scheduler,host-scheduler
Change-Id: I1071813db197c0e5e035b4d8db615030386f1c1c
Reviewed-on: https://chromium-review.googlesource.com/246428
Reviewed-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
diff --git a/server/autoserv b/server/autoserv
index a357910..24ec567 100755
--- a/server/autoserv
+++ b/server/autoserv
@@ -58,7 +58,7 @@
from autotest_lib.server import utils as server_utils
from autotest_lib.site_utils import job_overhead
from autotest_lib.client.common_lib import pidfile, logging_manager
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
def log_alarm(signum, frame):
logging.error("Received SIGALARM. Ignoring and continuing on.")
@@ -380,8 +380,8 @@
try:
afe = frontend.AFE()
board = server_utils.get_board_from_afe(machines[0], afe)
- timer = stats.Timer('autoserv_run_time.%s.%s' %
- (board, test_name))
+ timer = autotest_stats.Timer('autoserv_run_time.%s.%s' %
+ (board, test_name))
timer.start()
except (urllib2.HTTPError, urllib2.URLError):
# Ignore error if RPC failed to get board
diff --git a/server/autotest.py b/server/autotest.py
index fdd6a70..10f8376 100644
--- a/server/autotest.py
+++ b/server/autotest.py
@@ -6,7 +6,7 @@
from autotest_lib.client.common_lib import base_job, error, autotemp
from autotest_lib.client.common_lib import global_config, packages
from autotest_lib.client.common_lib import utils as client_utils
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
AUTOTEST_SVN = 'svn://test.kernel.org/autotest/trunk/client'
AUTOTEST_HTTP = 'http://test.kernel.org/svn/autotest/trunk/client'
@@ -940,7 +940,7 @@
pass
# Copy all dirs in default to results_dir
- timer = stats.Timer('collect_client_job_results')
+ timer = autotest_stats.Timer('collect_client_job_results')
timer.start()
try:
self.host.get_file(self.client_results_dir + '/',
diff --git a/server/control_segments/cleanup b/server/control_segments/cleanup
index cb6b637..d8b585c 100644
--- a/server/control_segments/cleanup
+++ b/server/control_segments/cleanup
@@ -2,7 +2,7 @@
import os
from autotest_lib.client.common_lib import error
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.server.cros import provision
@@ -17,7 +17,7 @@
job.record('START', None, 'cleanup')
host = hosts.create_host(machine, initialize=False, auto_monitor=False,
try_lab_servo=True)
- timer = stats.Timer('cleanup_time')
+ timer = autotest_stats.Timer('cleanup_time')
timer.start()
# Try to save /var/log files. If the dut is not sshable, try to restart
diff --git a/server/control_segments/reset b/server/control_segments/reset
index c472e8e..ebe01d1 100644
--- a/server/control_segments/reset
+++ b/server/control_segments/reset
@@ -1,6 +1,6 @@
import sys
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.server.cros import provision
@@ -15,7 +15,7 @@
try:
job.record('START', None, 'reset')
host = hosts.create_host(machine, initialize=False, auto_monitor=False)
- timer = stats.Timer('reset_time')
+ timer = autotest_stats.Timer('reset_time')
timer.start()
# Assume cleanup always runs first.
diff --git a/server/control_segments/verify b/server/control_segments/verify
index ae54783..268a5e7 100644
--- a/server/control_segments/verify
+++ b/server/control_segments/verify
@@ -1,4 +1,4 @@
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.server.cros import provision
@@ -16,7 +16,7 @@
# servo update if needed.
host = hosts.create_host(machine, initialize=False, auto_monitor=False,
try_lab_servo=True)
- timer = stats.Timer('verify_time')
+ timer = autotest_stats.Timer('verify_time')
timer.start()
host.verify()
diff --git a/server/crashcollect.py b/server/crashcollect.py
index b82a036..3294eec 100644
--- a/server/crashcollect.py
+++ b/server/crashcollect.py
@@ -1,7 +1,7 @@
import os, time, logging, shutil
from autotest_lib.client.common_lib import global_config
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.client.cros import constants
from autotest_lib.server import utils
@@ -15,7 +15,7 @@
lambda host, test_start_time: None)
-_timer = stats.Timer('crash_collection')
+_timer = autotest_stats.Timer('crash_collection')
@_timer.decorate
def get_crashdumps(host, test_start_time):
@@ -81,7 +81,7 @@
logging.info("Waiting %s hours for %s to come up (%s)",
hours_to_wait, host.hostname, current_time)
if not host.wait_up(timeout=hours_to_wait * 3600):
- stats.Counter('collect_crashinfo_timeout').increment()
+ autotest_stats.Counter('collect_crashinfo_timeout').increment()
logging.warning("%s down, unable to collect crash info",
host.hostname)
return False
diff --git a/server/hosts/cros_host.py b/server/hosts/cros_host.py
index 2beecf9..8acabab 100644
--- a/server/hosts/cros_host.py
+++ b/server/hosts/cros_host.py
@@ -22,7 +22,7 @@
from autotest_lib.client.common_lib.cros import dev_server
from autotest_lib.client.common_lib.cros import retry
from autotest_lib.client.common_lib.cros.graphite import autotest_es
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.client.cros import constants as client_constants
from autotest_lib.client.cros import cros_ui
from autotest_lib.client.cros.audio import cras_utils
@@ -480,7 +480,7 @@
'branch': branch,
'devserver': devserver.replace('.', '_'),
}
- stats.Gauge('verify_job_repo_url').send(
+ autotest_stats.Gauge('verify_job_repo_url').send(
'%(board)s.%(build_type)s.%(branch)s.%(devserver)s' % stats_key,
stage_time)
@@ -945,7 +945,7 @@
% usb_boot_timeout)
logging.info('Downloading image to USB, then booting from it. Usb boot '
'timeout = %s', usb_boot_timeout)
- timer = stats.Timer(usb_boot_timer_key)
+ timer = autotest_stats.Timer(usb_boot_timer_key)
timer.start()
self.servo.install_recovery_image(image_url)
if not self.wait_up(timeout=usb_boot_timeout):
@@ -956,7 +956,7 @@
install_timer_key = ('servo_install.install_timeout_%s'
% install_timeout)
- timer = stats.Timer(install_timer_key)
+ timer = autotest_stats.Timer(install_timer_key)
timer.start()
logging.info('Installing image through chromeos-install.')
self.run('chromeos-install --yes --lab_preserve_logs=%s' %
@@ -1153,35 +1153,35 @@
repair_func()
self.try_collect_crashlogs()
self.check_device()
- stats.Counter(
+ autotest_stats.Counter(
'%s.SUCCEEDED' % repair_func.__name__).increment()
if board:
- stats.Counter(
+ autotest_stats.Counter(
'%s.%s.SUCCEEDED' % (repair_func.__name__,
board)).increment()
return
except error.AutoservRepairMethodNA as e:
- stats.Counter(
+ autotest_stats.Counter(
'%s.RepairNA' % repair_func.__name__).increment()
if board:
- stats.Counter(
+ autotest_stats.Counter(
'%s.%s.RepairNA' % (repair_func.__name__,
board)).increment()
logging.warning('Repair function NA: %s', e)
errors.append(str(e))
except Exception as e:
- stats.Counter(
+ autotest_stats.Counter(
'%s.FAILED' % repair_func.__name__).increment()
if board:
- stats.Counter(
+ autotest_stats.Counter(
'%s.%s.FAILED' % (repair_func.__name__,
board)).increment()
logging.warning('Failed to repair device: %s', e)
errors.append(str(e))
- stats.Counter('Full_Repair_Failed').increment()
+ autotest_stats.Counter('Full_Repair_Failed').increment()
if board:
- stats.Counter(
+ autotest_stats.Counter(
'Full_Repair_Failed.%s' % board).increment()
raise error.AutoservRepairTotalFailure(
'All attempts at repairing the device failed:\n%s' %
diff --git a/server/hosts/servo_host.py b/server/hosts/servo_host.py
index 7711e6e..c0f2a9b 100644
--- a/server/hosts/servo_host.py
+++ b/server/hosts/servo_host.py
@@ -21,7 +21,7 @@
from autotest_lib.client.common_lib.cros import autoupdater
from autotest_lib.client.common_lib.cros import dev_server
from autotest_lib.client.common_lib.cros import retry
-from autotest_lib.client.common_lib.cros.graphite import stats
+from autotest_lib.client.common_lib.cros.graphite import autotest_stats
from autotest_lib.client.common_lib.cros.network import ping_runner
from autotest_lib.server import site_utils as server_site_utils
from autotest_lib.server.cros.servo import servo
@@ -83,7 +83,7 @@
INITIALIZE_SERVO_TIMEOUT_SECS = 30
_MAX_POWER_CYCLE_ATTEMPTS = 3
- _timer = stats.Timer('servo_host')
+ _timer = autotest_stats.Timer('servo_host')
def _initialize(self, servo_host='localhost', servo_port=9999,
@@ -454,7 +454,8 @@
updater.trigger_update()
except autoupdater.RootFSUpdateError as e:
trigger_download_status = 'failed with %s' % str(e)
- stats.Counter('servo_host.RootFSUpdateError').increment()
+ autotest_stats.Counter('servo_host.RootFSUpdateError'
+ ).increment()
else:
trigger_download_status = 'passed'
logging.info('Triggered download and update %s for %s, '
@@ -583,17 +584,18 @@
try:
repair_func()
self.verify()
- stats.Counter(counter_prefix + 'SUCCEEDED').increment()
+ autotest_stats.Counter(counter_prefix + 'SUCCEEDED').increment()
return
except ServoHostRepairMethodNA as e:
logging.warning('Repair method NA: %s', e)
- stats.Counter(counter_prefix + 'RepairNA').increment()
+ autotest_stats.Counter(counter_prefix + 'RepairNA').increment()
errors.append(str(e))
except Exception as e:
logging.warning('Failed to repair servo: %s', e)
- stats.Counter(counter_prefix + 'FAILED').increment()
+ autotest_stats.Counter(counter_prefix + 'FAILED').increment()
errors.append(str(e))
- stats.Counter('servo_host_repair.Full_Repair_Failed').increment()
+ autotest_stats.Counter('servo_host_repair.Full_Repair_Failed'). \
+ increment()
raise ServoHostRepairTotalFailure(
'All attempts at repairing the servo failed:\n%s' %
'\n'.join(errors))