diff --git a/autosiso.py b/autosiso.py index d73ef36a7..46b13697a 100755 --- a/autosiso.py +++ b/autosiso.py @@ -12,6 +12,7 @@ Siso/Reclient builds. import os import re import sys +import uuid import reclient_helper import siso @@ -50,6 +51,7 @@ def main(argv): file=sys.stderr) return 1 + os.environ.setdefault("AUTONINJA_BUILD_ID", str(uuid.uuid4())) with reclient_helper.build_context(argv, 'autosiso') as ret_code: if ret_code: return ret_code diff --git a/reclient_helper.py b/reclient_helper.py index 0e38776ff..8551b9247 100644 --- a/reclient_helper.py +++ b/reclient_helper.py @@ -10,6 +10,7 @@ import contextlib import hashlib import os import shutil +import socket import subprocess import sys import time @@ -114,6 +115,14 @@ def auth_cache_status(): return "missing", "UNSPECIFIED" +def get_hostname(): + hostname = socket.gethostname() + try: + return socket.gethostbyaddr(hostname)[0] + except socket.gaierror: + return hostname + + def set_reproxy_metrics_flags(tool): """Helper to setup metrics collection flags for reproxy. @@ -126,7 +135,8 @@ def set_reproxy_metrics_flags(tool): """ autoninja_id = os.environ.get("AUTONINJA_BUILD_ID") if autoninja_id is not None: - os.environ.setdefault("RBE_invocation_id", autoninja_id) + os.environ.setdefault("RBE_invocation_id", + "%s/%s" % (get_hostname(), autoninja_id)) os.environ.setdefault("RBE_metrics_project", "chromium-reclient-metrics") os.environ.setdefault("RBE_metrics_table", "rbe_metrics.builds") labels = "source=developer,tool=" + tool diff --git a/tests/ninja_reclient_test.py b/tests/ninja_reclient_test.py index 9c680b11f..947a5b581 100755 --- a/tests/ninja_reclient_test.py +++ b/tests/ninja_reclient_test.py @@ -39,7 +39,8 @@ class NinjaReclientTest(trial_dir.TestCase): os.chdir(self.previous_dir) super(NinjaReclientTest, self).tearDown() - @unittest.mock.patch.dict(os.environ, {}) + @unittest.mock.patch.dict(os.environ, + {'AUTONINJA_BUILD_ID': "SOME_RANDOM_ID"}) @unittest.mock.patch('subprocess.call', return_value=0) @unittest.mock.patch('ninja.main', return_value=0) @unittest.mock.patch('reclient_metrics.check_status', return_value=True) @@ -83,6 +84,7 @@ class NinjaReclientTest(trial_dir.TestCase): hashlib.md5( os.path.join(self.root_dir, "out", "a", ".reproxy_tmp").encode()).hexdigest())) + self.assertIn("/SOME_RANDOM_ID", os.environ["RBE_invocation_id"]) if sys.platform.startswith('win'): self.assertEqual( os.environ.get('RBE_server_address'), @@ -126,7 +128,8 @@ class NinjaReclientTest(trial_dir.TestCase): ]), ]) - @unittest.mock.patch.dict(os.environ, {}) + @unittest.mock.patch.dict(os.environ, + {'AUTONINJA_BUILD_ID': "SOME_RANDOM_ID"}) @unittest.mock.patch('subprocess.call', return_value=0) @unittest.mock.patch('ninja.main', return_value=0) @unittest.mock.patch('reclient_metrics.check_status', return_value=True) @@ -171,6 +174,7 @@ expiry: { os.environ.get('RBE_proxy_log_dir'), os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs")) self.assertEqual(os.environ.get('RBE_cache_dir'), cache_dir) + self.assertIn("/SOME_RANDOM_ID", os.environ["RBE_invocation_id"]) if sys.platform.startswith('win'): self.assertEqual( os.environ.get('RBE_server_address'), @@ -214,7 +218,8 @@ expiry: { ]), ]) - @unittest.mock.patch.dict(os.environ, {}) + @unittest.mock.patch.dict(os.environ, + {'AUTONINJA_BUILD_ID': "SOME_RANDOM_ID"}) @unittest.mock.patch('subprocess.call', return_value=0) @unittest.mock.patch('ninja.main', return_value=0) @unittest.mock.patch('reclient_metrics.check_status', return_value=True) @@ -258,6 +263,7 @@ expiry: { os.environ.get('RBE_proxy_log_dir'), os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs")) self.assertEqual(os.environ.get('RBE_cache_dir'), cache_dir) + self.assertIn("/SOME_RANDOM_ID", os.environ["RBE_invocation_id"]) if sys.platform.startswith('win'): self.assertEqual( os.environ.get('RBE_server_address'),