Skip to content

Commit

Permalink
Reformat and redesign the recording output. (#186)
Browse files Browse the repository at this point in the history
* Reformat and redesign the recording output.

  - Formats command events into properly related JSON.
  - Properly record status responses (ok, warning, errors).
  - Record API requests as a chain related to each command.
  - Record the raw command issued, the actual command executed, and the command filter applied (if any).
  - Moves comment handling to OutputManager.
  - Consolidates stop_recording and save_recording.
  - Renamed some variables and methods for consistency.
  - Recording-related methods now all start with recording_ as a prefix.
  - Added a command line option to enable or disable timing data from the recorded data.
  - In general, callers adding details to the recorded data shouldn't test if recording is active. OutputManager handles that detail, the rest of the code simply states that it wishes to make something available for recording.

* Issues

  - The stack details for errors and warnings is bugged. See #185
  - We buffer the entire recording blob in memory until we stop recording (or we exit). This is to ensure valid JSON for the output, as writing (valid) JSON streams to a file is non-trivial. A solution is to write after each command, reload the file and append the data, then write again. This may or may not be a good idea, and it would look something like:

```python
            existing_data = []

            # Read the existing data from the file
            try:
                with open(self._filename, "r") as rec_file:
                    existing_data = json.load(rec_file)
            except (FileNotFoundError, json.JSONDecodeError):
                pass

            existing_data.append(recording_entry)

            # Write the updated data back to the file
            with open(self._filename, "w") as rec_file:
                json.dump(existing_data, rec_file, indent=2)
```
  • Loading branch information
terjekv authored Dec 18, 2023
1 parent 939f428 commit 263a668
Show file tree
Hide file tree
Showing 9 changed files with 21,599 additions and 15,321 deletions.
2 changes: 1 addition & 1 deletion ci/run_testsuite_and_record.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ group.user_set.add(user)

# run the test suite
rm -f new_testsuite_log.json
echo "test" | mreg-cli -u test -d example.org --url http://127.0.0.1:8000 --source testsuite --record new_testsuite_log.json >/dev/null
echo "test" | mreg-cli -u test -d example.org --url http://127.0.0.1:8000 --source testsuite --record new_testsuite_log.json --record-without-timestamps >/dev/null

# show a detailed diff
python diff.py testsuite-result.json new_testsuite_log.json
Expand Down
Loading

0 comments on commit 263a668

Please sign in to comment.