Read raw dump files, filter out incomplete sessions, and merge them into output files. Args: replay_dir (string) Full path to dumps num_sessions_per_file (int) number of sessions in each output file indent (int) The number of spaces per line in the output replay fil
(replay_dir, num_sessions_per_file, indent, fabricate_proxy_requests, out_dir)
| 224 | |
| 225 | |
| 226 | def readAndCombine(replay_dir, num_sessions_per_file, indent, fabricate_proxy_requests, out_dir): |
| 227 | """ Read raw dump files, filter out incomplete sessions, and merge |
| 228 | them into output files. |
| 229 | |
| 230 | Args: |
| 231 | replay_dir (string) Full path to dumps |
| 232 | num_sessions_per_file (int) number of sessions in each output file |
| 233 | indent (int) The number of spaces per line in the output replay files. |
| 234 | fabricate_proxy_requests (bool) Whether the post-processor should |
| 235 | fabricate proxy requests if they don't exist because the proxy served |
| 236 | the response locally. |
| 237 | out_dir (string) Output directory for post-processed json files. |
| 238 | """ |
| 239 | session_count = 0 |
| 240 | batch_count = 0 |
| 241 | transaction_count = 0 |
| 242 | error_count = defaultdict(int) |
| 243 | |
| 244 | base_name = os.path.basename(replay_dir) |
| 245 | |
| 246 | sessions = [] |
| 247 | for f in os.listdir(replay_dir): |
| 248 | replay_file = os.path.join(replay_dir, f) |
| 249 | if not os.path.isfile(replay_file): |
| 250 | continue |
| 251 | |
| 252 | try: |
| 253 | parsed_json = parse_json(replay_file) |
| 254 | except ParseJSONError as e: |
| 255 | error_count[e.message] += 1 |
| 256 | continue |
| 257 | |
| 258 | for session in parsed_json["sessions"]: |
| 259 | try: |
| 260 | verify_session(session, fabricate_proxy_requests) |
| 261 | except VerifyError as e: |
| 262 | connection_time = session['connection-time'] |
| 263 | if not connection_time: |
| 264 | connection_time = session['start-time'] |
| 265 | if connection_time: |
| 266 | logging.debug("Omitting session in %s with connection-time: %d: %s", replay_file, session['connection-time'], e) |
| 267 | else: |
| 268 | logging.debug("Omitting a session in %s, could not find a connection time: %s", replay_file, e) |
| 269 | continue |
| 270 | sessions.append(session) |
| 271 | session_count += 1 |
| 272 | transaction_count += len(session["transactions"]) |
| 273 | if len(sessions) >= num_sessions_per_file: |
| 274 | write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent) |
| 275 | sessions = [] |
| 276 | batch_count += 1 |
| 277 | if sessions: |
| 278 | write_sessions(sessions, f"{out_dir}/{base_name}_{batch_count}.json", indent) |
| 279 | |
| 280 | return session_count, transaction_count, error_count |
| 281 | |
| 282 | |
| 283 | def post_process(in_dir, subdir_q, out_dir, num_sessions_per_file, single_line, fabricate_proxy_requests, cnt_q): |
no test coverage detected