feat(codecs): Support more avro types - #24774
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
40d0d6a to
aa24899
Compare
|
Hey @vectordotdev/vector, appreciate if you could review this PR, thanks! |
|
@codex review Hi @omwbennett, thanks for contributing to Vector. I enabled the workflows and requested a first pass from codex. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 857b4b3903
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb2cbd735b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5336c62721
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Hi @omwbennett, happy to review this once all codex comments are addressed (feel free to decline those with a justification if they do not make sense) |
Thanks @pront, I have addressed all the codex review comments now, appreciate if you could take another look. |
e1dc4da to
05045a9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 05045a98ce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| None => Ok(value), | ||
| } | ||
| } | ||
| (value, _) => Ok(value), |
There was a problem hiding this comment.
Resolve named schemas before coercing logical fields
When a record containing a date or time-millis field is reused through an Avro named-type reference, its field schema reaches this fallback as Schema::Ref, so the nested VRL integer remains AvroValue::Long. The subsequent schema resolution then rejects it (for example, a second field of type "Inner" fails with Expected Value::Date or Value::Int, got: Long(...)), meaning valid schemas using named records cannot encode the newly supported logical types. Resolve references during this recursive pass, using the root schema's names map, before descending into the referenced schema.
Useful? React with 👍 / 👎.
| AvroValue::Date(_) => Err(vector_common::Error::from( | ||
| "AvroValue::Date is not supported", | ||
| )), | ||
| AvroValue::Bytes(bytes) => Ok(VrlValue::Bytes(Bytes::from(bytes))), |
There was a problem hiding this comment.
Preserve non-UTF-8 Avro byte payloads
When an Avro bytes field contains arbitrary non-UTF-8 data, converting it to VrlValue::Bytes here makes the encoder's later apache_avro::to_value(log) pass serialize it through VRL's lossy string representation. For example, [0xff, 0x00] is silently re-encoded as [0xef, 0xbf, 0xbd, 0x00]; the new Fixed branch has the same problem and can instead fail when replacement bytes change the fixed length. Avro binary values are not restricted to UTF-8, so the serializer must preserve VRL bytes through a schema-aware conversion rather than the lossy Serde path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Hi @omwbennett, apologies for the delay. I spend a little time on this PR but this is actually an important issue. If you are still interesting in completing this, happy to help reviewing. Otherwise, I think we want to split this into smaller PRs.
The fix here is to do the following:
(VrlValue::Bytes(bytes), Schema::Bytes) => Ok(AvroValue::Bytes(bytes.to_vec())),There was a problem hiding this comment.
Hi, thanks for taking another look. I can split this up into smaller PRs.
There was a problem hiding this comment.
Next is the introduction of coerce_logical_types to support a few simpler logical types (date/timemillis): #26112
Will add support for the remaining logical types in a follow-up PR.
| }; | ||
| Ok((name, value)) | ||
| }) | ||
| .collect::<vector_common::Result<_>>()?; |
There was a problem hiding this comment.
Avoid rebuilding every Avro event during coercion
Although the final version no longer rebuilds ResolvedSchema, it still sends every event through this branch: apache_avro::to_value(log) produces a map for log events, and this collect allocates a replacement map after walking every field, recursively rebuilding nested maps and arrays even when the schema contains no Date or TimeMillis. Nullable unions additionally deep-clone their values before the final resolution traverses them again. In high-throughput pipelines with ordinary schemas or large messages, this adds per-event allocations and copies unrelated to the feature; skip the pass when the schema needs no coercion or mutate containers in place.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 63ff8274c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let resolved = | ||
| apache_avro::schema::ResolvedSchema::try_from(&self.schema).map_err(|error| { | ||
| vector_common::Error::from(format!("Failed resolving Avro schema: {error}")) | ||
| })?; |
There was a problem hiding this comment.
Cache Avro name resolution across encoded events
In high-throughput Avro sinks, this rebuilds the schema's name map for every event, and value.resolve(&self.schema) immediately afterward constructs another ResolvedSchema, so each encoding traverses the schema twice before writing any data. Fresh evidence since the earlier thread is that the current diff has reintroduced ResolvedSchema::try_from(&self.schema) in encode; resolve or cache the names when constructing AvroSerializer, then reuse that state for coercion and final resolution.
Useful? React with 👍 / 👎.
| "AvroValue::Date is not supported", | ||
| )), | ||
| AvroValue::Bytes(bytes) => Ok(VrlValue::Bytes(Bytes::from(bytes))), | ||
| AvroValue::Date(days) => Ok(VrlValue::from(days)), |
There was a problem hiding this comment.
Regenerate Splunk HEC's Avro support docs
For users configuring either Splunk HEC decoding path, website/cue/reference/components/sources/generated/splunk_hec.cue still says that Date, Fixed, and TimeMillis are unsupported at lines 110-114 and 654-658, even though this commit updates the same generated description in the other source pages. Regenerate this component page as well so the published options do not contradict the newly supported branches.
AGENTS.md reference: AGENTS.md:L212-L212
Useful? React with 👍 / 👎.
Summary
Addresses #24773 by adding support for decoding Avro
Datevalues, in addition toFixed,TimeMillis,TimestampNanos,LocalTimestampNanostypes.Due to the way VRL stores integers, an extra step was added to the avro encoder path to coerce Avro types based on the schema field's LogicalType.
Vector configuration
Also used similar configs for the other Avro data types.
How did you test this PR?
Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
Closes #24773
Notes
@vectordotdev/vectorto reach out to us regarding this PR.pre-pushhook, please see this template.make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make testgit merge origin masterandgit push.Cargo.lock), pleaserun
make build-licensesto regenerate the license inventory and commit the changes (if any). More details here.