-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reformat and redesign the recording output. #186
Merged
terjekv
merged 17 commits into
unioslo:master
from
terjekv:terjekv/Improve-the-format-for-recordings
Dec 18, 2023
Merged
Reformat and redesign the recording output. #186
terjekv
merged 17 commits into
unioslo:master
from
terjekv:terjekv/Improve-the-format-for-recordings
Dec 18, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terjekv
force-pushed
the
terjekv/Improve-the-format-for-recordings
branch
from
December 6, 2023 21:18
f76bf46
to
009e22e
Compare
Before:[
{
"command": "zone list -forward\n"
},
{
"method": "GET",
"url": "/api/v1/zones/forward/",
"data": {},
"status": 200,
"response": {
"count": 1,
"next": null,
"previous": null,
"results": [
{
"nameservers": [
{
"name": "ns1.example.org",
"ttl": null
}
],
"updated": false,
"primary_ns": "ns1.example.org",
"email": "[email protected]",
"refresh": 10800,
"retry": 3600,
"expire": 1814400,
"soa_ttl": 43200,
"default_ttl": 43200,
"name": "example.org"
}
]
}
},
{
"output": "Zones:\n example.org"
},
{
"command": "zone set_ns example.org ns2.example.org"
},
{
"method": "GET",
"url": "/api/v1/hosts/ns2.example.org",
"data": {},
"status": 404,
"response": {
"detail": "Not found."
}
},
{
"method": "GET",
"url": "/api/v1/hosts/?cnames__name=ns2.example.org",
"data": {},
"status": 200,
"response": {
"count": 0,
"next": null,
"previous": null,
"results": []
}
},
{
"output": "WARNING: : host not found: 'ns2.example.org'"
},
{
"output": "WARNING: : ns2.example.org is not in mreg, must force"
}
] After:[
{
"command": "zone list -forward",
"command_filter": null,
"command_issued": "zone list -forward",
"ok": [],
"warning": [],
"error": [],
"output": [
"Zones:",
" example.org"
],
"api_requests": [
{
"method": "GET",
"url": "/api/v1/zones/forward/",
"data": {},
"status": 200,
"response": {
"count": 1,
"next": null,
"previous": null,
"results": [
{
"nameservers": [
{
"name": "ns1.example.org",
"ttl": null
}
],
"updated": false,
"primary_ns": "ns1.example.org",
"email": "[email protected]",
"refresh": 10800,
"retry": 3600,
"expire": 1814400,
"soa_ttl": 43200,
"default_ttl": 43200,
"name": "example.org"
}
]
}
}
]
},
{
"command": "zone set_ns example.org ns2.example.org",
"command_filter": null,
"command_issued": "zone set_ns example.org ns2.example.org # requires force because ns2 is unknown",
"ok": [],
"warning": [
"WARNING: : host not found: 'ns2.example.org'",
"WARNING: : ns2.example.org is not in mreg, must force"
],
"error": [],
"output": [],
"api_requests": [
{
"method": "GET",
"url": "/api/v1/hosts/ns2.example.org",
"data": {},
"status": 404,
"response": {
"detail": "Not found."
}
},
{
"method": "GET",
"url": "/api/v1/hosts/?cnames__name=ns2.example.org",
"data": {},
"status": 200,
"response": {
"count": 0,
"next": null,
"previous": null,
"results": []
}
}
]
}
] Note that this moves warnings (and errors) from the "output" block to separate blocks. This can be merged for output if desired. |
Note that console output is unchanged. |
pederhan
reviewed
Dec 11, 2023
pederhan
reviewed
Dec 11, 2023
terjekv
force-pushed
the
terjekv/Improve-the-format-for-recordings
branch
2 times, most recently
from
December 12, 2023 08:54
5aaea87
to
5ad7947
Compare
- 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. - We want timestamps in the logs, but they will differ for CI runs and thus fail. There needs to be a configuration option to disable logging timestamps... - The stack details for errors and warnings is bugged. See unioslo#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) ``` As this completely redefines the recording output, tests fail miserably.
- Recording-related methods now all start with recording_ as a prefix. - Added an 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.
- RecordingEntry is given proper type. - TimeInfo in RecordingEntry is given proper type. - Correct typing declarations during init.
terjekv
force-pushed
the
terjekv/Improve-the-format-for-recordings
branch
from
December 13, 2023 09:35
5ad7947
to
5cc6c1e
Compare
pederhan
approved these changes
Dec 14, 2023
pederhan
requested changes
Dec 18, 2023
pederhan
approved these changes
Dec 18, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
--record-without-timestamps
.Issues
log. _prefix_from_stack()
needs a defined behaviour. #185Modified tests
As this completely redefines the recording output, tests results are recreated.
Fixes #183