Support uploading host_name info in the tool event logger

host_name info is useful in several use cases including
1) to distinguish the concurrent tool invocations from the same user.
2) to understand the potential different performance from different hosts (e.g. local workstation VS cloudtop).
3) required to integrate the tool event log with the EPR system.

Test: atest tool_event_logger_test
Bug: 348482213

Change-Id: I98422b3f8ccec73d57fcdcdedac91780c448dc47
This commit is contained in:
Zhuoyao Zhang
2024-06-21 20:47:57 +00:00
parent 79d04e4115
commit d067588a26
3 changed files with 9 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ message ToolEvent {
string source_root = 3; string source_root = 3;
// Name of the tool used. // Name of the tool used.
string tool_tag = 6; string tool_tag = 6;
// Name of the host workstation.
string host_name = 7;
oneof event { oneof event {
InvocationStarted invocation_started = 4; InvocationStarted invocation_started = 4;

View File

@@ -38,6 +38,7 @@ class ToolEventLogger:
tool_tag: str, tool_tag: str,
invocation_id: str, invocation_id: str,
user_name: str, user_name: str,
host_name: str,
source_root: str, source_root: str,
platform_version: str, platform_version: str,
python_version: str, python_version: str,
@@ -46,6 +47,7 @@ class ToolEventLogger:
self.tool_tag = tool_tag self.tool_tag = tool_tag
self.invocation_id = invocation_id self.invocation_id = invocation_id
self.user_name = user_name self.user_name = user_name
self.host_name = host_name
self.source_root = source_root self.source_root = source_root
self.platform_version = platform_version self.platform_version = platform_version
self.python_version = python_version self.python_version = python_version
@@ -57,6 +59,7 @@ class ToolEventLogger:
tool_tag=tool_tag, tool_tag=tool_tag,
invocation_id=str(uuid.uuid4()), invocation_id=str(uuid.uuid4()),
user_name=getpass.getuser(), user_name=getpass.getuser(),
host_name=platform.node(),
source_root=os.environ.get('ANDROID_BUILD_TOP', ''), source_root=os.environ.get('ANDROID_BUILD_TOP', ''),
platform_version=platform.platform(), platform_version=platform.platform(),
python_version=platform.python_version(), python_version=platform.python_version(),
@@ -110,6 +113,7 @@ class ToolEventLogger:
tool_tag=self.tool_tag, tool_tag=self.tool_tag,
invocation_id=self.invocation_id, invocation_id=self.invocation_id,
user_name=self.user_name, user_name=self.user_name,
host_name=self.host_name,
source_root=self.source_root, source_root=self.source_root,
) )

View File

@@ -25,6 +25,7 @@ from tool_event_logger import tool_event_logger
TEST_INVOCATION_ID = 'test_invocation_id' TEST_INVOCATION_ID = 'test_invocation_id'
TEST_USER_NAME = 'test_user' TEST_USER_NAME = 'test_user'
TEST_HOST_NAME = 'test_host_name'
TEST_TOOL_TAG = 'test_tool' TEST_TOOL_TAG = 'test_tool'
TEST_SOURCE_ROOT = 'test_source_root' TEST_SOURCE_ROOT = 'test_source_root'
TEST_PLATFORM_VERSION = 'test_platform_version' TEST_PLATFORM_VERSION = 'test_platform_version'
@@ -41,6 +42,7 @@ class ToolEventLoggerTest(unittest.TestCase):
TEST_TOOL_TAG, TEST_TOOL_TAG,
TEST_INVOCATION_ID, TEST_INVOCATION_ID,
TEST_USER_NAME, TEST_USER_NAME,
TEST_HOST_NAME,
TEST_SOURCE_ROOT, TEST_SOURCE_ROOT,
TEST_PLATFORM_VERSION, TEST_PLATFORM_VERSION,
TEST_PYTHON_VERSION, TEST_PYTHON_VERSION,
@@ -65,6 +67,7 @@ class ToolEventLoggerTest(unittest.TestCase):
log_event = tool_event_pb2.ToolEvent.FromString(sent_event.source_extension) log_event = tool_event_pb2.ToolEvent.FromString(sent_event.source_extension)
self.assertEqual(log_event.invocation_id, TEST_INVOCATION_ID) self.assertEqual(log_event.invocation_id, TEST_INVOCATION_ID)
self.assertEqual(log_event.user_name, TEST_USER_NAME) self.assertEqual(log_event.user_name, TEST_USER_NAME)
self.assertEqual(log_event.host_name, TEST_HOST_NAME)
self.assertEqual(log_event.tool_tag, TEST_TOOL_TAG) self.assertEqual(log_event.tool_tag, TEST_TOOL_TAG)
self.assertEqual(log_event.source_root, TEST_SOURCE_ROOT) self.assertEqual(log_event.source_root, TEST_SOURCE_ROOT)