Skip to content

Declare AvroModelExtFactorySpi and wire provider-supplied pipeline stages in avro model #1681

Closed

Description

@jfallows

Describe the desired outcome from the user's perspective

As a Zilla operator, I want the avro model to let an installed module contribute its own pipeline stages — for whatever purpose that module defines — without oss zilla needing to know or declare what that purpose is.

Acceptance criteria

1. The SPI

// io.aklivity.zilla.runtime.model.avro.ext, model-avro's first exported package

public interface AvroModelExtFactorySpi extends FactorySpi
{
    // FactorySpi.type() names this extension, matching Factory's existing @Incubating-aware
    // ServiceLoader discovery convention used for every other plugin type
    AvroModelExt create(Configuration config);
}

public interface AvroModelExt
{
    String name();   // for diagnostics

    // called once per engine worker, mirroring Model#supply(EngineContext)
    AvroModelExtContext supply(EngineContext context);
}

public interface AvroModelExtContext
{
    // called once per resolved schema + config; whatever schema-time resolution/validation an
    // installed extension needs happens here — entirely its own business, this SPI defines no
    // contract for what "resolution" means
    AvroModelExtHandler supplyHandler(AvroSchema schema, AvroModelConfig config);
}

public interface AvroModelExtHandler
{
    // appends this extension's own stage(s) to an in-progress pipeline, in data-flow order
    AvroTransformable transform(AvroTransformable stream);
}

AvroTransformable is a new, minimal interface in common-avro (transform(AvroTransform): AvroTransformable) that AvroStream now extends, so an extension can append stages to an in-progress stream without depending on AvroStream's fuller terminal-bearing API (.lenient()/.reporting()/.into()). This is the only common-avro change this issue needs — common-avro otherwise stays a pure codec library with no engine/config dependency, unchanged.

Registered via META-INF/services/io.aklivity.zilla.runtime.model.avro.ext.AvroModelExtFactorySpi. Any number of implementations may be installed at once — every one discovered contributes independently, in ServiceLoader discovery order, via Factory.instantiate(ServiceLoader.load(AvroModelExtFactorySpi.class)) (the same @Incubating-aware helper every other plugin type already uses). Installed extensions simply compose: each appends its own stage(s) ahead of the model's own adapter stage, so there is no single-claimant contention between them to resolve.

2. Composition and caching

AvroModelFactorySpi.create(Configuration) discovers every installed AvroModelExtFactorySpi, and AvroModelContext supplies each one's AvroModelExtContext once per engine worker. AvroModelHandlerImpl folds every extension's handler into the pipeline when constructing it for a resolved schema:

private AvroStream extend(AvroStream stream, AvroSchema schema)
{
    AvroStream extended = stream;
    for (AvroModelExtContext ext : exts)
    {
        extended = (AvroStream) ext.supplyHandler(schema, options).transform(extended);
    }
    return extended;
}

This folds in ahead of the model's own decode/encode adapter stage, and reuses the existing per-schema-id pipeline cache in AvroModelDecoderPipeline/AvroModelEncoderPipeline (Int2ObjectCache, keyed by schema id) — no new caching mechanism was needed; supplyHandler is called once per schema id, not per message, for free.

A deployment with zero installed extensions pays nothing: the loop is empty, extend() returns its input unchanged, and the assembled pipeline carries no extra stage.

3. Scope

This SPI defines only the generic composition mechanism above. What an installed extension actually does with the stage(s) it appends — and any config surface it needs to configure that — is entirely its own design, using its own types and its own target-resolution logic against common-avro's existing AvroType/AvroField/AvroType#matchingPaths API (#2302), attached to AvroModelConfig via the pre-existing Config/ConfigBuilder extension mechanism (ModelExtInfo/ConfigExtAdapter, AvroModelConfig.ext(name, type) / ConfigBuilder.Extensible.ext(factory), delivered per #2360) rather than any oss-declared field. This issue declares no opinion on what any installed extension is for.

4. Coverage

Unit coverage in model-avro: SPI discovery via a Configuration-supplied test AvroModelExtFactorySpi, per-worker AvroModelExt#supply invocation, supplyHandler invoked once per schema id (reusing the pipeline cache) with a stage installed ahead of the model's own adapter, multiple registered extensions composing in discovery order, and a zero-extension deployment producing an unmodified pipeline (identity() preserved, no extra stage).

Additional context

Blocked on #2302 (schema field annotation retention) only in the sense that an installed extension wanting tag-based field selection needs AvroField.attribute(String) — this SPI itself has no annotation dependency.

Sequenced after #1680 in this epic's plan; this SPI's own discovery mechanism (Factory, Configuration, EngineContext) is pre-existing engine plumbing that predates #1680, not something #1680 itself introduces — there is no hard technical dependency between them.

Activity

  1. added theissue type on Mar 30, 2026
  2. self-assigned this
    on Apr 1, 2026
  3. changed the title [-]Implement field-level encryption pipeline in avro model[/-] [+]Declare AvroTransformFactorySpi and wire provider-supplied transforms in avro model[/+] on Aug 4, 2026
  4. changed the title [-]Declare AvroTransformFactorySpi and wire provider-supplied transforms in avro model[/-] [+]Declare AvroModelExtFactorySpi and wire provider-supplied pipeline stages in avro model[/+] on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions