Skip to content
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

No indent option on --json and --log-json #3605

Open
xeor opened this issue Feb 9, 2018 · 14 comments
Open

No indent option on --json and --log-json #3605

xeor opened this issue Feb 9, 2018 · 14 comments
Milestone

Comments

@xeor
Copy link

xeor commented Feb 9, 2018

It would be much easier for tools reading logs from stdout to parse the json if every line was a single entry (ie, no indention).

What would be the best way to implement this? Using another option, like --json-indent=0, or --json-singleline?

I can make a PR on this, but wanted to discuss it first.

@ThomasWaldmann
Copy link
Member

"Easier"? Do you mean it would be faster? Did you measure that?

I don't think a json parser has bad feelings about repeatedly having to skip some whitespace. :-D

@xeor
Copy link
Author

xeor commented Feb 10, 2018

I feel sorry for the parsers that look at the stdout on all this json. They will have it much easier if they could knew that there was 1 entry per line, so they don't need to figure out where the json ends.

This might be a everything from a simple script to splunk. Much easier to use the \n, than using a lot of logic..

The json output option is there to make the output easier to parse for robots after all, why mix in the humanized layer (indention) when they don't care..? :)

@enkore
Copy link
Contributor

enkore commented Feb 10, 2018

stdout only gets one JSON object - so that one is easy, you just hand the entire stdout output to the parser.

stderr is already jsonlines.

@xeor
Copy link
Author

xeor commented Feb 10, 2018

oh...... I didn't notice that :) Problem solved! Thanks!

@xeor xeor closed this as completed Feb 10, 2018
@xeor
Copy link
Author

xeor commented Feb 18, 2018

Sorry for reopening this. But even tho the stream of info, and the summary is separated into stdout and stderr, it makes it much harder than it need to be to parse the summary.

An example (in my case):

  • borg backup runs every night inside a container inside a kubernetes cluster
  • container output is picked up by a logger collector (fluentd), then sent to splunk
  • splunk parses the stderr fine as default, being able to extract the key/values from the json
  • the stdout however, contains multiple lines, and splunk sees the lines as a separate event.

This is an example with splunk, but other log-tools would probably also have the same problem.

It is fixable, but then we need a lot of extra log-logic configuration for what an "event" is, logic being separated by stderr/stdout, or something..

@xeor xeor reopened this Feb 18, 2018
@ThomasWaldmann
Copy link
Member

I'ld say if the output of borg is not what your tools can process, you just need to do some intermediate processing to make it fit.

@xeor
Copy link
Author

xeor commented Feb 19, 2018

Yes.. Some intermediate processing would fix this. But either doing that in fluentd or splunk would still feel wrong. Getting the json output option is awesome, but why not go all the way making it even easier for machine, making it obvious when the blob starts and ends, without extra configuration or intermediate steps.

Will a PR on this gets accepted?

@enkore
Copy link
Contributor

enkore commented Feb 19, 2018

I don't think the specific format of stdout is actually guaranteed in JSON mode so you can probably just change it.

@xeor
Copy link
Author

xeor commented Feb 19, 2018

Correct me if i'm wrong, but isnt

msg = json.dumps(data)
the part that output what we discuss? I thought there where going to be an indent=4 here somewhere. Is this getting "prettified" somewhere else?

@xeor
Copy link
Author

xeor commented Feb 19, 2018

Sorry, based on the docs, it sais

An indent level of 0, negative, or "" will only insert newlines. None (the default) selects the most compact representation.

So I guess, it's hard to know... :)

@enkore
Copy link
Contributor

enkore commented Feb 19, 2018

Nope, that's progress. Stats are this:

if args.stats:

@xeor
Copy link
Author

xeor commented Feb 19, 2018

aha.. yes...

So it is ultimately

return json.dumps(obj, sort_keys=True, indent=4, cls=BorgJsonEncoder)
that is the one that I want configurable..

@enkore
Copy link
Contributor

enkore commented Feb 19, 2018

You don't want it configurable, you just need to get rid of the indentation ;)

@xeor
Copy link
Author

xeor commented Feb 19, 2018

So will the logic of something like 0 if args.flatten_json else 4 be "ok" at that line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants