Closed lge closed 1 year ago
Nice catch! Thanks for the report, I'll have a look...
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".
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 🙂
[ { "first":"row"} ,{"second":"row"} ]
The newlines are generated as part of the log_print
here: https://github.com/lvmteam/lvm2/blob/c36e0129267befe90a4116f1d9c5d92fac0128fa/device_mapper/libdm-report.c#L4913-L4919
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.
Yeah, that is probably better approach, considering how current code works. This should be now fixed with: c36e0129267befe90a4116f1d9c5d92fac0128fa
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 :slightly_smiling_face:
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