-
Notifications
You must be signed in to change notification settings - Fork 593
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
rpk
: add support for tombstone records in produce
and consume
#23264
Conversation
src/go/rpk/pkg/cli/topic/consume.go
Outdated
@@ -221,6 +221,9 @@ func (c *consumer) consume(ctx context.Context) { | |||
r.Key = decKey | |||
} | |||
} | |||
if r.Value == nil { | |||
r.Value = []byte("null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misread the file originally. I don't think we want this, this hijacks the output always for any null value.
I don't have a solid idea yet, but one idea is to add a formatting directive to print null or true if the value is null. I'm not sure yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can handle this case better if we change our Value to a *string
type: https://gist.github.com/WillemKauf/459b2f7ece149a54a6b61f35d5706ec1
Now, our output is
{
"topic": "topic",
"key": "this_is_a_record_with_null_string",
"value": "null",
"timestamp": 1726000933223,
"partition": 0,
"offset": 3
}
{
"topic": "topic",
"key": "this_is_not_a_tombstone_record",
"value": "",
"timestamp": 1726000937808,
"partition": 0,
"offset": 4
}
{
"topic": "topic",
"key": "this_is_a_tombstone_record",
"value": null,
"timestamp": 1726000941565,
"partition": 0,
"offset": 5
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could either:
- Remove
omitempty
and have the above output - Leave it, and have the output look like:
{
"topic": "topic",
"key": "this_is_a_record_with_null_string",
"value": "null",
"timestamp": 1726000933223,
"partition": 0,
"offset": 3
}
{
"topic": "topic",
"key": "this_is_not_a_tombstone_record",
"value": "",
"timestamp": 1726000937808,
"partition": 0,
"offset": 4
}
{
"topic": "topic",
"key": "this_is_a_tombstone_record",
"timestamp": 1726000941565,
"partition": 0,
"offset": 5
}
Now, the tombstone record has its value omitted, but the record with an empty-string value is still included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I'm ok with this change. I can make a corresponding change to franz-go to support querying null-ness vs. emptiness -- %v{is_null}
or something -- but for the json output here in rpk, this is a fine fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! This change has been made in the last force push to this PR (omitempty
is kept, tombstones have no value printed, whereas empty string value records have their values print as ""
)
8ba6d8a
to
894b4f4
Compare
Force push to:
|
894b4f4
to
4825c39
Compare
To differentiate tombstone records with null values (`null`) from records with empty string values (`""`), use a `*string` on the `rpk` side. The output from `rpk topic consume` will show an empty string for records, while tombstone records will have their values omitted.
To differentiate a record with an empty string-value (`""`) in `rpk topic produce` from a record with a null value (`null`, as produced by `rpk topic produce -Z`), assign the empty-string to an empty-byte slice.
4825c39
to
8d35402
Compare
Force push to rebase to upstream |
Recommend adding a new paragraph in Something like (adjust when necessary) :
|
To give better guidance around tombstone records.
Push to:
|
For
rpk topic produce
:To differentiate tombstones record with a null value (
null
, as produced byrpk topic produce -Z
) from records with empty string-values (""
) inrpk topic produce
, assign the empty-string value case to an empty-byte slice.For
rpk topic consume
:To differentiate tombstone records with null values (
null
, as produced byrpk topic produce -Z
) from records with empty string values (""
) inrpk topic consume
, use a*string
on therpk
side for JSON marshalling.The output from
rpk topic consume
will show""
for records with empty-string values, while tombstone records will have their values omitted.An example of the output from
rpk topic consume
with tombstone and non-tombstone records now looks like:Backports Required
Release Notes
Improvements
rpk produce
andrpk consume
.