summaryrefslogtreecommitdiffstats
path: root/git_trace2_event_log.py
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-09-13 17:40:07 -0700
committerRaman Tenneti <rtenneti@google.com>2021-09-14 21:36:12 +0000
commit6448a4f2af53c241594b5d12eb0d03b18f889eda (patch)
tree554753373be6dbd595a659907d2016ac203268cd /git_trace2_event_log.py
parent1328c35a4d0b47c7e8c00fe351f0e587481e28c2 (diff)
downloadgit-repo-6448a4f2af53c241594b5d12eb0d03b18f889eda.tar.gz
sync: Log repo sync state events as 'data' events.
git_trace2_event_log.py: + Added LogDataConfigEvents method to log 'data' events. Sync's current_sync_state and previous_sync_state are logged as 'data' events in the current log. It logs are key/value in the |config| argument. Each key is prefixed with |prefix| argument. The following are sample events that are logged during repo sync. {"event":"data", "sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0", "thread":"MainThread", "time":"2021-09-14T18:16:19.935846Z", "key":"previous_sync_state/repo.syncstate.main.synctime", "value":"2021-09-14T17:27:11.573717Z"} {"event":"data", "sid":"repo-20210914T181545Z-P000330c0/repo-20210914T181545Z-P000330c0", "thread":"MainThread", "time":"2021-09-14T18:16:19.955546Z", "key":"current_sync_state/repo.syncstate.main.synctime", "value":"2021-09-14T18:16:19.935979Z"} tests/test_git_trace2_event_log.py: + Added unit tests sync.py: + Changed logging calls to LogDataConfigEvents. Tested: $ ./run_tests Tested it by running the following command multiple times. $ repo_dev sync -j 20 repo sync has finished successfully Verified config data is looged in trace2 event logs. Bug: [google internal] b/199758376 Change-Id: I75fd830e90c1811ec28510538c99a2632b104e85 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/317823 Reviewed-by: Josh Steadmon <steadmon@google.com> Reviewed-by: Xin Li <delphij@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
Diffstat (limited to 'git_trace2_event_log.py')
-rw-r--r--git_trace2_event_log.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py
index 9c9e5a70..92c4cc6b 100644
--- a/git_trace2_event_log.py
+++ b/git_trace2_event_log.py
@@ -167,6 +167,22 @@ class EventLog(object):
167 repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} 167 repo_config = {k: v for k, v in config.items() if k.startswith('repo.')}
168 self.LogConfigEvents(repo_config, 'def_param') 168 self.LogConfigEvents(repo_config, 'def_param')
169 169
170 def LogDataConfigEvents(self, config, prefix):
171 """Append a 'data' event for each config key/value in |config| to the current log.
172
173 For each keyX and valueX of the config, "key" field of the event is '|prefix|/keyX'
174 and the "value" of the "key" field is valueX.
175
176 Args:
177 config: Configuration dictionary.
178 prefix: Prefix for each key that is logged.
179 """
180 for key, value in config.items():
181 event = self._CreateEventDict('data')
182 event['key'] = f'{prefix}/{key}'
183 event['value'] = value
184 self._log.append(event)
185
170 def ErrorEvent(self, msg, fmt): 186 def ErrorEvent(self, msg, fmt):
171 """Append a 'error' event to the current log.""" 187 """Append a 'error' event to the current log."""
172 error_event = self._CreateEventDict('error') 188 error_event = self._CreateEventDict('error')