Browse Source

[reclient] Add hostname to invocation ids

This is already covered in the PDD for googlers. We are already gathering hostnames in cloud monitoring mertrics


Bug: b/294945709
Change-Id: Idfb5b8d3b7cf64edd60092f6bd49a3f9f1950d15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4848094
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Commit-Queue: Ben Segall <bentekkie@google.com>
Ben Segall 1 year ago
parent
commit
b64ee7f525
3 changed files with 22 additions and 4 deletions
  1. 2 0
      autosiso.py
  2. 11 1
      reclient_helper.py
  3. 9 3
      tests/ninja_reclient_test.py

+ 2 - 0
autosiso.py

@@ -12,6 +12,7 @@ Siso/Reclient builds.
 import os
 import os
 import re
 import re
 import sys
 import sys
+import uuid
 
 
 import reclient_helper
 import reclient_helper
 import siso
 import siso
@@ -50,6 +51,7 @@ def main(argv):
             file=sys.stderr)
             file=sys.stderr)
         return 1
         return 1
 
 
+    os.environ.setdefault("AUTONINJA_BUILD_ID", str(uuid.uuid4()))
     with reclient_helper.build_context(argv, 'autosiso') as ret_code:
     with reclient_helper.build_context(argv, 'autosiso') as ret_code:
         if ret_code:
         if ret_code:
             return ret_code
             return ret_code

+ 11 - 1
reclient_helper.py

@@ -10,6 +10,7 @@ import contextlib
 import hashlib
 import hashlib
 import os
 import os
 import shutil
 import shutil
+import socket
 import subprocess
 import subprocess
 import sys
 import sys
 import time
 import time
@@ -114,6 +115,14 @@ def auth_cache_status():
         return "missing", "UNSPECIFIED"
         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):
 def set_reproxy_metrics_flags(tool):
     """Helper to setup metrics collection flags for reproxy.
     """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")
     autoninja_id = os.environ.get("AUTONINJA_BUILD_ID")
     if autoninja_id is not None:
     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_project", "chromium-reclient-metrics")
     os.environ.setdefault("RBE_metrics_table", "rbe_metrics.builds")
     os.environ.setdefault("RBE_metrics_table", "rbe_metrics.builds")
     labels = "source=developer,tool=" + tool
     labels = "source=developer,tool=" + tool

+ 9 - 3
tests/ninja_reclient_test.py

@@ -39,7 +39,8 @@ class NinjaReclientTest(trial_dir.TestCase):
         os.chdir(self.previous_dir)
         os.chdir(self.previous_dir)
         super(NinjaReclientTest, self).tearDown()
         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('subprocess.call', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
@@ -83,6 +84,7 @@ class NinjaReclientTest(trial_dir.TestCase):
                 hashlib.md5(
                 hashlib.md5(
                     os.path.join(self.root_dir, "out", "a",
                     os.path.join(self.root_dir, "out", "a",
                                  ".reproxy_tmp").encode()).hexdigest()))
                                  ".reproxy_tmp").encode()).hexdigest()))
+        self.assertIn("/SOME_RANDOM_ID", os.environ["RBE_invocation_id"])
         if sys.platform.startswith('win'):
         if sys.platform.startswith('win'):
             self.assertEqual(
             self.assertEqual(
                 os.environ.get('RBE_server_address'),
                 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('subprocess.call', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
@@ -171,6 +174,7 @@ expiry:  {
             os.environ.get('RBE_proxy_log_dir'),
             os.environ.get('RBE_proxy_log_dir'),
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
         self.assertEqual(os.environ.get('RBE_cache_dir'), cache_dir)
         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'):
         if sys.platform.startswith('win'):
             self.assertEqual(
             self.assertEqual(
                 os.environ.get('RBE_server_address'),
                 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('subprocess.call', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('ninja.main', return_value=0)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
     @unittest.mock.patch('reclient_metrics.check_status', return_value=True)
@@ -258,6 +263,7 @@ expiry:  {
             os.environ.get('RBE_proxy_log_dir'),
             os.environ.get('RBE_proxy_log_dir'),
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
         self.assertEqual(os.environ.get('RBE_cache_dir'), cache_dir)
         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'):
         if sys.platform.startswith('win'):
             self.assertEqual(
             self.assertEqual(
                 os.environ.get('RBE_server_address'),
                 os.environ.get('RBE_server_address'),