Skip to content

[adapters] Kafka header filters.#6607

Merged
ryzhyk merged 1 commit into
mainfrom
kafka-header-filters
Jul 9, 2026
Merged

[adapters] Kafka header filters.#6607
ryzhyk merged 1 commit into
mainfrom
kafka-header-filters

Conversation

@ryzhyk

@ryzhyk ryzhyk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

New Kafka input connector config setting to filter messages based on Kafka message headers. Supports primitive checks against regular expressions and arbitrary Boolean combinations.

Describe Manual Test Plan

Tested with a single-table pipeline and a Kafka topic with 5 messages, and a couple of headers each.

Checklist

  • Unit tests added/updated
  • Integration tests added/updated
  • Documentation updated
  • Changelog updated

Breaking Changes?

Mark if you think the answer is yes for any of these components:

Describe Incompatible Changes

@ryzhyk
ryzhyk requested review from blp and mihaibudiu July 9, 2026 15:28
@ryzhyk ryzhyk added the connectors Issues related to the adapters/connectors crate label Jul 9, 2026

@mythical-fred mythical-fred left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One tiny formatting nit inline; nothing blocking.

Comment thread crates/feldera-types/src/transport/kafka.rs Outdated
New Kafka input connector config setting to filter messages based on Kafka
message headers. Supports primitive checks against regular expressions and
arbitrary Boolean combinations.

Signed-off-by: Leonid Ryzhyk <ryzhyk@gmail.com>
@ryzhyk
ryzhyk force-pushed the kafka-header-filters branch from ca95793 to f54cbcc Compare July 9, 2026 17:18
@ryzhyk
ryzhyk enabled auto-merge July 9, 2026 17:19
@mihaibudiu

Copy link
Copy Markdown
Contributor

This is the kind of stuff that looks like it could live well in a preprocessor.

@ryzhyk

ryzhyk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

This is the kind of stuff that looks like it could live well in a preprocessor.

When you have a hammer...

This is true, but we have users who'd like to use this with multiple data formats. They'd have to write multiple Rust preprocessors. A connector config setting is easier.

[dev-dependencies]
csv = { workspace = true }
tempfile = { workspace = true }
serde_yaml = { workspace = true }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yech


// Admit iff (env is prod or staging) and not (skip == drop).
let filter = json!({
"and": [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should standardize on the language for these expressions, in the push-down PR we are talking about JsonLogic https://crates.io/crates/jsonlogic-rs

But JsonLogic does not have regexes, these are very difficult across languages... sigh

{ "not": { "header": { "name": "skip", "pattern": "true" } } }
]
}
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use an example with escaped regex characters, so one does not have to read the regex documentation

against regular expressions. Each node is a JSON object with a single key:

| Node | Value | Matches when |
|------------|----------------------|-------------------------------------------------|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very fond of this language, let's make this as general as possible, we may reuse it in several places.
There should be a crate for parsing and validating this language.
"header" is fine, and it should return a string.
Use "pattern" as a function which takes a string and returns a regex
Use "match" as a function which takes a string and a regex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very fond of this language, let's make this as general as possible,

why?

we may reuse it in several places.

what do you have in mind?

"header" is fine, and it should return a string.
Use "pattern" as a function which takes a string and returns a regex
Use "match" as a function which takes a string and a regex

I don't understand what this means. Is this some JsonLogic stuff? Seems like we're trying to massively overengineer this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem like a good idea to force users to learn JsonLogic to write a simple header filter...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree, they will have to learn SOME language, let's at least make it a consistent language


/// Drop incoming messages whose Kafka headers do not satisfy this filter.
///
/// The filter is a boolean expression (`and`, `or`, `not`) over regular

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not describe here the filter language at all.

/// starts with `test-`.
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum HeaderFilter {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to a separate crate, something like JsonExpression.

@mihaibudiu

Copy link
Copy Markdown
Contributor

Sorry to make your life harder, but I think a more general solution is worth pursuing. We already have a myriad little languages sprinkled everywhere.

@mihaibudiu

Copy link
Copy Markdown
Contributor

I can help implementing the "JsonExpression" crate I mentioned if it helps. Or maybe we can reuse some of the stuff that @gz has built already.

@gz

gz commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

there is a query language for json built by a friend of mine https://www.jsoniq.org

but I agree lets keep it simple for now

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This design is fine if we expect that the filter language is complete in its current form.

@ryzhyk
ryzhyk added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit c3799d3 Jul 9, 2026
1 check passed
@ryzhyk
ryzhyk deleted the kafka-header-filters branch July 9, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connectors Issues related to the adapters/connectors crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants