From 6448a4f2af53c241594b5d12eb0d03b18f889eda Mon Sep 17 00:00:00 2001 From: Raman Tenneti Date: Mon, 13 Sep 2021 17:40:07 -0700 Subject: 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 Reviewed-by: Xin Li Tested-by: Raman Tenneti --- git_trace2_event_log.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'git_trace2_event_log.py') 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): repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} self.LogConfigEvents(repo_config, 'def_param') + def LogDataConfigEvents(self, config, prefix): + """Append a 'data' event for each config key/value in |config| to the current log. + + For each keyX and valueX of the config, "key" field of the event is '|prefix|/keyX' + and the "value" of the "key" field is valueX. + + Args: + config: Configuration dictionary. + prefix: Prefix for each key that is logged. + """ + for key, value in config.items(): + event = self._CreateEventDict('data') + event['key'] = f'{prefix}/{key}' + event['value'] = value + self._log.append(event) + def ErrorEvent(self, msg, fmt): """Append a 'error' event to the current log.""" error_event = self._CreateEventDict('error') -- cgit v1.2.3-54-g00ecf