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

eventpb: allow encoding of zero values #86242

Merged
merged 1 commit into from
Aug 19, 2022

Conversation

nicktrav
Copy link
Collaborator

@nicktrav nicktrav commented Aug 16, 2022

Currently, the JSON encoder unconditionally elides zero values, due the
presence of a if m.{{.FieldName}} != 0 { rule in the template. There
are situations where a zero value should still be emitted, despite it
being the default value.

Update the encoder to use the absence of the omitempty proto
annotation as an indication that a zero value should be emitted.
Boolean, string, and numerical native types take this annotation into
account.

Release note: None.

Release justification: Low risk, high benefit changes to existing functionality.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nicktrav
Copy link
Collaborator Author

With this patch, the following fields in the following proto messages would start to be emitted unconditionally, as they do not contain an omitempty annotation. Previously, they were only emitted if non-zero:

CapturedIndexUsageStats
- TotalReadCount
- TableID
- IndexID

DebugRecoverReplica
- RangeID
- StoreID
- SurvivorReplicaID
- UpdatedReplicaID
- StartKey
- EndKey

SchemaDescriptor
- SnapshotID
- Name

SchemaSnapshotMetadata
- SnapshotID
- NumRecords

@nicktrav nicktrav marked this pull request as ready for review August 16, 2022 18:48
@nicktrav nicktrav requested review from a team and knz August 16, 2022 18:48
Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz and @nicktrav)


pkg/util/log/eventpb/eventpbgen/gen.go line 385 at r1 (raw file):

			// Allow zero values if the field is NOT annotated with 'omitempty'.
			allowZeroValue := !strings.Contains(line, "omitempty")

Let's use a different boolean (something like includeempty?)

It's important that zero values get omitted by default. We are really anxious about the size of log entries, and I'd rather have folk think twice about including data with an includeempty than forgetting to exclude it with omitempty.

Currently, the JSON encoder unconditionally elides zero values, due the
presence of a `if m.{{.FieldName}} != 0 {` rule in the template. There
are situations where a zero value should still be emitted, despite it
being the default value.

Update the encoder to use the absence of the `includeempty` proto
annotation as an indication that a zero value should be emitted.
Boolean, string, and numerical native types take this annotation into
account.

Release note: None.

Release justification: Low risk, high benefit changes to existing
functionality.
Copy link
Collaborator Author

@nicktrav nicktrav left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/util/log/eventpb/eventpbgen/gen.go line 385 at r1 (raw file):

Previously, knz (kena) wrote…

Let's use a different boolean (something like includeempty?)

It's important that zero values get omitted by default. We are really anxious about the size of log entries, and I'd rather have folk think twice about including data with an includeempty than forgetting to exclude it with omitempty.

Sounds good. Done.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nicktrav)

@nicktrav
Copy link
Collaborator Author

nicktrav commented Aug 18, 2022

TFTR!

bors r=knz

@craig
Copy link
Contributor

craig bot commented Aug 18, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 18, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 18, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Aug 19, 2022

Build failed:

@nicktrav
Copy link
Collaborator Author

bors r=knz

@craig
Copy link
Contributor

craig bot commented Aug 19, 2022

Build succeeded:

@craig craig bot merged commit c4d4a0b into cockroachdb:master Aug 19, 2022
@nicktrav nicktrav deleted the nickt.zero-value branch August 19, 2022 16:20
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.

3 participants