Fix event log command event hierarchy.

command should be cmd_name, to match what git is emitting. This also
fixes arguments, so that only relevant arguments are passed instead
of the entire sys.args, which will contain wrapper information

Change-Id: Id436accfff511292ec2c56798fffb2306dda38fc
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/443741
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Tested-by: Josip Sokcevic <sokcevic@google.com>
This commit is contained in:
Josip Sokcevic 2024-11-22 00:02:40 +00:00 committed by LUCI
parent b1613d741e
commit fafd1ec23e
3 changed files with 16 additions and 18 deletions

View File

@ -130,10 +130,10 @@ class BaseEventLog:
"time": datetime.datetime.now(datetime.timezone.utc).isoformat(), "time": datetime.datetime.now(datetime.timezone.utc).isoformat(),
} }
def StartEvent(self): def StartEvent(self, argv):
"""Append a 'start' event to the current log.""" """Append a 'start' event to the current log."""
start_event = self._CreateEventDict("start") start_event = self._CreateEventDict("start")
start_event["argv"] = sys.argv start_event["argv"] = argv
self._log.append(start_event) self._log.append(start_event)
def ExitEvent(self, result): def ExitEvent(self, result):
@ -159,9 +159,11 @@ class BaseEventLog:
name: Name of the primary command (ex: repo, git) name: Name of the primary command (ex: repo, git)
subcommands: List of the sub-commands (ex: version, init, sync) subcommands: List of the sub-commands (ex: version, init, sync)
""" """
command_event = self._CreateEventDict("command") command_event = self._CreateEventDict("cmd_name")
name = f"{name}-"
name += "-".join(subcommands)
command_event["name"] = name command_event["name"] = name
command_event["subcommands"] = subcommands command_event["hierarchy"] = name
self._log.append(command_event) self._log.append(command_event)
def LogConfigEvents(self, config, event_dict_name): def LogConfigEvents(self, config, event_dict_name):

View File

@ -357,7 +357,7 @@ class _Repo:
start = time.time() start = time.time()
cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start) cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start)
cmd.event_log.SetParent(cmd_event) cmd.event_log.SetParent(cmd_event)
git_trace2_event_log.StartEvent() git_trace2_event_log.StartEvent(["repo", name] + argv)
git_trace2_event_log.CommandEvent(name="repo", subcommands=[name]) git_trace2_event_log.CommandEvent(name="repo", subcommands=[name])
def execute_command_helper(): def execute_command_helper():

View File

@ -150,7 +150,7 @@ class EventLogTestCase(unittest.TestCase):
<version event> <version event>
<start event> <start event>
""" """
self._event_log_module.StartEvent() self._event_log_module.StartEvent([])
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir: with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
log_path = self._event_log_module.Write(path=tempdir) log_path = self._event_log_module.Write(path=tempdir)
self._log_data = self.readLog(log_path) self._log_data = self.readLog(log_path)
@ -213,10 +213,8 @@ class EventLogTestCase(unittest.TestCase):
<version event> <version event>
<command event> <command event>
""" """
name = "repo"
subcommands = ["init" "this"]
self._event_log_module.CommandEvent( self._event_log_module.CommandEvent(
name="repo", subcommands=subcommands name="repo", subcommands=["init", "this"]
) )
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir: with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
log_path = self._event_log_module.Write(path=tempdir) log_path = self._event_log_module.Write(path=tempdir)
@ -225,12 +223,10 @@ class EventLogTestCase(unittest.TestCase):
self.assertEqual(len(self._log_data), 2) self.assertEqual(len(self._log_data), 2)
command_event = self._log_data[1] command_event = self._log_data[1]
self.verifyCommonKeys(self._log_data[0], expected_event_name="version") self.verifyCommonKeys(self._log_data[0], expected_event_name="version")
self.verifyCommonKeys(command_event, expected_event_name="command") self.verifyCommonKeys(command_event, expected_event_name="cmd_name")
# Check for 'command' event specific fields. # Check for 'command' event specific fields.
self.assertIn("name", command_event) self.assertIn("name", command_event)
self.assertIn("subcommands", command_event) self.assertEqual(command_event["name"], "repo-init-this")
self.assertEqual(command_event["name"], name)
self.assertEqual(command_event["subcommands"], subcommands)
def test_def_params_event_repo_config(self): def test_def_params_event_repo_config(self):
"""Test 'def_params' event data outputs only repo config keys. """Test 'def_params' event data outputs only repo config keys.
@ -382,17 +378,17 @@ class EventLogTestCase(unittest.TestCase):
socket_path = os.path.join(tempdir, "server.sock") socket_path = os.path.join(tempdir, "server.sock")
server_ready = threading.Condition() server_ready = threading.Condition()
# Start "server" listening on Unix domain socket at socket_path. # Start "server" listening on Unix domain socket at socket_path.
try:
server_thread = threading.Thread( server_thread = threading.Thread(
target=serverLoggingThread, target=serverLoggingThread,
args=(socket_path, server_ready, received_traces), args=(socket_path, server_ready, received_traces),
) )
try:
server_thread.start() server_thread.start()
with server_ready: with server_ready:
server_ready.wait(timeout=120) server_ready.wait(timeout=120)
self._event_log_module.StartEvent() self._event_log_module.StartEvent([])
path = self._event_log_module.Write( path = self._event_log_module.Write(
path=f"af_unix:{socket_path}" path=f"af_unix:{socket_path}"
) )