Repository navigation
feat(model-protobuf): add ProtobufModelExt SPI for provider-supplied pipeline stages - #2380
Merged
Merged
Conversation
…pipeline stages Mirrors model-avro's AvroModelExt SPI (#2376) exactly, substituting Protobuf for Avro throughout. Adds ProtobufTransformable to common-protobuf (the narrower supertype ProtobufStream now extends) and a new io.aklivity.zilla.runtime.model.protobuf.ext package (ProtobufModelExtFactorySpi/ProtobufModelExt/ProtobufModelExtContext/ ProtobufModelExtHandler). ProtobufModelHandlerImpl folds every discovered extension's handler into the decode-only pipeline, ahead of its own extractor stage, and sums each extension's declared padding() contribution into the Kafka cache capacity estimate. A deployment with zero installed extensions pays nothing. Fixes #1683 Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
The protobuf model's own allOf branch restricted itself with a local additionalProperties: false, which is evaluated purely against that branch and can never see properties contributed by a sibling allOf branch such as an installed model extension's schema patch (already merged for model-avro's equivalent AvroModelExtFactorySpi). Since the model extension SPI's whole point is letting an installed module contribute additional per-model config, a locally-scoped additionalProperties: false silently blocks every such contribution. Remove the redundant local restriction; the shared unevaluatedProperties: false on $defs/models/model (added for model-avro) already enforces the same closed-schema guarantee while seeing annotations from every allOf branch, including extension- contributed ones.
…buf-extensions-7y9hwr
Adds a src/test-only TestUppercaseProtobufModelExtFactorySpi, registered
solely under META-INF/services so it never ships in the production jar,
proving the ProtobufModelExtFactorySpi composition mechanism works
end-to-end through a live engine -- independent of any specific installed
extension. It uppercases scalar string field values unconditionally, with
no configuration of its own, mirroring the ProtobufModelExtDisclosureTransform
withhold-then-substitute pattern over the same ProtobufTransform contract.
New client.received.protobuf.{json,binary}.ext.uppercase scenarios drive
this through ProtobufModelIT's reply-direction decode path (the only
direction extensions attach to), plus their NetworkIT/ApplicationIT
self-consistency pairs.
Fixes a schemaId=0/NO_SCHEMA_ID collision in value.view.json.yaml and
value.binary.yaml: the test catalog's own resolved id defaulted to the
same sentinel used for "unresolved", so a legitimately-resolved schema on
the decode path was discarded as if no schema had been found. An explicit
catalog id avoids the collision, matching the same fix already applied to
model-avro's equivalent test config.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
…t-jar TestUppercaseProtobufModelExtFactorySpi and its META-INF/services registration exist solely to prove the ProtobufModelExtFactorySpi ServiceLoader composition mechanism in this module's own ProtobufModelIT. The test-jar packaged everything under target/test-classes with no curation, so any consumer depending on model-protobuf:test-jar (e.g. a real installed protobuf model extension's own test suite) picked up this fixture too -- and since ProtobufModelExt implementations are discovered and applied unconditionally, its unconditional uppercase transform silently stacked on top of that consumer's own extension. Excludes the fixture's class and service registration from the test-jar so it stays local to this module's own build, mirroring the curated test-jar packaging convention already used for the engine module's own type: test SPI implementations. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
… transform() signature ProtobufTransformable<T extends ProtobufTransformable<T>> is now self-bounded, so ProtobufModelExtHandler.transform() returns the caller's own concrete stream type instead of the narrower ProtobufTransformable supertype. Mechanical signature update only, no behavior change. ProtobufModelHandlerImpl no longer needs to cast the extended stream back to ProtobufStream, and test doubles that mocked ProtobufTransformable now mock ProtobufStream instead, since a raw ProtobufTransformable mock can no longer bind to the generic parameter without an unchecked cast. Mirrors AvroTransformable's identical self-bounded-generic refactor. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
…irection ProtobufModelExtHandler.transform(T stream) had no notion of which direction it was extending, so ProtobufModelHandlerImpl.extend() folded every installed extension's stage into the decoder pipeline only -- the encoder pipeline built its stream without any extension folding, and encodePadding() never accounted for extension padding. A future extension that must transform both directions (e.g. one applied symmetrically on write and read) had no way to do so. Split into decode(T transformable) / encode(T transformable), each defaulting to a pass-through, mirroring the decode/encode-suffixed members ProtobufModelHandler already exposes (decodeLenient/encodeLenient, decodePadding()/encodePadding()) rather than threading a boolean flag through a single method. ProtobufModelHandlerImpl.extend() is split the same way into extendDecode()/extendEncode(), each backing the matching newPipeline() overload; encodePadding() now sums the extension padding contribution the same way decodePadding() already did. Updates the two existing client.received.protobuf.*.ext.uppercase IT scripts: their application-side scripts previously assumed the encode leg (network client's request reaching the application) passed through untransformed, which is no longer true now that installed extensions fold into the encoder pipeline too. Mirrors AvroModelExtHandler's identical decode/encode split. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QiMcyVBhRqf8cEmVadRAZ8
…buf-extensions-7y9hwr
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.
Description
Adds a way for an installed module to contribute its own
ProtobufTransformstage(s) into model-protobuf's pipeline construction, without model-protobuf needing to know anything about what those stages do — mirroring theAvroModelExtSPI (#2376) exactly, substituted for Protobuf:common-protobuf:ProtobufTransformable<T extends ProtobufTransformable<T>>(append-only, chainable, self-bounded stage builder), withProtobufStreamnow extendingProtobufTransformable<ProtobufStream>, so a provider can append transforms to an in-progress stream and get back its own concrete stream type, without depending onProtobufStream's fuller API or an unchecked cast.model-protobuf: new exportedextpackage withProtobufModelExtFactorySpi(extendsFactorySpi, so@Incubatinggating andServiceLoaderdiscovery come for free),ProtobufModelExt,ProtobufModelExtContext,ProtobufModelExtHandler— mirroringModelFactorySpi/Model/ModelContext's worker-scoped,EngineContext-threaded lifecycle exactly, narrowed to Protobuf. Any number of installed extensions compose, each folded into the stream ahead of the existing pipeline construction, at the same pointnewPipelinealready resolves and caches per schema id.ProtobufModelExtHandler.decode(T)/encode(T)are split into two methods (each defaulting to a pass-through), mirroring the decode/encode-suffixed membersProtobufModelHandleralready exposes (decodeLenient/encodeLenient,decodePadding()/encodePadding()) — andAvroModelExtHandler's identical split — rather than threading a boolean direction flag through a single method.ProtobufModelHandlerImplfolds installed extensions into both the decoder and encoder pipeline built from the same schema, andencodePadding()now sums the extension padding contribution the same waydecodePadding()already did. An extension whose contract only applies to one direction (e.g. a read-side concern like disclosure redaction) overrides just that method and inherits the pass-through default for the other.padding()value, summed into the model's Kafka cache capacity sizing contribution, matching model-avro'sextPadding()mechanism.protobuf.schema.patch.json: removed the model-protobuf branch's localadditionalProperties: false, which is evaluated purely against that branch and can never see properties contributed by a sibling allOf branch such as an installed model extension's schema patch. The sharedunevaluatedProperties: falseon$defs/models/model(added for model-avro) already enforces the same closed-schema guarantee while seeing annotations from every allOf branch, including extension-contributed ones — without this fix, no installed protobuf model extension could ever validate its own config.Verified end-to-end through a live engine via a
src/test-onlyTestUppercaseProtobufModelExtFactorySpi, registered solely underMETA-INF/servicesso it never ships in the production jar. It uppercases scalar string field values unconditionally, proving theProtobufModelExtFactorySpiServiceLoadercomposition mechanism works end-to-end — independent of any specific installed extension — the same mechanism a real installed extension (e.g. zilla-plus's disclosure) relies on, and now overrides bothdecode()andencode()to exercise the composition mechanism symmetrically in both directions. The existingProtobufModelITscenarios (client.received.protobuf.{json,binary}.ext.uppercase) drive one full round trip through a live engine — request leg (encode) and reply leg (decode) both now fold the extension in, so the application-side scripts were updated to expect the request value already uppercased before it reaches the application — plus theirNetworkIT/ApplicationITself-consistency pairs.Fixes #1683
Test plan
./mvnw install -pl runtime/common-protobuf,runtime/model-protobuf,runtime/binding-kafka -am— unit tests, includingProtobufModelExtHandlerTest, extension-padding coverage inProtobufModelDecoderPipelineTest, and the decode/encode split./mvnw checkstyle:check— clean./mvnw install -pl specs/model-protobuf.spec— spec module builds against the relaxed schema./mvnw verify -pl specs/model-protobuf.spec—NetworkIT/ApplicationITself-consistency, including the ext scenarios updated for the encoder-side fold./mvnw verify -pl runtime/model-protobuf—ProtobufModelITagainst a live engine, including the extension-composition scenarios exercising both decode and encodeGenerated by Claude Code