[SERVER-47208] mongod --version is formatted awkwardly Created: 31/Mar/20  Updated: 29/Oct/23  Resolved: 08/May/20

Status: Closed
Project: Core Server
Component/s: Diagnostics
Affects Version/s: None
Fix Version/s: 4.4.0-rc6, 4.7.0

Type: Improvement Priority: Major - P3
Reporter: Bruce Lucas (Inactive) Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
Related
related to SERVER-47215 Truncated mongod --version output on ... Closed
is related to SERVER-46765 mongod --version broken by Structured... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.4
Sprint: Service arch 2020-05-18
Participants:
Linked BF Score: 0

 Description   

> mongod --version
db version v4.5.0-472-gb74a814
Build Info:{"version":"4.5.0-472-gb74a814"
 ,"gitVersion":"b74a8143ac2160f8687de2a222ce66af85a092de"
 ,"openSSLVersion":"OpenSSL 1.1.1  11 Sep 2018"
 ,"modules":[]
 ,"allocator":"tcmalloc"
 ,"environment":{"distmod":"ubuntu1804"
   ,"distarch":"x86_64"
   ,"target_arch":"x86_64"}}

This is a very unusual formatting for a json document. Standard pretty-printed formatting would be something like

Build Info: {
    "version": "4.5.0-472-gb74a814",
    "gitVersion": "b74a8143ac2160f8687de2a222ce66af85a092de",
    "openSSLVersion": "OpenSSL 1.1.1  11 Sep 2018",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "x86_64",
        "target_arch":"x86_64"
    }
}



 Comments   
Comment by Githook User [ 08/May/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-47208 make tojson(BSONObj) match JavaScript JSON.stringify.

(cherry picked from commit 5e34f22c838de78290b574519abb7a7241bc1059)
Branch: v4.4
https://github.com/mongodb/mongo/commit/f6a7997c48c33b4b2e2e90eca1bcb3ce0daabbd4

Comment by Githook User [ 08/May/20 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-47208 make tojson(BSONObj) match JavaScript JSON.stringify.
Branch: master
https://github.com/mongodb/mongo/commit/5e34f22c838de78290b574519abb7a7241bc1059

Comment by Billy Donahue [ 06/May/20 ]

CR https://mongodbcr.appspot.com/604010005/

Comment by Bruce Lucas (Inactive) [ 04/May/20 ]

billy.donahue, sounds like there's already code to do this, so should be pretty easy to do? Can we get this in for 4.4.0? I think this will look sloppy to customers.

Regarding specifics of formatting, I think, having originated in Javascript, the standard for JSON formatting is set by Javascript's JSON.stringify (in particular the pretty-printing variant, e.g. JSON.stringify(o, null, 4)). This would format it as in my initial comment. Also this is basically the format we've adopted in the mongo shell for JSON pretty-printing.

Comment by Billy Donahue [ 09/Apr/20 ]

I wouldn't want to do that just to rearrange some commas.

If it comes down to it, I wrote a json pretty printer pretty quickly for the stacktracing project we can use for stuff like this. It produces indentation and commas almost like we'd expect. There was an aesthetic LISP-like choice to join closing braces to the preceding line but we can do whatever.

https://github.com/mongodb/mongo/blob/aeed74375c24c59fb6fb725691fe9ce547a810ab/src/mongo/util/stacktrace_json.cpp

 

Comment by Bruce Lucas (Inactive) [ 09/Apr/20 ]

I don't suppose you could just pass it through the Javascript engine as JSON.stringify(o, null, 4)?

Comment by Billy Donahue [ 08/Apr/20 ]

Ugh I know. This is what our tojson(BSONObj) function emits in pretty mode.
I was disappointed as well, but thought it was somehow a mongo standard format.

Here it is:
https://github.com/mongodb/mongo/blob/c24a1563faff611edbe4edef682d39a2338bdf01/src/mongo/util/version.cpp#L212
I need a better BSON emitter. I'll have to look around for one.

Generated at Thu Feb 08 05:13:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.