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

zapcore: Ignore nil Entry.Time in encoders #1369

Merged
merged 3 commits into from
Oct 5, 2023
Merged

zapcore: Ignore nil Entry.Time in encoders #1369

merged 3 commits into from
Oct 5, 2023

Conversation

justinhwang
Copy link
Contributor

Per the comment on Encoder.EncodeEntry, any fields that are empty including fields on the Entry type should be omitted. Omit the Time field when we have empty time.
This also aligns with slog.Handler contract.

Refs #1334
Discovered by #1335

Per the comment on `Encoder.EncodeEntry`, any fields that are empty
including fields on the `Entry` type should be omitted.
Omit the `Time` field when we have empty time.
This also aligns with slog.Handler contract.

Refs #1334
Discovered by #1335
@CLAassistant
Copy link

CLAassistant commented Oct 4, 2023

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #1369 (f9de9df) into master (54430cb) will increase coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1369      +/-   ##
==========================================
+ Coverage   98.28%   98.42%   +0.14%     
==========================================
  Files          53       53              
  Lines        3493     3493              
==========================================
+ Hits         3433     3438       +5     
+ Misses         50       46       -4     
+ Partials       10        9       -1     
Files Coverage Δ
zapcore/console_encoder.go 100.00% <100.00%> (ø)
zapcore/json_encoder.go 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!
The PR largely LGTM. Just two changes, please:

  • Delete the skipped test. We'd prefer to track that pending work in a GH issue.
  • Add a similar check to console_encoder_test as the JSON case.

@@ -189,3 +193,42 @@ func TestAttrKinds(t *testing.T) {
},
entry.ContextMap())
}

func TestSlogtest(t *testing.T) {
t.Skip() // TODO: skip for now until test failures are fixed (#1334)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to keep this test off master until we actually have it passing.
t.Skips don't really get follow ups that often—I'd prefer we track the pending work in issues as we're already doing that.

Would you mind deleting this change from this PR?

Comment on lines +112 to +114
{
desc: "zero_time_omitted",
expected: `{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Would you mind adding a similar check to the console_encoder_test.go as well?

This work is being tracked in #1334.
Verifies that the console encoder also skips the time
if it's a zero value.
Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

I realized that the console encoder didn't have an existing test for something like this. I added one and a test for this.

LGTM!

Copy link
Member

@mway mway left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @justinhwang and @abhinav!

@mway mway merged commit 87577d8 into uber-go:master Oct 5, 2023
6 checks passed
@justinhwang justinhwang deleted the justinhwang/zerotime branch October 5, 2023 19:44
howardjohn added a commit to howardjohn/istio that referenced this pull request Mar 5, 2024
howardjohn added a commit to howardjohn/istio that referenced this pull request Mar 5, 2024
howardjohn added a commit to howardjohn/istio that referenced this pull request Mar 6, 2024
istio-testing pushed a commit to istio/istio that referenced this pull request Mar 6, 2024
* bump go.mod dependencies

* jsonpatch evanphx/json-patch#160

* zap uber-go/zap#1369

* lint
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.

4 participants