diff options
author | Ian Kasprzak <iankaz@google.com> | 2021-03-05 11:04:49 -0800 |
---|---|---|
committer | Ian Kasprzak <iankaz@google.com> | 2021-03-08 17:32:09 +0000 |
commit | 835a34bdb911e15e228cb760043d3f737dd56c84 (patch) | |
tree | 2152ffa9a3aa2ccb878ca2d92d67775a36de555f | |
parent | ef99ec07b4687cef0129057b81c0c1ebd21bb640 (diff) | |
download | git-repo-835a34bdb911e15e228cb760043d3f737dd56c84.tar.gz |
Log repo.* config variables in git trace2 logger.
Bug: [google internal] b/181758736
Testing:
- Unit tests
- Verified repo git trace2 logs had expected data
Change-Id: I9af8a574377bd91115f085808c1271e9dee16a36
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/299182
Tested-by: Ian Kasprzak <iankaz@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Raman Tenneti <rtenneti@google.com>
-rw-r--r-- | git_config.py | 15 | ||||
-rw-r--r-- | git_trace2_event_log.py | 15 | ||||
-rwxr-xr-x | main.py | 2 | ||||
-rw-r--r-- | tests/test_git_trace2_event_log.py | 49 |
4 files changed, 81 insertions, 0 deletions
diff --git a/git_config.py b/git_config.py index 282c0802..914b2924 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -145,6 +145,21 @@ class GitConfig(object): | |||
145 | except ValueError: | 145 | except ValueError: |
146 | return None | 146 | return None |
147 | 147 | ||
148 | def DumpConfigDict(self): | ||
149 | """Returns the current configuration dict. | ||
150 | |||
151 | Configuration data is information only (e.g. logging) and | ||
152 | should not be considered a stable data-source. | ||
153 | |||
154 | Returns: | ||
155 | dict of {<key>, <value>} for git configuration cache. | ||
156 | <value> are strings converted by GetString. | ||
157 | """ | ||
158 | config_dict = {} | ||
159 | for key in self._cache: | ||
160 | config_dict[key] = self.GetString(key) | ||
161 | return config_dict | ||
162 | |||
148 | def GetBoolean(self, name): | 163 | def GetBoolean(self, name): |
149 | """Returns a boolean from the configuration file. | 164 | """Returns a boolean from the configuration file. |
150 | None : The value was not defined, or is not a boolean. | 165 | None : The value was not defined, or is not a boolean. |
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index fe34092a..8c33d80b 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py | |||
@@ -132,6 +132,21 @@ class EventLog(object): | |||
132 | exit_event['code'] = result | 132 | exit_event['code'] = result |
133 | self._log.append(exit_event) | 133 | self._log.append(exit_event) |
134 | 134 | ||
135 | def DefParamRepoEvents(self, config): | ||
136 | """Append a 'def_param' event for each repo.* config key to the current log. | ||
137 | |||
138 | Args: | ||
139 | config: Repo configuration dictionary | ||
140 | """ | ||
141 | # Only output the repo.* config parameters. | ||
142 | repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} | ||
143 | |||
144 | for param, value in repo_config.items(): | ||
145 | def_param_event = self._CreateEventDict('def_param') | ||
146 | def_param_event['param'] = param | ||
147 | def_param_event['value'] = value | ||
148 | self._log.append(def_param_event) | ||
149 | |||
135 | def _GetEventTargetPath(self): | 150 | def _GetEventTargetPath(self): |
136 | """Get the 'trace2.eventtarget' path from git configuration. | 151 | """Get the 'trace2.eventtarget' path from git configuration. |
137 | 152 | ||
@@ -297,6 +297,8 @@ class _Repo(object): | |||
297 | 297 | ||
298 | cmd.event_log.FinishEvent(cmd_event, finish, | 298 | cmd.event_log.FinishEvent(cmd_event, finish, |
299 | result is None or result == 0) | 299 | result is None or result == 0) |
300 | git_trace2_event_log.DefParamRepoEvents( | ||
301 | cmd.manifest.manifestProject.config.DumpConfigDict()) | ||
300 | git_trace2_event_log.ExitEvent(result) | 302 | git_trace2_event_log.ExitEvent(result) |
301 | 303 | ||
302 | if gopts.event_log: | 304 | if gopts.event_log: |
diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py index 8fb38dbe..3c5cb150 100644 --- a/tests/test_git_trace2_event_log.py +++ b/tests/test_git_trace2_event_log.py | |||
@@ -161,6 +161,55 @@ class EventLogTestCase(unittest.TestCase): | |||
161 | self.assertIn('code', exit_event) | 161 | self.assertIn('code', exit_event) |
162 | self.assertEqual(exit_event['code'], 2) | 162 | self.assertEqual(exit_event['code'], 2) |
163 | 163 | ||
164 | def test_def_params_event_repo_config(self): | ||
165 | """Test 'def_params' event data outputs only repo config keys. | ||
166 | |||
167 | Expected event log: | ||
168 | <version event> | ||
169 | <def_param event> | ||
170 | <def_param event> | ||
171 | """ | ||
172 | config = { | ||
173 | 'git.foo': 'bar', | ||
174 | 'repo.partialclone': 'true', | ||
175 | 'repo.partialclonefilter': 'blob:none', | ||
176 | } | ||
177 | self._event_log_module.DefParamRepoEvents(config) | ||
178 | |||
179 | with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir: | ||
180 | log_path = self._event_log_module.Write(path=tempdir) | ||
181 | self._log_data = self.readLog(log_path) | ||
182 | |||
183 | self.assertEqual(len(self._log_data), 3) | ||
184 | def_param_events = self._log_data[1:] | ||
185 | self.verifyCommonKeys(self._log_data[0], expected_event_name='version') | ||
186 | |||
187 | for event in def_param_events: | ||
188 | self.verifyCommonKeys(event, expected_event_name='def_param') | ||
189 | # Check for 'def_param' event specific fields. | ||
190 | self.assertIn('param', event) | ||
191 | self.assertIn('value', event) | ||
192 | self.assertTrue(event['param'].startswith('repo.')) | ||
193 | |||
194 | def test_def_params_event_no_repo_config(self): | ||
195 | """Test 'def_params' event data won't output non-repo config keys. | ||
196 | |||
197 | Expected event log: | ||
198 | <version event> | ||
199 | """ | ||
200 | config = { | ||
201 | 'git.foo': 'bar', | ||
202 | 'git.core.foo2': 'baz', | ||
203 | } | ||
204 | self._event_log_module.DefParamRepoEvents(config) | ||
205 | |||
206 | with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir: | ||
207 | log_path = self._event_log_module.Write(path=tempdir) | ||
208 | self._log_data = self.readLog(log_path) | ||
209 | |||
210 | self.assertEqual(len(self._log_data), 1) | ||
211 | self.verifyCommonKeys(self._log_data[0], expected_event_name='version') | ||
212 | |||
164 | def test_write_with_filename(self): | 213 | def test_write_with_filename(self): |
165 | """Test Write() with a path to a file exits with None.""" | 214 | """Test Write() with a path to a file exits with None.""" |
166 | self.assertIsNone(self._event_log_module.Write(path='path/to/file')) | 215 | self.assertIsNone(self._event_log_module.Write(path='path/to/file')) |