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

Flatten serialized entries #107

Merged
merged 4 commits into from
Jul 29, 2016
Merged

Flatten serialized entries #107

merged 4 commits into from
Jul 29, 2016

Conversation

akshayjshah
Copy link
Contributor

Log aggregation and processing systems typically require some metadata in the top-level JSON. In zap, we included the message, level, and timestamp, but that's clearly not enough to support many use cases. We could support adding information to this envelope via a separate API, but the simplest option is to flatten the entry.

This is a small change to the production code, but it requires large changes to the tests. To keep review semi-sane, the production and test changes are in separate commits.

require.True(t, cm.OK(), "Expected CheckedMessage to be OK at enabled levels.")
cm.Write(Int("magic", 42))
assert.Equal(
t,
`{"msg":"Info.","level":"info","ts":0,"fields":{"magic":42}}`,
output()[0],
`{"magic":42,"msg":"Info.","level":"info"}`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the JSON output isn't intended for users, it will often be consumed by humans. The current ordering of keys isn't very human-friendly, I'd prefer: time, level, msg, fields. (specifically, the time, level and message should be before the fields).

Since we're copying the bytes in clone anyway, I don't think it'll be any less efficient to create a new buffer, append the time/level/message fields before copying over the fields buffer.

@akshayjshah akshayjshah force-pushed the ajs-encoders branch 2 times, most recently from 771711d to f52eddd Compare July 28, 2016 18:38
@akshayjshah
Copy link
Contributor Author

Updated.

}
final.bytes = append(final.bytes, enc.bytes...)
}
final.bytes = append(final.bytes, "}\n"...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's change this to:

final.bytes = append(final.bytes, '}', '\n')

It looks like this is slightly faster,
https://github.com/prashantv/go-bench/blob/master/append_bytes_test.go

BenchmarkAppendString-8 500000000                3.72 ns/op            0 B/op          0 allocs/op
BenchmarkAppendBytes-8  2000000000               1.63 ns/op            0 B/op          0 allocs/op

Copy link

Choose a reason for hiding this comment

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

You guys are ridiculous :P

Copy link
Collaborator

Choose a reason for hiding this comment

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

Every nanosecond counts!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎶 Eeeeevery nanosecond is precious... 🎶

@prashantv
Copy link
Collaborator

lgtm with minor comments

Akshay Shah added 4 commits July 28, 2016 19:59
Log aggregation and processing systems typically require some
information in the top-level JSON. In zap, we included the message,
level, and timestamp, but that's clearly not enough to support many use
cases. We could support adding information to this envelope via a
separate API, but the simplest option is to flatten the entry.

This is a small change to the production code, but it requires large
changes to the tests. To keep review semi-sane, this commit includes
only the production code changes.
Amend all the tests to expect flattened logs.
@akshayjshah akshayjshah merged commit 7b16b33 into master Jul 29, 2016
@akshayjshah akshayjshah deleted the ajs-encoders branch July 29, 2016 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants