-
Notifications
You must be signed in to change notification settings - Fork 68
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
successful commands output invalid json (trailing comma) for default command_log_selection with --reportformat json #130
Comments
Nice catch! Thanks for the report, I'll have a look... |
…MES and selection When reporting in JSON format, we need to be able to find the 'last displayed row', not just 'last row' as we did before. This is used to decide whether to put the JSON_SEPARATOR (the ',' character) between the lines when reporting in JSON format. This is mainly important in case we use a combination of JSON format and a report marked with DM_REPORT_OUTPUT_MULTIPLE_TIMES flag. Such report may be reused several times with different selection criteria each time. In that case, the report always contains all lines in memory, even though some of them do not need to pass the selection criteria that are currently used. Without DM_REPORT_OUTPUT_MULTIPLE_TIMES flag, the report only contains the lines that have passed the selection criteria, so the this wasn't an issue in this case. Fix suggested by Lars Ellenberg and reported here: #130
At first, I was wondering why we don't see the issue with usual reports (like pvs, lvs, vgs...), but then I realized we use DM_REPORT_OUTPUT_MULTIPLE_TIMES for the log report so we can use different selection criteria on the same log report (this is useful in lvm shell). In that case, we keep the whole report in memory, including the lines that don't even pass current selection criteria. And so the "last row" may not be the same as "last displayed row".
The newlines are generated as part of the lvm2/device_mapper/libdm-report.c Lines 4913 to 4919 in c36e012
Yeah, that is probably better approach, considering how current code works. This should be now fixed with: c36e012 |
With a successful command,
command_log_selection="!(log_type=status && message=success)"
filters the last (success) message, and we end up with invalid json (note the trailing comma separator).Workaround:
log/command_log_sort="-log_seq_num"
; it only hurt if we filter out the "last" row, no harm done filtering the "first" (in output order))log/command_log_selection="log_seq_num>=0"
)suggested fix:
In
device_mapper/libdm-report.c:_output_as_columns()
, currently the separator is appended after an object was shown, unless it happens to be the last row (if (rowh != last_row && !dm_pool_grow_object(rh->mem, JSON_SEPARATOR, 0)) ... goto bad;
); but the last row may be filtered away (if (!_should_display_row(row)) continue;
), leaving the trailing separator.I suggest to instead prepend the separator, unless it is the first row to be shown:
Not even compile tested, but something like this should do it, though I'm unclear where the newlines are generated, so I suspect it will now look like below 🙂
To fix that, you may need to reverse iterate the list to find the last not filtered row, then do as you did before, and again use that to decide whether to show a separator or not.
Thanks,
Lars
The text was updated successfully, but these errors were encountered: