Skip to content

feat(codecs): make avro codec optional via cargo feature flag#25338

Open
ahachete wants to merge 1 commit intovectordotdev:masterfrom
ahachete:ahachete-make-avro-optional
Open

feat(codecs): make avro codec optional via cargo feature flag#25338
ahachete wants to merge 1 commit intovectordotdev:masterfrom
ahachete:ahachete-make-avro-optional

Conversation

@ahachete
Copy link
Copy Markdown

@ahachete ahachete commented May 1, 2026

Summary

Make the avro codec optional via a new codecs-avro Cargo feature flag, mirroring the existing gating pattern already used in lib/codecs/Cargo.toml for arrow, parquet, opentelemetry, and syslog codecs.

The feature is enabled by default in every release feature aggregator (base, and transitively default-no-api-client, the per-target release features, etc.). Both sources-pulsar and sinks-pulsar pull codecs-avro automatically. No behavior change for anyone using the default build, the shipping release binaries, or the existing release feature sets.

Custom builds via cargo build --no-default-features --features ... that do not enable codecs-avro (and do not enable sources-pulsar or sinks-pulsar) skip compiling apache-avro and the avro codec implementation. Measured savings: ~440 KB on the production release profile (opt-level=3, lto=fat, codegen-units=1, panic=abort, strip=symbols) for a curated build.

This is a small, self-contained step toward the broader goal in #20064. Quoting @jszwedko in that umbrella issue:

the real savings is likely to come from users only compiling in the modules they need ... we do enable that via feature flags, but it's not well documented or easy for users to create their own distributions

Vector configuration

No configuration change. Existing YAML using codec: avro continues to work because codecs-avro is enabled by default in release builds.

How did you test this PR?

Compile-time:

  • cargo check --no-default-features --features "sources-file,transforms-remap,sinks-console,sinks-opentelemetry": apache-avro no longer linked.
  • cargo check --no-default-features --features "sources-file,transforms-remap,sinks-console,sinks-pulsar": codecs-avro auto-pulled via sinks-pulsar, Pulsar's SerializerConfig::Avro match arm in src/sinks/pulsar/config.rs:370 compiles unchanged.

Runtime:

  • Production release build (same minimal feature set, profile: opt-level=3, lto=fat, codegen-units=1, panic=abort, strip=symbols) shrinks from 30.600 MB to 30.166 MB (−444 KB).

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

(Closest fit. The change is purely structural: it adds a build-time opt-out without altering any runtime behavior).

Is this a breaking change?

  • Yes
  • No

The feature is enabled by default in every release feature aggregator and pulled in transitively by both Pulsar features, so default and shipping builds are bit-equivalent in behavior.

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

Changelog fragment included: changelog.d/codecs_avro_optional.enhancement.md.

References

Notes for reviewers

  • The new feature follows the existing pattern in lib/codecs/Cargo.toml (and the *Serializer / *Deserializer enum gating in serializer.rs / decoding/mod.rs) for arrow, parquet, opentelemetry, syslog. Each new #[cfg(feature = "avro")] site mirrors a matching site for one of those codecs.
  • src/components/validation/resources/mod.rs already had #[cfg(feature = "codecs-opentelemetry")] and #[cfg(feature = "codecs-syslog")] gates on the corresponding match arms; this PR adds the analogous #[cfg(feature = "codecs-avro")] gates in two places.
  • [[bin]] generate-avro-fixtures now declares required-features = ["avro"], the standard cargo idiom for feature-gated binaries.
  • The root Cargo.toml keeps the existing apache-avro workspace dep at v0.16 unchanged — that is used directly by the Pulsar source/sink for protocol-level types and is independent of the codec dep at v0.20.0 in lib/codecs/Cargo.toml.

Mirror the existing {arrow,parquet,opentelemetry,syslog} gating
pattern in lib/codecs/Cargo.toml for avro. The apache-avro dependency
and the avro encoder/decoder are now gated behind a new codecs-avro
Cargo feature.

The feature is enabled by default in all release feature aggregators
(base, default-no-api-client, target-* sets). Both sources-pulsar and
sinks-pulsar pull codecs-avro automatically, so default behavior and
shipping releases are unchanged.

Custom builds via --no-default-features that do not enable codecs-avro
(directly or through pulsar) skip compiling apache-avro and the avro
codec implementation, reducing the binary size by ~440 KB on x86_64
on my current setup, against a curated build. YMMV.

Refs vectordotdev#20064.
@ahachete ahachete requested a review from a team as a code owner May 1, 2026 13:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@ahachete
Copy link
Copy Markdown
Author

ahachete commented May 1, 2026

I have read the CLA Document and I hereby sign the CLA

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.

1 participant