Skip to content

marshal logs and metrics with json for print - #1079

Closed
europaul wants to merge 1 commit into
lf-edge:masterfrom
europaul:json-instead-of-protojson
Closed

europaul wants to merge 1 commit into
lf-edge:masterfrom
europaul:json-instead-of-protojson

Conversation

@europaul

Copy link
Copy Markdown
Contributor

I was wondering for a long time why msgid is marshalled as a string, while it's defined as int64. Turns out that protojson.Marshal converts all int64 to string according to the protobuf spec.

I find this peculiar, so I decided to use json.Marshal instead. We'll only use this for printing, to avoid compatibility issues.

As can be seen here it's a known issue and is by design.

@europaul
europaul requested a review from uncleDecart as a code owner July 16, 2025 13:42
@europaul

Copy link
Copy Markdown
Contributor Author

/rerun red

@europaul

Copy link
Copy Markdown
Contributor Author

@uncleDecart could you please restart the tests here?

@europaul
europaul force-pushed the json-instead-of-protojson branch from 123c3a3 to 83a9c34 Compare September 18, 2025 17:03

@eriknordmark eriknordmark left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase this on master.

I was wondering for a long time why msgid is marshalled as a string,
while it's defined as int64. Turns out that protojson.Marshal
converts all int64 to string according to the protobuf spec.

I find this peculiar, so I decided to use json.Marshal instead.
We'll only use this for printing, to avoid compatibility issues.

Signed-off-by: Paul Gaiduk <paulg@zededa.com>
@europaul
europaul force-pushed the json-instead-of-protojson branch from 83a9c34 to 3438dec Compare September 30, 2026 16:58
@europaul

europaul commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing: json.Marshal changes the output shape for proto messages (oneofs nest as {"MetricContent":{"Dm":...}}, timestamps become {seconds,nanos}), which breaks existing jq-based test scripts. protojson's int64-as-string is the lesser evil.

@europaul europaul closed this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants