Skip to content

CON-623: franz outputs: send empty or null keys as nil keys - #5191

Merged
squiidz merged 3 commits into
mainfrom
jira/CON-623
Nov 13, 2026
Merged

squiidz merged 3 commits into
mainfrom
jira/CON-623

Conversation

@squiidz

@squiidz squiidz commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

The franz-based outputs (redpanda, kafka_franz and the components built on FranzWriter) send a key that resolves to an empty string or to null as a null Kafka key, so those records are distributed across partitions.

Why

A source record without a key reaches the output as an empty string, and a missing metadata entry or null Bloblang value renders as the bytes null. franz-go hashes any non-nil key, so all such records were written to a single partition.

How

  • Add franzRecordKey in franz_writer.go: returns nil for a zero-length key, and for the literal bytes null when the key is interpolated, otherwise the key unchanged; applied in messageBatchToFranzRecords after key interpolation. A static key (no interpolation) such as key: "null" is kept as written.
  • Same approach as Bento PR 943; the public InterpolatedString API has no null-aware accessor, so the null rendering is matched by value.
  • New franz-specific key field description documents the null-key behaviour; the sarama kafka output keeps its previous text since it already drops empty keys and is out of scope.
  • FranzRecordToMessageV0 still sets kafka_key to an empty string for nil keys to avoid changing Bloblang mappings that read it; the output-side fix covers that path.

Testing

  • New TestFranzWriterKey (11 cases); fails on 4 cases without the fix, passes with it
  • go test ./internal/impl/kafka/ unit tests pass
  • golangci-lint on ./internal/impl/kafka/...: 0 issues; gofumpt clean
  • task build:redpanda-connect succeeds
  • go test -run Integration ./internal/impl/kafka/ passes against Docker Redpanda; TestIntegrationSaramaCheckpointOneLockUp fails with the same deadline race on origin/main (untouched sarama code)
  • End-to-end kafka (kill and restart mid-stream): pass, 3000/3000 delivered, 0 lost, 248 redelivered (allowed)

Test evidence

End to end: a source container, the connector built from this branch, and a checker for loss, duplicates, per-key order and content.

Run Commit Result Delivered Duplicates Order Throughput
kafka, killed and restarted mid-stream efe0bbb1f ✅ pass 3000/3000, 0 lost 227 (allowed: at-least-once) in order 63 msg/s, p95 lag 48 s

Integration tests at efe0bbb1f: go test -run Integration ./internal/impl/kafka/...: passed (kafka 127s, kafka/enterprise 10s), none skipped

Updated 2026-11-13.

Risks

Behaviour change: a key that interpolates to the empty string or to the literal string null is now sent as a null key instead of being hashed. An interpolated key whose value is the 4-byte string "null" (for example {"key":"null"} with key: '${! json("key") }') is affected, since the interpolation renders it the same as a null value; a static key: "null" is not. Both are documented in the field description and covered by TestFranzWriterKey.

Jira: https://redpandadata.atlassian.net/browse/CON-623

@squiidz
squiidz marked this pull request as ready for review November 10, 2026 18:33
Comment thread internal/impl/kafka/franz_writer.go Resolved
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Connect docs check

The docs build passed with this PR's generated docs.

Preview: https://connect-pr-5191--redpanda-connect.netlify.app/connect/home/

This PR changes 4 published pages (4 generated files: 4 changed, 0 added, 0 removed). Review the rendered pages, not only the Go strings.

Page Preview
/connect/components/outputs/kafka_franz/ preview
/connect/components/outputs/ockam_kafka/ preview
/connect/components/outputs/redpanda_common/ preview
/connect/components/outputs/redpanda/ preview

Per-file diffs and the rendered-HTML findings are in the job summary. Checked at efe0bbb.

@vbotbuildovich
vbotbuildovich requested a review from a team November 10, 2026 18:53
@Leward
Leward self-requested a review November 12, 2026 22:22

@Leward Leward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix itself is good, but I have concerns where a user would have a key that is legitimately the string "null". It's odd and unusual, but possible.

Comment thread internal/impl/kafka/franz_writer.go Resolved
Comment thread internal/impl/kafka/franz_writer.go Resolved
@squiidz
squiidz requested a review from Leward November 13, 2026 00:50

@Leward Leward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the follow-up. Looks good to me

@squiidz
squiidz merged commit b57cfa2 into main Nov 13, 2026
16 checks passed
@squiidz
squiidz deleted the jira/CON-623 branch November 13, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants