blob: 3ecee648717435566acf2106ed61255023d081d2 [file] [log] [blame]
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import socket
import subprocess
import sys
# Install Infra build environment.
BUILD_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(
sys.path.insert(0, os.path.join(BUILD_ROOT, 'scripts'))
from slave import infra_platform
LOGGER = logging.getLogger('monitoring_utils')
('linux',): {
'run_cmd': ['/opt/infra-python/'],
('mac',): {
'run_cmd': ['/opt/infra-python/'],
('win',): {
'run_cmd': ['C:\\infra-python\\ENV\\Scripts\\python.exe',
def _check_call(cmd, **kwargs):'Executing command: %s', cmd)
subprocess.check_call(cmd, **kwargs)
def write_build_monitoring_event(datadir, build_properties):
# Ensure that all command components of "run_cmd" are available.
config = infra_platform.cascade_config(PLATFORM_CONFIG)
if not config or 'run_cmd' not in config:
LOGGER.warning('No is defined for this platform.')
run_cmd_missing = [p for p in config['run_cmd'] if not os.path.exists(p)]
if run_cmd_missing:
LOGGER.warning('Unable to find Some components are missing: %s',
hostname = socket.getfqdn()
if hostname: # just in case getfqdn() returns None.
hostname = hostname.split('.')[0]
hostname = None
cmd = config['run_cmd'] + [
'--event-mon-output-file', os.path.join(datadir, 'log_request_proto'),
'--event-mon-run-type', 'file',
% build_properties.get('mastername', 'UNKNOWN'),
build_properties.get('buildername', 'UNKNOWN'),
str(build_properties.get('buildnumber', 0)),
str(1000*int(build_properties.get('requestedAt', 0))),
'--build-event-type', 'BUILD',
'--event-mon-timestamp-kind', 'POINT',
# And use only defaults for credentials.
# Add this conditionally so that we get an error in
# send_monitoring_event log files in case it isn't present.
if hostname:
cmd += ['--build-event-hostname', hostname]
except Exception:
LOGGER.warning("Failed to send monitoring event.", exc_info=True)