Skip to content

refactor(binding-kafka): replace KafkaPipeline with ModelEnvelope-backed extraction - #2458

Merged
jfallows merged 1 commit into
developfrom
claude/zilla-plus-pii-status-nfzbgr
Aug 30, 2026
Merged

jfallows merged 1 commit into
developfrom
claude/zilla-plus-pii-status-nfzbgr

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

KafkaPipeline sits above ModelPipeline/KafkaCacheModel and provides a bespoke whole-message lane vocabulary (KafkaEvent: SWITCH_KEY/SWITCH_VALUE/SWITCH_HEADERS/FIELD, plus KafkaSink/KafkaSource/KafkaController/KafkaTransform) so a topic's transforms: extract-key / extract-headers config can promote a field observed mid-traversal into the key or a header. It predates ModelEnvelope, the engine SPI that already lets a composed ModelTransform read/write named, out-of-value metadata directly — already used by the produce path (KafkaCacheTrailerEnvelope) and the client-fetch path (KafkaCacheHeadersEnvelope) to do exactly what extract-headers does, with no lane vocabulary at all.

This PR closes that gap for the key side too, via a reserved :key pseudo-name (colon-prefixed, HTTP/2-pseudo-header style — deliberately not zilla:key, which is a real, wire-materialized header elsewhere), letting extract-key resolve the same way extract-headers already does. With both extraction paths expressible as a plain, composed ModelTransform writing into an envelope, KafkaPipeline and its supporting lane vocabulary (KafkaEvent, KafkaSink, KafkaSource, KafkaController, KafkaTransform) have no remaining reason to exist and are removed.

Changes

  • KafkaExtractTransform rewritten as a plain ModelTransform: on a field-path match it calls envelope.set(name, value), nothing else. Multiple extract-headers entries compose the same way any ModelTransform chain already does, via andThen.
  • KafkaCacheKeyEnvelope (new): a minimal single-value ModelEnvelope for the key's own model, recognizing only the reserved :key name — the key-side counterpart to the existing KafkaCacheHeadersEnvelope/KafkaCacheTrailerEnvelope.
  • KafkaCacheModel.writer(...) widened with a ModelEnvelope parameter, matching the shape encoder/reader already had.
  • KafkaCacheServerFetchFactory composes KafkaExtractTransform directly per extract-key/extract-headers config entry, replacing KafkaPipeline's lane-switch dispatch.
  • KafkaCachePartition's populate-path writeEntryStart/writeEntryFinish now take KafkaCacheModel transformKey/transformValue directly (matching the produce path's existing shape) instead of a KafkaPipeline, and reuse a claimed block in the log file for header collection during the value drive — mirroring the produce path's claim-per-message design — in place of a heap-resident builder reused across every fetched message on a partition. KafkaEntrySink's single-slot key buffering is replaced by an in-place padded-key overwrite sourced from the key's envelope, aborting the entry (rather than corrupting adjacent bytes) if an override doesn't fit within the key's own reserved padding.
  • New cache.server.trailers.size.max config bound (mirrors the existing cache.client.trailers.size.max) sizes the populate-path claim, applied only when the topic actually configures a value model.
  • KafkaPipeline, KafkaEvent, KafkaSink, KafkaSource, KafkaController, KafkaTransform removed entirely, along with their tests and JMH benchmarks (which exercised the deleted lane-switch mechanism directly).

The transforms: extract-key / extract-headers YAML config surface is unchanged — only the internal implementation changes. Existing extract-key/extract-headers k3po coverage (CacheFetchIT#shouldReceiveMessagesWithExtractedKey, #shouldReceiveMessagesWithExtractedHeaderFilter) passes unmodified, plus new unit coverage for sequential-entry envelope reuse and the key-override / header-collection overflow paths.

Test plan

  • ./mvnw clean verify -pl runtime/binding-kafka — unit tests, all k3po ITs, checkstyle, license, JaCoCo all green
  • Existing extract-key/extract-headers k3po scenarios pass unmodified
  • New unit coverage: KafkaExtractTransformTest, KafkaCacheKeyEnvelopeTest, plus KafkaCachePartitionTest cases for sequential-entry envelope reuse, null-key-then-real-key sequencing, key-override-overflow abort, and header-collection-claim overflow abort

Generated by Claude Code

…ked extraction

KafkaPipeline provided a bespoke whole-message lane vocabulary (SWITCH_KEY/
SWITCH_VALUE/SWITCH_HEADERS/FIELD) so extract-key/extract-headers topic
transforms could route a matched field to a different destination. This
predates ModelEnvelope (#1689/#2455), which already lets a composed
ModelTransform read/write named, out-of-value metadata directly and is
already used by the produce and client-fetch paths without any lane
vocabulary at all.

Extends the same envelope mechanism to the key's own model via a reserved
":key" pseudo-name (HTTP/2-pseudo-header style), letting extract-key resolve
the same way extract-headers already does through KafkaCacheHeadersEnvelope/
KafkaCacheTrailerEnvelope. KafkaExtractTransform is rewritten as a plain
ModelTransform that calls envelope.set() on a path match; KafkaCacheServerFetchFactory
composes it directly per extract-key/extract-headers config entry, replacing
KafkaPipeline's lane-switch dispatch and KafkaCachePartition's KafkaEntrySink
single-slot key buffering and heap-resident trailers builder.

KafkaCachePartition's populate-path writeEntryStart/writeEntryFinish now take
KafkaCacheModel transformKey/transformValue directly (matching the produce
path's existing shape) instead of a KafkaPipeline, and reuse a claimed block
in the log file for header collection during the value drive -- mirroring
the produce path's claim-per-message design -- rather than a heap-resident
builder reused across every fetched message on a partition. A new
cache.server.trailers.size.max config bound sizes this claim, gated on
whether the topic actually configures a value model.

KafkaPipeline, KafkaEvent, KafkaSink, KafkaSource, KafkaController, and
KafkaTransform are removed entirely along with their tests and benchmarks,
which exercised the deleted lane-switch mechanism directly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CzxN4tJLhiHQ8ikNeuN8WS
@jfallows
jfallows merged commit 8455f27 into develop Aug 30, 2026
43 checks passed
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.

2 participants