Use json omitzero for struct-typed fields in cgroup structs#288
Merged
orestisfl merged 1 commit intoelastic:mainfrom Feb 26, 2026
Merged
Conversation
encoding/json's omitempty is silently ignored on struct fields — zero-valued structs are always serialized regardless of the tag. Go 1.24's omitzero fixes this by checking IsZero() or the zero value. No downstream production code is affected (consumers use struct tags via go-structform, not json tags), but this corrects a latent bug if these types are ever json.Marshal'd directly.
Member
|
@orestisfl have you tried to use a local |
Contributor
Author
|
@rdner testded it locally |
rdner
approved these changes
Feb 25, 2026
orestisfl
added a commit
to orestisfl/elastic-agent-system-metrics
that referenced
this pull request
Feb 26, 2026
The CFS, UsOpt, and opt.Uint fields added on this branch used omitempty, which is silently ignored for structs by encoding/json. Switch to omitzero (Go 1.24) consistent with the fix in elastic#288. Refactor omitzero_test.go to table-driven style with exact key equality via assert.Equal instead of Contains/NotContains.
This was referenced Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
encoding/json's omitempty is silently ignored on struct fields — zero-valued structs are always serialized regardless of the tag. Go 1.24's omitzero fixes this by checking IsZero() or the zero value.
Why is it important?
No downstream production code is affected (consumers use struct tags via go-structform, not json tags), but this corrects a latent bug if these types are ever json.Marshal'd directly.
Checklist
Related issues