Skip to content

Commit fafd1ec

Browse files
sokcevicGLUCI
authored andcommitted
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 <[email protected]> Reviewed-by: Gavin Mak <[email protected]> Tested-by: Josip Sokcevic <[email protected]>
1 parent b1613d7 commit fafd1ec

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

git_trace2_event_log_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def _CreateEventDict(self, event_name):
130130
"time": datetime.datetime.now(datetime.timezone.utc).isoformat(),
131131
}
132132

133-
def StartEvent(self):
133+
def StartEvent(self, argv):
134134
"""Append a 'start' event to the current log."""
135135
start_event = self._CreateEventDict("start")
136-
start_event["argv"] = sys.argv
136+
start_event["argv"] = argv
137137
self._log.append(start_event)
138138

139139
def ExitEvent(self, result):
@@ -159,9 +159,11 @@ def CommandEvent(self, name, subcommands):
159159
name: Name of the primary command (ex: repo, git)
160160
subcommands: List of the sub-commands (ex: version, init, sync)
161161
"""
162-
command_event = self._CreateEventDict("command")
162+
command_event = self._CreateEventDict("cmd_name")
163+
name = f"{name}-"
164+
name += "-".join(subcommands)
163165
command_event["name"] = name
164-
command_event["subcommands"] = subcommands
166+
command_event["hierarchy"] = name
165167
self._log.append(command_event)
166168

167169
def LogConfigEvents(self, config, event_dict_name):

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def _RunLong(self, name, gopts, argv, git_trace2_event_log):
357357
start = time.time()
358358
cmd_event = cmd.event_log.Add(name, event_log.TASK_COMMAND, start)
359359
cmd.event_log.SetParent(cmd_event)
360-
git_trace2_event_log.StartEvent()
360+
git_trace2_event_log.StartEvent(["repo", name] + argv)
361361
git_trace2_event_log.CommandEvent(name="repo", subcommands=[name])
362362

363363
def execute_command_helper():

tests/test_git_trace2_event_log.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_start_event(self):
150150
<version event>
151151
<start event>
152152
"""
153-
self._event_log_module.StartEvent()
153+
self._event_log_module.StartEvent([])
154154
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
155155
log_path = self._event_log_module.Write(path=tempdir)
156156
self._log_data = self.readLog(log_path)
@@ -213,10 +213,8 @@ def test_command_event(self):
213213
<version event>
214214
<command event>
215215
"""
216-
name = "repo"
217-
subcommands = ["init" "this"]
218216
self._event_log_module.CommandEvent(
219-
name="repo", subcommands=subcommands
217+
name="repo", subcommands=["init", "this"]
220218
)
221219
with tempfile.TemporaryDirectory(prefix="event_log_tests") as tempdir:
222220
log_path = self._event_log_module.Write(path=tempdir)
@@ -225,12 +223,10 @@ def test_command_event(self):
225223
self.assertEqual(len(self._log_data), 2)
226224
command_event = self._log_data[1]
227225
self.verifyCommonKeys(self._log_data[0], expected_event_name="version")
228-
self.verifyCommonKeys(command_event, expected_event_name="command")
226+
self.verifyCommonKeys(command_event, expected_event_name="cmd_name")
229227
# Check for 'command' event specific fields.
230228
self.assertIn("name", command_event)
231-
self.assertIn("subcommands", command_event)
232-
self.assertEqual(command_event["name"], name)
233-
self.assertEqual(command_event["subcommands"], subcommands)
229+
self.assertEqual(command_event["name"], "repo-init-this")
234230

235231
def test_def_params_event_repo_config(self):
236232
"""Test 'def_params' event data outputs only repo config keys.
@@ -382,17 +378,17 @@ def test_write_socket(self):
382378
socket_path = os.path.join(tempdir, "server.sock")
383379
server_ready = threading.Condition()
384380
# Start "server" listening on Unix domain socket at socket_path.
381+
server_thread = threading.Thread(
382+
target=serverLoggingThread,
383+
args=(socket_path, server_ready, received_traces),
384+
)
385385
try:
386-
server_thread = threading.Thread(
387-
target=serverLoggingThread,
388-
args=(socket_path, server_ready, received_traces),
389-
)
390386
server_thread.start()
391387

392388
with server_ready:
393389
server_ready.wait(timeout=120)
394390

395-
self._event_log_module.StartEvent()
391+
self._event_log_module.StartEvent([])
396392
path = self._event_log_module.Write(
397393
path=f"af_unix:{socket_path}"
398394
)

0 commit comments

Comments
 (0)